0
votes

I have a 3d scene containing a line with coordinates Xa,Ya,Za for one side and Xb,Yb,Zb for the other side: enter image description here

How to determine the 3d coordinates (Xa1,Ya1,Za1,Xa2,...Zb4) of a bounding box for this line, having in addition to above data, the width and height of this box, and the rotation angle on its axis: enter image description here

Thanks

1
To clarify: you have a line segment, with given endpoints, and you are not looking for the smalled axis-parallel box containing this line (which is the usual meaning of bounding box) but instead for some box which contains that line, and has given dimensions. Right? Is the length of the box equal to that of the line? You write you have the rotation around the axis, but with respect to what frame of reference, i.e. what does angle zero mean? - MvG
Yes, your assumptions above are correct. box has same length that the line. Angle 0 would be parallel to the plane below. Thanks for your answer, will try to code the algorithm. - Laurent Crivello

1 Answers

1
votes

Essentially what you have to do is establish a suitable orthonormal coordinate basis, so that one basis vector points along the given line while other two are orthogonal to that. The actual choice depends on the angle you're mentioning, but you need some reference direction to decide angle zero.

Usually I'd say let a be the normalized (to length 1) vector from one of the points to the other. Let v be some fixed reference direction, e.g. “up”. Make sure that a and v are independent, i.e. pointing in different directions. Compute the cross product a×v, normalize to unit length, and call that b. It will be a vector orthogonal to both a and v and therefore something like the direction away from the line in a horizontal plane, if v was up. Compute c=a×b which will be the third basis vector, orthogonal to a and b and already at unit length.

Now take either endpoint and add ± w/2∙b ± h/2∙c to that, where w and h are the dimensions of the bounding box. This gives you the 8 corner points of your bounding box. If you want to rotate the box around the line, apply a two-dimensional rotation to the vectors b and c:

b' = cos(θ)∙b + sin(θ)∙c
c' = cos(θ)∙c − sin(θ)∙b