Given center, dimensions and orientation of a box, whats the quickest way of calculating its vertices?

Viewed 69

suppose I have a box characterized by

box = [cx,cy,cz,length,width,height,tx,ty,tz]

where cx,cy,cz is the coordinate of the center of the box. and tx,ty,tz are the angles the box is rotated w.r.t to each axis, for example, yaw can be calculated by arctan(ty/tx).

What is the quickest way one can calculate the 8 vertices of this box? A google search yielded no algorithm. Although not too difficult of a task, would appreciate someone sharing an algorithm if known.

A simplifying assumption is that the pitch and roll angles can be ignored.

EDIT: basically asking for the reverse of Convert 3D box vertices to center, dimensions and rotation

1 Answers

With only yaw to use, the directions of the edges are (tx, ty, 0), (-ty, tx, 0), (0, 0, 1). Normalized to unit length they are nx = (tx, ty, 0)/sqrt(tx²+ty²) ny = (-ty, tx, 0)/sqrt(tx²+ty²) and nz = (0, 0, 1).

Then the positions of the vertices are (cx, cy, cz) + (±.5*length, ±.5*width, ±.5*height) * (nx, ny, nz).

The three ± signs lead to 8 combinations for the 8 vertices of the rotated box.

Please check that in your application the rotation around the yaw axis has the correct sign. Normally it is defined as positive rotation with the axis going up. And yaw = arctan ty/tx also confirms this.

Depending on how tx and ty are given, sqrt(tx²+ty²) could already/always be normalized to 1, which would simplify the first formula for the normalized edge directions.

Related