What is the slope of tangent line to a rotated ellipse at a specific point?

582 Views Asked by At

I've seen discussions about this but with too many details left out. I have an ellipse with the standard parameters: $h, k, a, b$ and a rotation angle. (I can convert all that to the general form coefficients: $A, B, C, D, E,$ and $F$ if needed)

To get the tangent line, I check to see if the slope equals infinity or not and do some very simple math (no trig) to generate a couple of points, thus defining a line.

But getting the slope is proving to be problematic. I check to see if either the x or y of the given point are at any extrema (pre-calculated) and set the slope to $0$ or infinity, accordingly. But I can't seem to work out the math for the "normal" cases.

I can use $$-(\frac{x}{ y} \cdot \frac{b^2}{a^2})$$ for a non-rotated ellipse. But this doesn't work, of course, in the rotated case.

3

There are 3 best solutions below

0
On BEST ANSWER

After following the link suggested by Minus One-Twelfth, this is what finally worked for me as a couple of Swift methods:

func slope(at pt: CGPoint) -> CGFloat
{
    let dy = 2 * C * pt.y + E + B * pt.x
    if dy.equals(0) {
        return .infinity
    } else {
        let dx = 2 * A * pt.x + D + B * pt.y
        return -dx / dy
    }
}

func tangent(at pt: CGPoint) -> Line
{
    let m = slope(at: pt) // 9 for some arbitrary length
    if m == .infinity {
        return Line(a: CGPoint(x: pt.x, y: pt.y-9),
                    b: CGPoint(x: pt.x, y: pt.y+9))
    } else {
        return Line(a: CGPoint(x: pt.x-9, y: pt.y-m*9),
                    b: CGPoint(x: pt.x+9, y: pt.y+m*9))
    }
}
0
On

When the ellipse is rotated, the tangent is rotated as well. From the slope on the non-rotated ellipse ($=\tan{\varphi}$), you can calculate the angle $\varphi$, add the rotation angle $\rho$ and calculate the tangent of the sum to get the desired slope: $$\tan{(\varphi + \rho)} = \frac{\tan{\varphi}+\tan{\rho}}{1-\tan{\varphi}\tan{\rho}}$$

1
On

Given the general equation $Ax^2+Bxy+Cy^2+Dx+Ey+F=0$ of a nondegenerate conic, you can obtain the equation of the tangent to it at any point on the conic either via implicit differentiation, as suggested in a comment to your question, or by using the fact that the tangent line and point of tangency form a polar pair. Knowing the latter, you can obtain an equation for the tangent line at $(x_0,y_0)$ via a series of simple substitutions, namely, $$x^2 \to xx_0 \\ y^2 \to yy_0 \\ xy \to \frac12(xy_0+x_0y)\\ x \to \frac12(x+x_0) \\ y \to \frac12(y+y_0).$$ After simplification, you’ll get an equation of the form $ax+by+c=0$, from which I expect you know how to find the slope.

You don’t need to remember these substitutions, though. They are captured in the matrix equation $$\begin{bmatrix}x&y&1\end{bmatrix} \begin{bmatrix}A&\frac B2&\frac D2\\\frac B2&C&\frac E2\\\frac D2&\frac E2&F\end{bmatrix} \begin{bmatrix}x_0\\y_0\\1\end{bmatrix} = 0.$$ This equation expresses the pole-polar relationship that I mentioned earlier. If you compute the product of the matrix and right-hand vector, you’ll have the coefficients of $x$ and $y$ in the final equation of the line without having to do any further rearrangement or simplification.