3

For an arc in 3D space with the following known variables:

  • $A$: start point
  • $B$: end point
  • $C$: center point
  • $r$: radius
  • vector normal to the surface of the arc

How can we calculate the coordinates of the point $D$ lying in the middle of the arc using the swept angle $\fracθ2$? How would this angle be calculated correctly?

I have tried the following:

  • Calculate the $X$ direction vector as $X = C - A$.
  • Calculate the Y direction vector as Y = normal x X.
  • Get the vectors from center to start and end, $CA$ and $CB$ respectively.
  • Calculate swept angle as $\theta = \arccos\left(\frac{CA\cdot{CB}}{{\lvert CA\rvert}{\lvert CB\rvert}}\right)$.
  • $D = C + X_{dir}\cdot{r}\cdot{\cos{\frac{\theta}{2}}}+ Y_{dir}\cdot{r}\cdot{\sin{\frac{\theta}{2}}}$

This way I am sometimes getting a diametrically opposite point. The problem seems to be that the sign of the angle $\theta$ I am calculating does not respect the direction of the normal axis.

enter image description here

Tsaras
  • 133
  • Most of the time you are eligible for an answer when you show what you did. What coordinate system are you using? – Narasimham May 03 '23 at 14:43
  • I thought I wouldn't clutter the question with my calculations. I will add more information. – Tsaras May 03 '23 at 14:46
  • I don't think you need the normal vector. Calculate $(B-C) \times (A-C)$ [the cross-product] and use known formulas connecting cross product with the angle swept out. – coffeemath May 03 '23 at 15:00
  • 1
    The formula I mean in previous comment: $|u \times v|=|u|\cdot |v|\cdot \sin(\theta)$ where $\theta$ is the angle between vectors $u,v.$ – coffeemath May 03 '23 at 15:08

1 Answers1

2

First, I would advise you to not take the arccos of that dot product. It is numerically unstable, and could even yield an error if the vectors CA and CB are parallel or anti-parallel and the floating point error falls the wrong way.

The cross product is a more stable source of the angle. Simply calculating CA x CB will yield a vector which lies is along the normal vector, whose length is tan(θ)(CA · CB)

So, we can first use the normal vector to get the angle θ:

// possibly confirm normal is parallel to CA x CB
θ = atan2(normal · (CA ⅹ CB), (CA · CB))

We now need to resolve the question's ambiguity. There are two possible arcs you've specified: The short way around and the long way around.

If it is guaranteed you want the short way around, we're already done. atan2 will yeild an angle in the range (-180º, 180º], so dividing it by 2 will give you either a clockwise or a counterclockwise angle in the range (-90º, 90º] with the shortest way around (tie goes to positive angle)

If it is instead guaranteed that the provided normal vector is consistently oriented to the arc (so that the end B is clockwise from A looking down the normal, or vice versa), then you can manipulate atan2 to lie in positive range (0º, 360º] with the substitution atan2(-y, -x) + 180º

θ = atan2(-normal · (CA ⅹ CB), -(CA · CB)) + 180
// possibly flip θ depending on the convention

If neither is guaranteed, I believe the problem is underspecified.

Either way, you now have a stable signed angle θ from A to B, and you can get the arc midpoint by rotating around the normal vector by θ/2 (using your calculation above, or using the Rodriguez rotation formula).

kotoole
  • 138
  • 1
    Just a note for posterity, if you have this problem without a normal specified at all, you can use the length (norm(CA x CB)) in place of (normal · (CA x CB)), then use that cross product normalize(CA x CB) as the normal to rotate around in the last step. However, if A, B and C are collinear you have a bigger ambiguity to deal with, since without a normal specified there are an infinite number of 180º arcs to choose from for midpoints. – kotoole May 03 '23 at 20:07
  • Thank you for the insightful answer. It turns out it is the case that my input normal vector always point to the right direction, so the angles are indeed always positive. I have substituted the calculations with atan2 as per your suggestion. – Tsaras May 04 '23 at 11:53