开发者

Bounding Boxes for Circle and Arcs in 3D

Given curves of type Circle and Circular-Arc in 3D space, what is a good way to compute accurate bounding boxes (world axis aligned)?


Edit: found 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);
}


One thing that's not specified is how you convert that angle range to points in space. So we'll start there and assume that the angle 0 maps to O + r***X** and angle π/2 maps to O + r***Y**, where O is the center of the circle and X = (x1,x2,x3) and Y = (y1,y2,y3) are unit vectors.

So the circle is swept out by the function

P(θ) = O + rcos(θ)X + rsin(θ)Y where θ is in the closed interval [θstartend].

The derivative of P is

P'(θ) = -rsin(θ)X + rcos(θ)Y

For the purpose of computing a bounding box we're interested in the points where one of the coordinates reaches an extremal value, hence points where one of the coordinates of P' is zero.

Setting -rsin(θ)xi + rcos(θ)yi = 0 we get tan(θ) = sin(θ)/cos(θ) = yi/xi.

So we're looking for θ where θ = arctan(yi/xi) for i in {1,2,3}.

You have to watch out for the details of the range of arctan(), and avoiding divide-by-zero, and that if θ is a solution then so is θ±k*π, and I'll leave those details to you.

All you have to do is find the set of θ corresponding to extremal values in your angle range, and compute the bounding box of their corresponding points on the circle, and you're done. It's possible that there are no extremal values in the angle range, in which case you compute the bounding box of the points corresponding to θstart and θend. In fact you may as well initialize your solution set of θ's with those two values, so you don't have to special case it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜