John.Ludlum
John.Ludlum

Reputation: 155

Convert 3D box vertices to center, dimensions and rotation

Given the locations of the vertices of a cuboid in 3D space (8x3 matrix), how can I calculate the following:

  1. Coordinates of the center of box
  2. Dimensions of the box: this is pretty simple I guess, just euclidean distance between the correct pairs of points.
  3. Angle of rotation around the yaw axis

The box i'm working with is a bounding box for 3D object detection. So we can assume that there is no rotation at all along the pitch and roll axis (if that helps). Below shows an example of the setup i have: enter image description here

I've been able to find stuff online for the inverse calculation, from dimensions to vertices. But i can't find anything in this direction. Would really appreciate any help!

Upvotes: 0

Views: 2251

Answers (1)

MBo
MBo

Reputation: 80187

Assuming that initially edge P0-P1 was directed along OX axis, we can find rotation angle around OZ axis as

angle = atan2(P1.y - P0.y, P1.x - P0.x)

(atan2 function gives results in radians in the most of languages)

Box center is just a middle of any space diagonal (0-6, or 2-4 etc)

cx = (P0.x + P6.x) / 2
cy = (P0.y + P6.y) / 2
cz = (P0.z + P6.z) / 2

Upvotes: 1

Related Questions