简体   繁体   中英

Define coordinates of bounding box

I have a 3d scene containing a line with coordinates Xa,Ya,Za for one side and Xb,Yb,Zb for the other side: 在此处输入图片说明

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: 在此处输入图片说明

Thanks

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, eg “up”. Make sure that a and v are independent, ie 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM