0

Read through Find projection point on elipse where the answer goes over the 2D case of projecting a point $\textbf{p}$ onto an ellipse defined by $\textbf{x}(t) = \textbf{c} + \textbf{u}\cos(t) + \textbf{v}\sin(t)$ where $\textbf{c}$ is the center of the ellipse, $\textbf{u}$ is the vector that defines the length and direction of one of the semi major/minor axis and $\textbf{v}$ defines the length and direction of the other semi major/minor axis. Both of which are orthogonal to each other. The equation below is derived from the relationship $(\textbf{x}(t) - \textbf{p}) \cdot\textbf{x}'(t) = 0$ $$C_1\cos(t) + C_2\sin(t) + C_3\sin(2t) = 0$$ where $$C_1 = (\textbf{c} - \textbf{p})\cdot \textbf{v}, C_2 = (\textbf{p} - \textbf{c})\cdot \textbf{u}, C_3 = \frac{1}{2}(\textbf{u}\cdot \textbf{u} - \textbf{v}\cdot \textbf{v})$$

It seems this equation which is claimed to have 4 roots at most (when solving for t) is solved best when you have a fixed ellipse with actual numbers and are trying to solve it with a Computer Algebra System for a specific case of an ellipse. Trying to solve this symbolically to get the generalization gives very lengthy equations (tried in Mathematica).

I need this for some 3D code where the position and form of my ellipse is dynamic so $\textbf{c}, \textbf{u}, \textbf{v}$ can change rapidly. So what do I do? I tried Numerical Methods such as the Newton-Raphson but I have no clue how to get all 4 roots (if there are any) all the time. Without all 4, you cannot check for the closest using $||\textbf{x}(t_i) - \textbf{p}||_2$. Any help would be appreciated on the direction to take, if I'm misunderstanding something, any assumptions are incorrect, etc.

There's also this paper "Least-squares orthogonal distances fitting of circle, sphere, ellipse, hyperbola, and parabola" by Sung Joon Ahn, et. al., but I'm not mathematically mature enough to read this quite yet.

Emblem
  • 1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Aug 17 '24 at 00:22
  • You don't need Newton-Raphson for this trigonometric equation. The solutions can be obtained in terms of the coefficients $C_1, C_2, C_3$. First transform the trigonometric equation, using the variable $z = \tan\left(\dfrac{t}{2}\right)$. This will result in a quartic (degree 4) polynomial in $z$, given by $$ a_4 z^4 + a_3 z^3 + a_2 z^2 + a_1 z + a_0 = 0 $$ , where $a_4 = -C_1 , a_3 = 2 C_2 - 4 C_3, a_2 = 0, a_1 = 2 C_2 + 4 C_3, a_0 = C_1 $. Find the roots of this equation, then find corresponding values of $t$ given by $t = 2 \tan^{-1} z $. –  Aug 17 '24 at 02:10
  • Ah, didn't know Weierstrass Substitution was used in things like this. Pretty nice how it becomes a quartic. This definitely does give me a direction. Now my code will need a Quartic Solver. Thank you. – Emblem Aug 17 '24 at 12:51
  • My code has been working for a while now. But there is a case that I'm approximating which works fine but I'm wondering what exactly is going on in the math. For example, if I plug in $p = <0, 5>, c = <5, 5>, u = <3, 0>, v = <0, 1.5>$ this'll return (8, 5) despite (2, 5) being the answer. I'm guessing this is because $C_1 = (p - c).v = 0$ due to orthogonality reducing the polynomial to $a_3z^3 + a_1z = 0 \implies z(a_3z^2 + a_1) = 0$ which only has one real solution ($z = 0$) due to the solution of $a_3z^2 + a_1 = 0$ being imaginary in this case -a1/a3 < 0. – Emblem Aug 28 '24 at 16:12
  • Here is a link to my Python Code to test out an Orthogonal Projection onto an Ellipse and see what I'm talking about: https://github.com/DinoDonald/PointToEllipse/blob/main/main.py – Emblem Sep 01 '24 at 18:37

0 Answers0