I want to find the rotation angle $\theta$ so that a line with given slope $m$ and y-intersect $t$ is tangential to an ellipse with a given minor axis $a$, major axis $b$ and center $h,k$. The rotation axis is the global z-axis.

enter image description here


  • The blue ellipse with $a$,$b$ in a given reference state (center: $h=r+a, k=0$)
  • The green line with $m$,$t$.


  • Rotate the green line around the origin until it is tangential to the blue ellipse (result is grey line) OR
  • Rotate the blue ellipse until it is tangential to the green line (result is grey ellipse)

What I know:

(1) Equation of a straight line $$y=m*x+t$$

(2) Rotation around z-axis $$x'=x*\cos(\theta)-y*\sin(\theta)$$ $$y'=x*\sin(\theta)+y*\cos(\theta)$$

(3) Equation of a ellipse in the given reference state (blue ellipse) $$\frac{(x-h)^2}{a^2}+\frac{(y(x)-k)^2}{b^2}-1$$

I can find the implicit derivative of the ellipse $$\frac{d}{dx}y(x)=-\frac{b^2*(2*h-2*x)}{2*a^2*(k-y(x))}$$

and I know that this must be equal to the slope $m$ of the line. But here comes the problem. Not with the slope $m$ of the green line but with the slope $m$ of the rotated line (which is unknown, since I don't know the rotation angle.)

Can anybody help me to find what I'm missing? I think somehow I have to use equation 1 and 2 but I don't see how to solve for the angle $\theta$.

I would appreciate help very much.


2 Answers 2


HINT...When you rotate the green line by $\theta$ clockwise, to get the grey line, the equation of this line is $$y(\cos\theta+m\sin\theta)=x(m\cos\theta-\sin\theta)+t$$

This is of the form $y=Mx+C$, (assuming $\cos\theta+m\sin\theta \neq0)$.

If you solve this simultaneously with the equation of the ellipse $$\frac{(x-h)^2}{a^2}+\frac{y^2}{b^2}=1,$$ the resulting quadratic in $x$ must have double roots since the line is a tangent. Putting the discriminant $=0$ results in the equation $$-2MCh-C^2+b^2-M^2h^2+a^2M^2=0$$ where $$M=\frac{m\cos\theta-\sin\theta}{\cos\theta+m\sin\theta}$$ and $$C=\frac{t}{\cos\theta+m\sin\theta}$$

You then have an equation for $\theta$ to solve.

  • $\begingroup$ Thank you very much. I understand your approach. But what I don't understand is how to solve this equation. It has $sin(\theta)$ and $cos(\theta)$ in numerator / denuminator. I can solve it with Newton method and I can find the correct angle value, that is fine for a first step. But is there a method to solve this analytical for $\theta$? The only method I know is compound angle transformation but this cannot be used here for sure. $\endgroup$
    – mk3
    Commented Feb 11, 2022 at 19:22
  • 2
    $\begingroup$ Bear in mind there will be $4$ possible values of $\theta$. You can obtain a quartic equation in $t$ where $t=\tan\frac12\theta$, but the workings won't be easy. $\endgroup$ Commented Feb 11, 2022 at 23:33
  • $\begingroup$ I never thought that but I actually find a solution with your help. Thank you very much! Answer accepted! $\endgroup$
    – mk3
    Commented Feb 14, 2022 at 13:30
  • $\begingroup$ good to hear it was useful! $\endgroup$ Commented Feb 14, 2022 at 14:22

Assume the ellipse is given by

$(r - r_0)^T Q (r - r_0) = 1$

where $r_0 = (h, k) $ and $Q$ is a positive definite matrix.

If the ellipse is in the standard orientation given in the problem then

$Q = \begin{bmatrix} \dfrac{1}{a^2} && 0 \\ 0 && \dfrac{1}{b^2} \end{bmatrix} $

Also we have the line. Its equation is given by

$n^T (r - r_1) = 0$

where $n$ is the unit normal to the line, $n = ( - \dfrac{ m}{ \sqrt{m^2 + 1}} , \dfrac{1}{\sqrt{m^2 + 1}} ) = (\cos \theta_N , \sin \theta_N )$

and $r_1 = (0, t)$.

Now we'll rotate the ellipse about the origin of the coordinate system by an angle $\theta$.

The rotation matrix $R$ is given by

$R = \begin{bmatrix} \cos \theta && -\sin \theta \\ \sin \theta && \cos \theta \end{bmatrix} $

The image of a point $r$ on the ellipse is $r' = R r$. Therefore, $r = R^T r'$. Plug this into the equation of the ellipse, this results in

$ (R^T r' - r_0)^T Q (R^T r' - r_0) = 1 $

which simplifies to

$(r' - R r_0)^T R Q R^T (r' - R r_0) = 1$

Rename $r'$ as $r$

$(r - R r_0)^T R Q R^T (r - R r_0) = 1$

Note that the center of the rotated ellipse is now $R r_0 $.

The normal vector to the rotated ellipse at a point $p$ on it is

$g = 2 R Q R^T (p - R r_0 )$

and we want this vector to be parallel to the normal vector to the line , which is vector $n$, so

$R Q R^T ( p - R r_0 ) = \alpha n$

from which

$p - R r_0 = \alpha R Q^{-1} R^T n$

Plug this into the ellipse equation, and you get

$\alpha = \dfrac{1}{\sqrt{ n^T R Q^{-1} R^T n } } $

So now the tangency point $p$ is known. It is given by

$p = R r_0 + \dfrac{ R Q^{-1} R^T n } { \sqrt{ n^T R Q^{-1} R^T n } }$

So far we have found the point that has a tangent parallel to the line. If this tangency point is on the line then the following equation must be satisfied

$ ( p - R r_0) \cdot n = -n^T (R r_0 - r_1) \hspace{15pt} (*)$

The left hand side is the projection of the vector $(p - R r_0)$ along the normal vector $n$ , and the right hand side is the perpendicular distance between the center of the ellipse and the line.

Now the left hand side $= \dfrac{ n^T R Q^{-1} R^T n }{\sqrt{ n^T R Q^{-1} R^T n} } = \sqrt{ n^T R Q^{-1} R^T n } $

Hence, by squaring $ (*)$

$\begin{equation} \begin{split} n^T R Q^{-1} R^T n &= (R r_0 - r_1)^T n n^T (R r_0 - r_1) \\ &= r_0^T R^T n n^T R r_0 - 2 r_1^T n n^T R r_0 + r_1^T n n^T r_1\\ &= n^T R r_0 r_0^T R^T n - 2 n^T R r_0 r_1^T n + r_1^T n n^T r_1 \hspace{15pt} (**)\\ \end{split} \end{equation} $

Define $u = R^T n = (\cos \phi, \sin \phi )$

(Note that since $u$ is a rotation of the unit vector $n$, it is also a unit vector)

Now equation $(**)$ becomes

$ u^T Q^{-1} u = u^T r_0 r_0^T u - 2 u^T (r_0 r_1^T n) + r_1^T n n^T r_1 $

And this is of the form

$ A \cos \phi + B \sin \sin \phi + C \cos (2 \phi) + D \sin (2 \phi) + E = 0$

and can be solved by introducing the transformation

$ z = \tan \dfrac{\phi}{2} $

which results in a quartic (4th degree) polynomial in $z$.

Find its roots, then find the corresponding $\phi$'s, $\phi_i = 2 \tan^{-1} z_i $ where $z_i$ is the $i$-th root of the quartic polynomial.

Once we have the $\phi$'s, we can find the rotation angles by noting that $\phi = \theta_N - \theta $

where $\theta_N$ is the polar angle of the unit normal vector $n$.

  • $\begingroup$ Hi thanks! I already received a solution with the first post. I will try it with your way also but to me the first post was more helpful because it is more equal to my approach. Thank you also very much! $\endgroup$
    – mk3
    Commented Feb 14, 2022 at 13:30

You must log in to answer this question.

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