3D bounding boxes for circle and arc

Given curves like Circle and Circular-Arc in 3D space, what is a good way to calculate exact bounding rectangles (alignment on the world axis)?


Edit: Found a solution for circles, still need help with Arcs.

C # snippet for solving BoundingBoxes for circles:

public static BoundingBox CircleBBox(Circle circle) { Point3d O = circle.Center; Vector3d N = circle.Normal; double ax = Angle(N, new Vector3d(1,0,0)); double ay = Angle(N, new Vector3d(0,1,0)); double az = Angle(N, new Vector3d(0,0,1)); Vector3d R = new Vector3d(Math.Sin(ax), Math.Sin(ay), Math.Sin(az)); R *= circle.Radius; return new BoundingBox(O - R, O + R); } private static double Angle(Vector3d A, Vector3d B) { double dP = A * B; if (dP <= -1.0) { return Math.PI; } if (dP >= +1.0) { return 0.0; } return Math.Acos(dP); } 
+4
source share
1 answer

One thing that is not listed is how you convert this angular range to points in space. So, we start with the fact that the angle 0 is displayed in O + r *** X **, and the angle Ο€ / 2 is displayed in O + r ** * Y **, where O is the center of the circle and X = ( x 1 , x 2 , x 3 )) and also Y = (y 1 , y 2 , y 3 ) are unit vectors.

Thus, the circle is swept away by the function

P (? Theta) = O + rcos (? Theta;) X + rsin (? Theta) Y where? Theta; is in closed range [& thet; start , & theta; end ].

The derivative of P is equal to

P '(? Theta;) = -rsin (? Theta;) X + rcos (? Theta;) Y

To calculate the bounding box, we are interested in the points where one of the coordinates reaches an extreme value, therefore, the points where one of the coordinates P 'is equal to zero.

Setting -rsin (? Theta;) x i + rcos (? Theta;) y i = 0, we get tan (? Theta;) = sin (? Theta)) / cos (? Theta;) = y i / x i .

So we are looking for & theta; where? = arctan (y i / x i ) for i in {1,2,3}.

You should keep an eye on the details of the arctan () range and avoid division by zero, and that if & theta; this decision, i.e. & theta; ? plusmn; k * & pi ;, and I will leave this data to you.

All you have to do is find the & theta; corresponding to extreme values ​​in your angular range, and calculate the bounding box of their corresponding points on the circle, and you're done. It is possible that there are no extreme values ​​in the range of angles, in which case you calculate the bounding box of the points corresponding to & thet; start and & theta; end . In fact, you can also initialize your & theta; with these two values, so you have no special case.

+3
source

Source: https://habr.com/ru/post/1306226/


All Articles