How to find an intersection point between a line and an ellipse, where the line passes from the center of the ellipse?

I know everything about the ellipse.

I know the angle $(\theta)$ (whose $\tan$ will be slope) and starting point of the line (where the starting point is the center of the ellipse).

Here are the equations which I'm trying to use: $$\frac{(x-x_{0})^2}{a^2} + \frac{(y-y_{0})^2}{b^2}$$ $$y = \tan(\theta) \cdot x + n$$ $$n = y_{0} - x_{0} \cdot \tan(\theta)$$

  • 1
    $\begingroup$ If you know the equations of the line and the ellipse (say the line is given by $f(x,y) = 0$ and the ellipse is $g(x,y)=0$) then you can solve for $f(x,y) = g(x,y)$. $\endgroup$
    – desiigner
    Jul 15, 2019 at 20:11
  • $\begingroup$ Actually I don't know the equation of the line I just know it's starting point and the angle. $\endgroup$
    – Akef
    Jul 15, 2019 at 20:21
  • $\begingroup$ I'm not sure what you mean by "angle." If you mean the angle from one of the axes, this is the same as having the slope. So if you have the slope of a line and a point it passes through, you should be able to determine the equation of the line. $\endgroup$
    – desiigner
    Jul 15, 2019 at 20:24
  • $\begingroup$ I added a picture to the post which contains the equations that I'm using. $\endgroup$
    – Akef
    Jul 15, 2019 at 20:33
  • 1
    $\begingroup$ If you know the line’s starting point and angle, then you know (or should easily be able to construct) an equation for it. $\endgroup$
    – amd
    Jul 16, 2019 at 1:38

2 Answers 2


First, I assume the ellipse you're using has a center at $(x_0,y_0)$, a width of $2a$ and a height of $2b$. If so, the entire equation then is

$$\frac{(x-x_{0})^2}{a^2} + \frac{(y-y_{0})^2}{b^2} = 1 \tag{1}\label{eq1}$$

You also give

$$y = \tan(\text{angle}) * x + n \tag{2}\label{eq2}$$ $$n = y_{0} - x_{0} * \tan(\text{angle}) \tag{3}\label{eq3}$$

Let $\alpha = \text{angle}$, then substitute \eqref{eq3} into \eqref{eq2}, rearrange and factor to get

$$y - y_0 = \left(x - x_0\right)\tan(\alpha) \tag{4}\label{eq4}$$

This equation indicates $\alpha$ is the angle, relative to the positive $x$-axis, of the line through the ellipse center.

At the intersection points (note there will be $2$ of them), the values of $x$ and $y$ will need to satisfy both \eqref{eq1} and \eqref{eq4} simultaneously. To determine their values, substitute \eqref{eq4} into \eqref{eq1} to get

\begin{align} 1 & = \frac{(x-x_{0})^2}{a^2} + \frac{\left((x-x_{0})\tan(\alpha)\right)^2}{b^2} \\ & = (x-x_{0})^2\left(\frac{1}{a^2} + \frac{\tan^2(\alpha)}{b^2}\right) \\ & = (x-x_{0})^2\left(\frac{b^2 + a^2\tan^2(\alpha)}{a^2 b^2}\right) \tag{5}\label{eq5} \end{align}

To make the handling a bit simpler, let

$$k = \frac{a^2 b^2}{b^2 + a^2\tan^2(\alpha)} \tag{6}\label{eq6}$$

since $k$ is a constant value. Next, multiplying both sides in \eqref{eq5} by $k$ and then taking square roots gives

$$x - x_0 = \pm\sqrt{k} \; \iff \; x = x_0 \pm\sqrt{k} \tag{7}\label{eq7}$$

Substituting \eqref{eq7} into \eqref{eq4} gives

$$y - y_0 = \pm \sqrt{k} \tan(\alpha) \; \iff \; y = y_0 \pm \sqrt{k} \tan(\alpha) \tag{8}\label{eq8}$$

Thus, the $2$ points of intersection between the line and the ellipse are $\left(x_0 + \sqrt{k}, y_0 + \sqrt{k} \tan(\alpha)\right)$ and $\left(x_0 - \sqrt{k}, y_0 - \sqrt{k} \tan(\alpha)\right)$.

  • $\begingroup$ Thanks for your answer it helps me a lot. Now what if I want a line that doesn't pass from the center of the ellipse like this line: $$y−ys=(x−xs)tan(α)$$ $\endgroup$
    – Akef
    Jul 16, 2019 at 5:33
  • $\begingroup$ @Akef You're welcome. As for a line which doesn't pass through the ellipse center, you can use a similar procedure. First, get the equation of it, then determine $y$ is in terms of $x$ (or vice versa), plug this into the ellipse equation, solve for $x$ (or $y$) and then determine the other variable. Note, however, if the line doesn't go through the ellipse center, the arithmetic won't be quite as simple. In particular, in my (7), I was able to get an equation where I could just take square roots. In general, you'll have a quadratic equation in $x$ or $y$ requiring using the quadratic formula. $\endgroup$ Jul 16, 2019 at 5:51
  • $\begingroup$ @Akef With your equation of $y - ys = (x - xs)\tan(\alpha)$, note $y - ys = y(1-s)$ and $x - xs = x(1-s)$, so if $s \neq 1$, it simplifies to $y = x\tan(\alpha)$. As I explained above, plug this for $y$ into my (1), simplify to get a quadratic equation in $x$, solve for $x$ using the quadratic formula, then plug this into $y = x\tan(\alpha)$ to get $y$. However, there is one thing you need to be careful of. Depending on the various values of $a, b, x_0, y_0$, etc., there possibly be no intersections, just $1$ intersection, or $2$ intersections. This depends on the $x$ quadratic eq. roots. $\endgroup$ Jul 16, 2019 at 5:57
  • $\begingroup$ Sorry the equation is: $$y−y_{s}=(x−x_{s})tan(α)$$ I'm not adapted with formulation. Actually, I solved this as you said and I programmed the equation but I didn't get the right points here is my equations: $$Ax^2+Bx+c=0$$ $$A=\frac{1}{a^2}+\frac{tan^2(angle)}{b^2}$$ $$B=-2[\frac{x_{0}}{a^2}+\frac{tan(angle)}{b^2} (tan(angle)x_{s} - y_{s}+y_{0})]$$ $$C=\frac{(tan(angle)x_{s}-y_{s}+y_{0})^2}{b^2}-1$$ $\endgroup$
    – Akef
    Jul 16, 2019 at 6:11
  • $\begingroup$ @Akef You're adding fractions with different denominators. In this case, I suggest multiplying both sides of (1) by $a^2 b^2$ so there are no fractions. In this case, you'll get $Ax^2 + Bx + C = 0$ where $A = b^2 + a^2\tan^2(\alpha)$, $B = -2b^2x_0 - 2a^2x_s\tan^2(\alpha) + 2a^2\tan(\alpha)(y_s - y_0)$ and $C = b^2x_0^2 + a^2x_s^2\tan^2(\alpha) - 2a^2x_s\tan(\alpha)(y_s - y_0) + a^2(y_s-y_0)^2 - a^2 b^2$. As you can see, it's quite messy. I did a quick double-check, but it's definitely possible I made a typo somewhere, so please check carefully yourself. $\endgroup$ Jul 16, 2019 at 6:22

First, translate the origin to $(x_0,y_0)$ to simplify the expressions that you’re working with. The equation of the ellipse becomes $x^2/a^2+y^2/b^2=1$, and the line now goes through the origin, so its equation is of the form $y=x\tan\alpha$, where $\alpha$ is the angle between line and $x$-axis. You could now substitute for $y$ into the equation of the translated ellipse, solve the resulting quadratic for $x$ and then back-substitute into the equation of the line to find the corresponding values of $y$, but there’s a way that’s perhaps even easier: Transform the problem once more by scaling $x$ and $y$ so that the ellipse becomes a unit circle. This is accomplished by making the substitutions $x\to x'/a$ and $y\to y'/b$.

Before proceeding, I’ll note that equations of the form $y=x\tan\alpha$ don’t cover all possible lines through the origin: the equation of the $y$-axis itself is $x=0$. For this line, $\alpha=\pi/2$, but the tangent of this angle is undefined. We can cover this case, too, by multiplying both sides of the equation by $\cos\alpha$ to get $y\cos\alpha=x\sin\alpha$. This covers all possible lines without any special cases or embarrassing divisions by zero.

For this problem, though, working with a parametric form of the line makes the computations pretty straightforward: the translated line is $(r\cos\alpha,r\sin\alpha)$ and after scaling it’s $\left(\frac ra\cos\alpha,\frac rb\sin\alpha\right)$. We want the value of $r$ for which this point is at a distance of $1$ from the origin: $$\left({r\cos\alpha\over a}\right)+\left({r\sin\alpha\over b}\right)^2=1$$ with solutions $$r = \pm{ab\over\sqrt{\left(b\cos\alpha\right)^2+\left(a\sin\alpha\right)^2}}.$$ Substituting this back into the unscaled line and translating back to the original coordinate system yields $$\left(x_0\pm{ab\cos\alpha\over\sqrt{\left(b\cos\alpha\right)^2+\left(a\sin\alpha\right)^2}},y_0\pm{ab\sin\alpha\over\sqrt{\left(b\cos\alpha\right)^2+\left(a\sin\alpha\right)^2}}\right).$$

Observe that in the process we’ve derived the polar equation of an ellipse centered at the coordinate origin with major axis along $\theta=0$. If you were allowed to take that equation as a given, you could’ve written the solution to the problem down directly.

  • $\begingroup$ What if I cannot translate the ellipse to the origin, I need the ellipse to be in a given point $$(x_{0},y_{0})$$ and I want to write a program to find the points I tried the solution which gave me @John Omielan but due to big calculations I got overflows. $\endgroup$
    – Akef
    Jul 18, 2019 at 5:50
  • $\begingroup$ @Akef You can always translate to the origin and then translate back. Observe that the final expression for the intersection points in my answer has the ellipse in its original position. $\endgroup$
    – amd
    Jul 18, 2019 at 6:10
  • $\begingroup$ you mean after I calculate the intersection points I can translate them back by adding $(x_{0}, y_{0})$ to them? $\endgroup$
    – Akef
    Jul 18, 2019 at 18:24
  • $\begingroup$ @Akef That’s it exactly. $\endgroup$
    – amd
    Jul 18, 2019 at 23:56

You must log in to answer this question.

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