3

I have some legacy code which is supposed to draw an arc with constant radius in 3d space however it is drawing the arc in the wrong position. I would like to know and understand the mathematical algorithm for doing this so I can verify the current code.

Given a start point in 3d space [x1, y1, z1], end point in 3d space[x2, y2, z2], centrepoint[c1, c2, c3] and number of segments, where segments define the number of points between the start and end point which will help draw the arc with straight lines, what is the math to help achieve this?

Update: The centrepoint is the midpoint of the sphere.

Seth
  • 53

1 Answers1

2

If I understand the question correctly, you want the arc generated by a center point $C[c_1;c_2;c_3]$, a start vector $u[x_1;y_1;z_1]$ and an end vector $v[x_2;y_2;z_2]$.

The starting point of your arc is therefore $C+u$, and the end point $C+v$ (thus forcing $u$ and $v$ to have same norm). Let $\alpha$ be the angle $(u;v)$

Your arc is defined by the set of points $C+\dfrac{\sin(\alpha-\theta)u+\sin(\theta)v}{\sin(\alpha)}$, for $\theta\in[0;\alpha]$. Using values of $\theta=\dfrac{k\alpha}{n}$ should give you the points you need to approximate the arc with $n$ segments.

Edit : Now that I have written this I realize that this does not work for $\alpha=\pi$, witch is to be expected as in 3D, two opposite vectors and the center of the sphere do not define an arc (as they don't define a plane). It does work otherwise. Given the midpoint instead of the center, one can find the center and make this work for all cases where $u \neq -v$. I'll look into this tomorrow, as well as computing the above formula using the cartesian coordinates.

Edit2 : after giving it some more thought, I think the best way to define an arc is giving the center of the sphere, the start vector, and the mid vector/point. That way the two vectors you are using are not colinear (thus defining the arc uniquely), unless you are trying to draw a circle. With those inputs, the above parametrisation should work with minor fixes. But first, some much needed sleep.

imj
  • 1,430
  • thanks so much for your answer! So is the centre point in the above equations the centre of the sphere? – Seth Mar 14 '13 at 20:19
  • ok reading more closely it is the centre of the sphere. – Seth Mar 14 '13 at 20:22
  • is alpha the angle of the arc, i.e. the angle between the vectors u and v is that what (u;v) notation means? – Seth Mar 14 '13 at 20:27
  • yes. cross and/or dot product of vectors u and v should give the values of $cos(\alpha)$, $\sin(\alpha)$ and $\alpha$ needed ($\sin(\alpha-\theta)=\sin(\alpha)cos(\theta)-\cos(\alpha)\sin(\theta)$). If $v$ is the midvector (to avoid colinear vectors), then $\theta\in[0;2\alpha]$ works. – imj Mar 15 '13 at 12:47
  • I have reworded the question, I think it was misleading that I originally stated 'start vector' when I really meant start point. Does that mean we should really be getting the vectors u - C and v - C? As opposed to C + u and C + v? – Seth Mar 20 '13 at 00:38
  • Could you expand on how you found the arc equation? If possible, could you also update your answer with your findings on how to make it useable for colinear vectors? – Mister Mystère Mar 16 '15 at 12:11