I am given a starting point $S=(s_1,s_2)^T$, the Center Point $C=(c_1,c_2)^T$ of the ellipse, with major radius $a$ and minor radius $b$, also the major axis is rotated w.r.t. the X axis by an angle of $\alpha$. I am also given an angle $\phi$ that is between the starting point $S$ and a target point $T$ looking from $C$. ($\phi$ can be >360°, e.g 540°, that would mean that the distance from $S$ to $T$ would be $d=1,5\cdot$ Perimeter of ellipse) I now have to get the target point $T$ and the distance on the ellipse between $S$ and $T$.

My Idea to get $T$ was :

1) rotate $A$ around origin by $\phi$ (name it $A'$

2) make a line $l$ from $C$ to $A'$

($l=C+(A-C)\cdot x)$

3) calculate intersection of this line with the ellipse

Problem: I have no clue how to do that either. Appreciate any help.


Your proposed method for finding $T$ is pretty good, although it can be simplified a bit. The tricky part is finding the distance, which I'll call $d$, along the arc of the ellipse. The best you'll do for this is a numerical approximation, because the exact distance involves an integral that cannot be expressed in elementary terms (indeed, the phrase "elliptic integrals" is a standard term precisely because of this).

First, let's write down two equations for your ellipse. I'm going to assume that the center, $C$ is at $(0,0)$, because that makes everything a little easier. To make this work, you replace $S$ by $S' = S - C$, you compute $T' = T - C$, and then you add $C$ back to $T'$ to get the point $T$ that you really wanted. This follows the general rule in physics (and linear algebra) that you're best off choosing the right coordinate frame to work in.

My next step is to work in a rotated coordinate system, in which $$ \pmatrix{x'\\y'} = \pmatrix{c & s \\ -s & c} \pmatrix{x\\y} $$ where $c = \cos \alpha, s = \sin \alpha$. In this coordinate system, the major axis is aligned with the $x'$-axis, and the minor with the $y'$-axis, so the ellipse equation is $$ \left(\frac{x}{a}\right) ^2 + \left(\frac{y}{b} \right) ^2 = 1, $$ which is probably easier to work with if we multiply through by $a^2 b^2$ and move everything to one side:

$$ b^2 x^2 + a^2 y^2 - a^2 b^2 = 0. $$ Now you need to find the point $S$, but in the rotated-and-translated coordinate system. The coordinates are $$ \pmatrix{s_1''\\s_2''} = \pmatrix{c & s \\ -s & c}\pmatrix{s_1 - c_1 \\ s_2 - c_2} $$ and we can now work with the coordinates in the "double-prime" system. We're going to find the (counterclockwise) angle between $(s_1'', s_2'')$ and the positive $x'$-axis. That's $$ \beta = atan2(s_2'', s_1'') $$ in just about any programming language. To move clockwise from there by $\phi$, you'll compute $$ \gamma = \beta - \phi $$ The point $T$ you're looking for lies somewhere along a ray in the $\gamma$ direction from the origin of the primed coordinate system, i.e., it has the form (in the primed coordinate system) $$ T'' = \pmatrix{t_1''\\ t_2''} = \pmatrix{r \cos \gamma\\ r \sin \gamma}, $$

where $r > 0$.

And this must satisfy the ellipse equation, i.e., you need to find the value of $r$ that makes $$ b^2 (r\sin \gamma)^2 + a^2 (r \cos \gamma)^2 - a^2b^2 = 0. $$ Writing that out with a little algebra, we get \begin{align} r^2 \biggl( b^2 \sin^2 \gamma + a^2 \cos^2 \gamma \biggr) &= a^2 b^2\\ r^2 &= \frac{a^2 b^2}{b^2 \sin^2 \gamma + a^2 \cos^2 \gamma}\\ r &= \frac{a b}{\sqrt{b^2 \sin^2 \gamma + a^2 \cos^2 \gamma}} \end{align}

Now, having the value for $r$ (you have to pick the positive one!), you want to convert back to regular coordinates. To do so, compute $$ \pmatrix{t_1'\\t_2'} = \pmatrix{c & -s \\ s & c}\pmatrix{t_1''\\ t_2''} $$ (notice that the "$-s$" has switched positions!), and then compute $$ \pmatrix{t_1\\t_2} = \pmatrix{t_1'\\t_2 }+\pmatrix{c_1\\ c_2}. $$

So that gets you the position of $T$.

As for the arclength, I can only suggest a numerical computation. It'll be easiest to work in the primed coordinate system. You basically need to compute a whole lot of angles between $\beta$ and $\gamma$, and compute a corresponding ellipse-point for each one, and then sum up the distances between successive ellipse-points (i.e., you're approximating the ellipse with an inscribed polygon with many many vertices). By taking the number of points to be large, your error can be made small, but that's about the best I can do for you.

  • $\begingroup$ Thanks for the answer. With your help I managed to implement an algorithm to achieve my goal. But your ellipse equation where you first used $r$ has an error. It needs to be $b^2(r cos(\gamma)^2 + a^2(r sin(\gamma)^2 -a^2b^2 = 0$. $\endgroup$ – Danjohles Feb 19 '20 at 15:25
  • $\begingroup$ Uh...the thing you claim is "correct" has 4 left-parentheses and 2 right-parentheses. I think maybe both of us are wrong. :) Anyhow, I'm glad I was of some use. $\endgroup$ – John Hughes Feb 19 '20 at 17:07
  • $\begingroup$ Yeah, I noticed the missing parenthesis after posting it on the mobile phone. And I can't find an option to edit my comment to correct it 😅 $\endgroup$ – Danjohles Feb 19 '20 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.