# 2D point projection on an ellipse

I would like to find an equation to this problem:

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.

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$$

• Sorry for the delay (it was night in Europe). That's exactly it. Thanks. Commented Aug 25, 2013 at 8:05

With "projection" what is normally meant is something else... it is the point of the ellipse that is closest to $P_1$. This will be on the line $P_1C$ if the ellipse is a circle or if the point is aligned to one of the two axes of the ellipse, but not in the general case where computing it is quite annoying.

You seem interested however in a simple problem...if the ellipse is axis-aligned then to find the point on the line $P_1C$ that is on the ellipse you can just do a little trick:

1. "squash" the world to make the ellipse a circle
2. compute the projection
3. "un-squash" the world to the original ratio

In formulas $$\theta = arctan_2(a(P_y - C_y),\ b(P_x - C_x))\\ P'_x = C_x + a\ cos(\theta)\\ P'_y = C_y + b\ sin(\theta)$$

where:

• $C$ is the center of the ellipse
• $a$ and $b$ are the lengths of horizontal and vertical semi-axes of the ellipse
• $P$ is the original point
• $P'$ is the computed "projected" point
• $arctan_2(y, x)$ is the function that returns the angle between the origin and the point $(x, y)$ (normally called atan2 in programming languages).

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.

• If I understand you correctly, then what you say is not true. If you calculate the point $x(\theta)$ using the equations you gave, and then calculate the angle between the $x$-axis and the ray leading to your point, then this angle will not be $\theta$. Commented Aug 25, 2013 at 3:10

Given typical point $$P(x_1,y_1)$$

Intersection points between ellipse and straight line

$$x^2/a^2+y^2/b^2= a^2,\; y/x= y_1/x_1\;$$ are by direct substitution and solving:

we have $$P$$ mapping to points: $$\pm \dfrac{ab\;( x_1,y_1)}{\sqrt{b^2 x_1^2+a^2 y_1^2}}.$$

Wanted to share my translation of the accepted answer in VB.net code ( @bubba ) This post helped me immensely and if someone needs the same in another language it is much easier to translate from this instead of the mathematical equation. Ellipse center point is $$(0,0)$$ in this as well.

    ''' <summary>
''' Calculate a point on an ellipse from the width and height and an angle.
''' This calculates based on East Orientation (90 degree start point).
''' http://math.stackexchange.com/questions/475436/2d-point-projection-on-an-ellipse/475505#475505
''' </summary>
''' <param name="Angle">In Degrees from 90 deg/east</param>
Protected Friend Shared Function EllipseEdgePointByAngle(EllipseWidthRadius As Double, EllipseHeightRadius As Double, Angle As Double) As PointD
Dim X As Double = K * Math.Cos(ThetaRads)
Dim Y As Double = K * Math.Sin(ThetaRads)
Dim out As New PointD(X, Y)
Return out
End Function

Private Shared Function Ellipse_k(ByVal EllipseWidthRadius As Double, ByVal EllipseHeightRadius As Double, ByVal ThetaRads As Double) As Double