5
$\begingroup$

The figure helps explaining the question:

enter image description here

I want to use TiKz to draw an arc between $A$ and $B$. Please note several things.

  1. This is a true 3D problem. There are already questions asked and solved for the 2D case. We assume that $\|B-O\|=\|A-O\|$.
  2. The common point between the two vectors $O$ does not have to be the origin, but it is not a big deal to translate the whole thing.
  3. I do not want 3D rotation matrices. I know the exact three coordinates of each of the three points $O$, $A$, and $B$. It is easy to compute the angle between the two vectors using dot product. So we have the range of angles. I want an equation wich is parametrized as a function of an angle between 0 and the angle between the two vectors.
  4. Any point in the plane of the two vectors can be written as: $P = O + s(B-O) + t(A-O)$. I would like simple expressions for $s$ and $t$ in terms of the components of the vectors.
  5. A point $X$ in the arc satisfies the equation $\|X-O\|=\|B-O\|$, $X=O + s(B-O)+t(A-O)$. 4 equations with 5 unknowns. I am missing an equation here. Actualy no. We need to eliminate 4 variables to come to the parametrization of the curve.
  6. Is there an easy way to solve this? (by easy I mean no 3D rotation matrices, no large system of equations.
  7. Still I would like a solution even if it is messy. Thanks.
$\endgroup$
2
  • 1
    $\begingroup$ In the parametric equation(s) you are seeking, does the independent parameter have to be angle, or can it be something else? I ask because the tidiest approach is (probably) to use a rational quadratic Bezier curve, but it's parameter will not be an angle. $\endgroup$
    – bubba
    Nov 1, 2015 at 5:10
  • $\begingroup$ @bubba : The parameter does not have to be angle. I did not know that yesterday but this morning I found a solution where the parameter is $s \in [0,1]$, which does not require finding any angles at all. $\endgroup$ Nov 1, 2015 at 17:12

3 Answers 3

3
$\begingroup$

The slerp formula is coordinate-free and gives you a constant-speed parametrization of the arc. In your case, assuming $O$ is at the origin, the formula is $$X = \frac{\sin\bigl((1-t)\phi\bigr)}{\sin\phi}A + \frac{\sin(t\phi)}{\sin\phi}B,$$ where $0\le t\le1$ and $\phi$ is the angle between $A$ and $B$. Observe that when $\phi=\pi/2$, the formula reduces to the usual $A\cos\theta+B\sin\theta$ parametrization of a circle, with $\theta=t\phi$.

$\endgroup$
5
  • $\begingroup$ I like the simplicity of your formula and the fact that is coordinate free. It is very easy to code. Precisely the problem I had before is while trying to plot circles in a sphere, but not great circles. That is, the center can not be the origin. Is there an easy conversion of your formula with a non 0 origin? I will study this. Thanks for your answer. $\endgroup$ Nov 2, 2015 at 13:55
  • 1
    $\begingroup$ I guess it would be $X=O + \frac{sin( (1-t) \phi}{\sin \phi} (A-O) + \frac{\sin(t \phi)}{\sin \phi} (B-O)$. $\endgroup$ Nov 2, 2015 at 13:58
  • $\begingroup$ In addition this solution fails when $\phi=\pi/2$. $\endgroup$ Nov 2, 2015 at 17:36
  • $\begingroup$ @Herman: No, it doesn't. Do you mean $\phi=\pi$? $\endgroup$
    – user856
    Nov 2, 2015 at 19:28
  • $\begingroup$ Sorry, you are right. I forgot my trigonometry. $\endgroup$ Nov 2, 2015 at 20:20
2
$\begingroup$

Here is a direct solution.

We assume first that $O=(0,0,0)$ and then shift the origin at the end. Since $O$ is the origin the points $A$ and $B$ are true vectors, so the segment that joins them is $S= A + s(B-A)$, with $s \in [0, 1]$. When $s=0$ we are sitting on $A$ and when $s=1$ we are sitting in $B$.

The idea is to bend the segment $S$. That is, at any point $P=A + s(B-A)$ in the segment we need to shift the point by the right amount away from $O$. Call $r=\| A \| = \| B \|$. Then find the unit vector in the direction of $P$. That is \begin{equation} \bf{u} = \it \frac{P}{\| P \|} \end{equation}

which is known for each $s \in [0,1]$. Note that $\| P \| \le r$ and the equality is only achieved at the end points $A$ and $B$, and the greatest difference is in the middle where the pull up is maximum. Then multiply the unit vector by $r$ So the solution is \begin{equation} x = O + r \ {\bf{u}} \quad , \quad s \in [0, 1] \end{equation} where now $O=(o_x, o_y, o_z)$ could be a point different from 0 and $\bf{u}$ is computed after subtracting the origin from $A$, and $B$.

The figure below shows the computed arc following the algorithm above.

enter image description here

I find low precision at the $B$ end. This might be a deficiency on my TiKz code.

In the TeX site for StackExchange

function to find arc between two points with a center of curvature

I show the TiKz/pgfplots code for the implementation of the algorithm.

$\endgroup$
3
  • $\begingroup$ This won't work very well if the angle between $OA$ and $OB$ is close to 180 degrees, and it won't work at all if that angle is larger than 180 degrees. $\endgroup$
    – bubba
    Nov 2, 2015 at 8:53
  • $\begingroup$ If the angle is 180 there is no arc. If the angle is close to 180, the arc is close to a line. Why should not work? I am not dividing my 0, I am dividing by $\|P\|$ which is stable as long as the points are not too close together. $\endgroup$ Nov 2, 2015 at 13:42
  • $\begingroup$ @bubba: I think I understand you. Is it because when you are closed to 180 degrees the vectors $O$, $A$, and $B$ are almost align? If this is the case all other methods will fail, and in particular your methods, because the vectors become almost linearly dependent, the matrix with the three vectors ill conditioned. All the contrary the method that I show seems to be less sensititive to these matters. $\endgroup$ Nov 2, 2015 at 13:46
1
$\begingroup$

Let $X$ and $W$ be unit vectors in the directions of $A - O$, and $B - O$ respectively. Then let $Z$ be the unit vector in the direction of $X \times W$, and let $Y = W \times X$. We now have an orthonormal set of vectors $X, Y, Z$. If $r$ is the radius of the circle, then the curve can be parameterized $$ P(\theta) = O + (r\cos\theta)X + (r\sin\theta)Y $$ You should use values of $\theta$ between zero and $\phi$, where $\phi$ is the angle between $OA$ and $OB$.

For a more symmetrical approach, let $X$ be the unit vector in the direction that bisects $A-O$ and $B-O$, and let $Y$ be the unit vector in the direction of the chord $B-A$. Then, again, the curve can be parameterized $$ P(\theta) = O + (r\cos\theta)X + (r\sin\theta)Y $$ but the relevant values of $\theta$ are now those in the range $-\tfrac12\phi \le \theta \le \tfrac12\phi$.

$\endgroup$
4
  • $\begingroup$ The vectors $X$ and $W$ are not orthonormal but this is irrelevant. The issue here is what do you mean $\theta$ is the angle theta. In 2D it is clear in 3D, not so clear. From computational point of view is clear that $\theta \in [0, \phi ]$. Geometrically it seems the angle in the plane normal to $Z$, but this implies rotation of coordinates. Still I will test your solution. Thanks. $\endgroup$ Nov 1, 2015 at 16:11
  • $\begingroup$ I am sorry I said I would test this. I do not want to deal with coordinates. I wanted a "coordinateless" solution. I am lazy. $\endgroup$ Nov 1, 2015 at 16:36
  • $\begingroup$ No, $X$ and $W$ are not necessarily orthogonal. But what I said was that $X$, $Y$ and $Z$ are orthonormal. You don't need to worry about what $\theta$ means. Just choose 20 or so values of $\theta$ in the interval $[0,\phi]$, and calculate points using the formula I gave. $\endgroup$
    – bubba
    Nov 2, 2015 at 8:44
  • $\begingroup$ I have to put my coordinate system in the plane of the vectors $X,Y$ normal to $Z$. This implies a rotation of coordinates. That is the part that I want to avoid. I want a coordinateless method. $\endgroup$ Nov 2, 2015 at 13:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .