For a hobby project gone too far, I'm trying to find the maximum separation between two ellipses. I have only a high-school-graduate-level grasp of algebra and calculus, and am happy to dig deeper than that... but I need some guidance.
I have 3 functions of the same form, $X(p, q)$, $Y(p, q)$, and $Z(p, q)$ for which I am trying to evaluate $p$ and $q$. I know that $X+Y+Z=0$. I know I need to express p and q in terms of each other, but as you can see below, the three functions together are quite complex. I've been futzing around with trig identities to try and isolate either variable, but am stuck. Perhaps fresh eyes will help; can anyone here see a way forward?
All values are known, except $p$ and $q$.
$X(p,q) = [b_1V_{x1}\cos(p)-a_1U_{x1}\sin(p)][(C_{x2}+a_2U_{x2}\cos(q)+b_2V_{x2}\sin(q))-(C_{x1}+a_1U_{x1}\cos(p)+b_1V_{x1}\sin(p))]$
$Y(p,q) = [b_1V_{y1}\cos(p)-a_1U_{y1}\sin(p)][(C_{y2}+a_2U_{y2}\cos(q)+b_2V_{y2}\sin(q))-(C_{y1}+a_1U_{y1}\cos(p)+b_1V_{y1}\sin(p))]$
$Z(p,q) = [b_1V_{z1}\cos(p)-a_1U_{z1}\sin(p)][(C_{z2}+a_2U_{z2}\cos(q)+b_2V_{z2}\sin(q))-(C_{z1}+a_1U_{z1}\cos(p)+b_1V_{z1}\sin(p))]$
Edit - A couple threads I've been trying to springboard off of:
- Furthest distance between two circles in 3D
- How to calculate minimum distance between two arbitrary ellipses in 2D
- Solving trigonometric equations of the form $a \sin x + b \cos x = c$
I arrived here by taking the partial derivatives of the distance function for two points, one on each ellipse. Once I can find the critical points from that, I should have my solution(s).
The distance function is from the ellipses' parametric equations:
$x(θ)=C_x+aU_x\cos(θ)+bV_x\sin(θ)$
$y(θ)=C_y+aU_y\cos(θ)+bV_y\sin(θ)$
$z(θ)=C_z+aU_z\cos(θ)+bV_z\sin(θ)$
(Where $C$ is the centrepoint of the ellipse, $a$ and $b$ are its semimajor and semiminor axes, respectively, and $U$ and $V$ are unit vectors defining the plane of the ellipse. Angle $θ$ describes position on the ellipse)
So the distance function is:
$$D=\sqrt{(x_1-x_2)^2+(y_1-y_2)^2+(z_1-z_2)^2}$$
As the derivative of $\sqrt{n}$ is ${n'\over2\sqrt{n}}$, I only need concern myself with where the numerator ($n'$) is equal to $0$:
$$n'=-2f'(p)[-f(p)+j(q)]-2g'(p)[-g(p)+k(q)]-2h'(p)[-h(p)+l(q)]$$
(Where functions $f$, $g$, and $h$ refer to the parametrics for the 1st ellipse, and functions $j$, $k$, and $l$ to those for the 2nd. $p$ and $q$ are used instead of $θ$)
$n'=0$ is essentially of the form $0=X+Y+Z$ as outlined above.