2D point projection on an ellipse

4.2k Views Asked by At

I would like to find an equation to this problem:

Ellipse

The problem is that I have an ellipse at a given center point C, with radius a (x axis), and radius b (y-axis). So far so good. Now I have the points P1-Pn anywhere around (P1 for example), even inside (P2). Now I want to get projection (I1-In) on ellipse for any possible P (except center I guess).

So basically a ray/ellipse intersection. Or maybe somehow detect angle between x-axis and P (Θ), and then project it back on ellipse.

2

There are 2 best solutions below

1
On BEST ANSWER

Let's assume that the ellipse is centered at the origin. If it's not, then translate the ellipse and the points to make this so.

Given a point $(x_0, y_0)$ that you want to project, you first find the angle $\theta$ between the $x$-axis and the ray leading to the point: in code, use $\theta = \text{atan2}(y_0, x_0)$. Then the projected point $(x,y)$ can be calculated using

$$k = \frac{ab}{\sqrt{ {b^2}\cos^2{\theta} + {a^2}\sin^2{\theta} }}$$

$$x = k \cos\theta$$

$$y = k \sin\theta$$

1
On

The ellipse can be parameterised as $x(\theta)=c_x+a\cos\theta,\,y(t)=c_y+b\sin\theta$.

You can also find the angle that the point $P$ makes with the positive $x$-axis, which would correspond to the value for $\theta$ in the above parameterisation of the ellipse.