# Tangent to ellipse rotated in 3D with perspective

I have an ellipse in 3D, with width $a$, height $b$, centered on $(0, 0, C)$ and parallel to the $xy$-plane.

I'm using a parametric equation with parameter $t$:

$x = a \cdot cos(t) \\ y = b \cdot sin(t) \\ z = C$

I rotate it by $\theta$ around the $z$-axis and then by $\phi$ around the $x$-axis to get:

$x_r = x \cdot cos(\theta) - y \cdot sin(\theta) \\ y_r = (x \cdot sin(\theta) + y \cdot cos(\theta)) \cdot cos(\phi) - z \cdot sin(\phi) \\ z_r = (x \cdot sin(\theta) + y \cdot cos(\theta)) \cdot sin(\phi) + z \cdot cos(\phi)$

Then I project it on the $xy$-plane with a perspective transform using some constant $p$:

$x_p = \dfrac{p \cdot x_r}{p + z_r} \\ \\ y_p = \dfrac{p \cdot y_r}{p + z_r}$

Before applying perspective, I can calculate the tangent (in 2D) with:

$dx = x \cdot cos(\theta) + y \cdot sin(\theta) \\ \\ dy = (x \cdot sin(\theta) - y \cdot cos(\theta)) \cdot sin(\phi)$

How can I get an equation for the 2D tangent in terms of $t$ for the ellipse after the perspective transform has been applied?

• I may not understand fully, but couldn't you compute the tangent line using the parametric formula $$\vec T(t) = \frac{d \vec r}{dt} = \left(\frac{dx_p}{dt},\ \frac{dy_p}{dt},\ \frac{dz_p}{dt} \right)$$ since $x_p$, $y_p$, and $z_p$ are all functions of $t$ and $\theta$, $\phi$, and $p$ are constants? It would be messy, but doable. – WB-man Mar 23 '17 at 17:31
• @WB-man You could be right, I'm just not sure how to do that. What is $r$ in your equation, the radius? I forgot to mention that I'm looking for the 2D tangent, which should make it a bit easier. – Peter Collingridge Mar 23 '17 at 17:49
• $\vec r$ is just my usual way of denoting the position function $\vec r(t) = (x(t),\ y(t),\ z(t))$ because you can think of it as a vector extending from the origin. Perhaps I don't know what you mean by "2-D". It looks like after applying the transformations you get a space curve. The tangent vector at any point would be a 3D vector. Although, if you're just interested in the $x$- and $y$-components, you could just compute $dx_p/dt$ and $dy_p/dt$ and ignore $z_p$. If this is what you're after, tell me and I'll write up how to do it as an answer. – WB-man Mar 23 '17 at 17:55
• Thanks. Yes, when I say 2D I mean I'm just interested in the x and y values. – Peter Collingridge Mar 23 '17 at 18:27
• What do you mean by “2-D tangent” here? Are you trying to implicitly differentiate the curve that results after the perspective transformation? Or are you looking for corresponding tangent line after all of the machinations? Either way, you can either transform the parameterized coordinates of the original ellipse and differentiate, or you can find the (3-D) tangent vector to the original ellipse and transform that. The latter approach is likely to require fewer manipulations. – amd Mar 23 '17 at 23:48

If we want to compute the slope of the tangent line of the projected curve given parametrically by \begin{align} x_p(t) &= \frac{p\,x_r(t)}{p+z_r(t)} \\ y_p(t) &= \frac{p\,y_r(t)}{p+z_r(t)} \end{align} we can do it by computing $dx_p/dt$ and $dy_p/dt$ and then using the fact that $$\frac{dy}{dx} = \frac{(dy/dt)}{(dx/dt)}$$ How do we compute those two derivatives? By a long application of the chain rule. I think trying to write out the entire expression for the derivatives would be unwieldy. Therefore I will not expand the new factors the chain rule gives us, but will provide the formulas to compute them. I don't know what the application of this question is, but if you'll be coding it up, this is probably the better way to do it.
Let us begin. First I'll compute $dx_p/dt$:$\newcommand{\indent}{\ \ \ \ \ \ }$ \begin{align} \frac{dx_p}{dt} &= \frac{d}{dt} \left(\frac{px_r}{p+z_r} \right) \\ &= \frac{p\,x_r' \cdot (p+z_r) - px_r z_r'}{(p+z_r)^2} \indent \textrm{Quotient Rule} \end{align} where \begin{align} x_r' &= x' \cos \theta - y' \sin \theta \\ z_r' &= (x' \sin \theta + y' \cos \theta) \sin \phi \end{align} and \begin{align} x' &= -a \sin t \\ y' &= b \cos t \end{align} And $dy_p/dt$ looks the same just with $y_r$ instead of $x_r$: $$\frac{dy_p}{dt} = \frac{p\,y_r' \cdot (p+z_r) - py_r z_r'}{(p+z_r)^2}$$ where $$y_r' = (x' \sin \theta + y' \cos \theta) \cos \phi$$ If we go ahead and take the quotient of these two, we get a small simplification since their common denominators of $(p+z_r)^2$ will cancel: \begin{align} \boxed{\frac{dy_p}{dx_p} = \frac{py_r' \cdot (p+z_r)-py_r z_r'}{px_r' \cdot (p+z_r)-px_r z_r'}} \end{align} It may be that this can be further simplified if you plug in the corresponding expressions for the various variables in this expression, but from a cursory inspection, it doesn't look like it will.
• Your logic seems sound, but I get the wrong answer. e.g. for $t = 0; \theta = 0$, I would expect $dx = 0$ for any $\phi$ since it's at the leftmost point of the ellipse so its tangent should be parallel to the x-axis. But if I plug in the values for $\phi = \pi / 2$, I get $dx = pab$. (In fact, you can cancel the $p$ in the final expression). – Peter Collingridge Mar 24 '17 at 14:31