<s>[INST] Find intersection between line and ellipsoid I want to find points $\space P(x,y,z) \space$ where a line intersect an ellipsoid with $$P = P_{1}+t(P_{2}-P_{1})$$
Here is where I stuck:
The ellipsoid can be described as:
$$\frac{(x-x_{3})^{2}}{a^{2}} + \frac{(y-y_{3})^{2}}{b^{2}} + \frac{(z-z_{3})^{2}}{c^{2}} = 1$$
after substitution:
$$\frac{(x_{2} - x_{1})^{2}t^{2}-2t(x_{2}-x_{1})(x_{3}-x_{1})+(x_{3}-x_{1})^{2})}{a^{2}} + \frac{(y_{2} - y_{1})^{2}t^{2}-2t(y_{2}-y_{1})(y_{3}-y_{1})+(y_{3}-y_{1})^{2})}{b^{2}} + \frac{(z_{2} - z_{1})^{2}t^{2}-2t(z_{2}-z_{1})(z_{3}-z_{1})+(z_{3}-z_{1})^{2}}{c^{2}} - 1 = 0$$
Substitution gives a quadratic equation of the form:
$$kt^{2} + lt + m = 0$$
Any help would be appreciated.
 [/INST] Translate the ellipsoid to origin, by subtracting $(x_3, y_3, z_3)$ from $P1$ and $P2$, so the line is parametrised as
$$\vec{p} = \vec{v}_0 + t \vec{v}_1$$
where
$$\begin{aligned}
\vec{v}_0 = (\chi_0, \gamma_0, \zeta_0) &= (x_1 - x_3, y_1 - y_3, z_1 - z_3) \\
\vec{v}_1 = (\chi_1, \gamma_1, \zeta_1) &= (x_2 - x_1, y_2 - y_1, z_2 - z_1) \\
\end{aligned}$$
and the ellipsoid is
$$\frac{x^2}{a^2} + \frac{y^2}{b^2} + \frac{z^2}{b^2} = 1$$
Substituting $\vec{p}$ into the ellipsoid yields
$$\left(\frac{\chi_0 + t \chi_1}{a}\right)^2 + \left(\frac{\gamma_0 + t \gamma_1}{b}\right)^2 + \left(\frac{\zeta_0 + t \zeta_1}{c}\right)^2 = 1$$
Expand the terms and collect the coefficients for powers of $t$ and you get
$$\begin{aligned}
\left( \displaystyle \frac{\chi_1^2}{a^2} + \frac{\gamma_1^2}{b^2} + \frac{\zeta_1^2}{c^2} \right) & t^2 ~ + \\
\left( \displaystyle \frac{2 \chi_0 \chi_1}{a^2} + \frac{2 \gamma_0 \gamma_1}{b^2} + \frac{2 \zeta_0 \zeta_1}{c^2} \right) & t ~ + \\
\left( \frac{\chi_0^2}{a^2} + \frac{\gamma_0^2}{b^2} + \frac{\zeta_0^2}{c^2} - 1 \right) & ~ = 0 \\
\end{aligned}$$
This is a simple quadratic equation in $t$, which can have 0, 1, or 2 real roots $t$.
Remember that we only translated the coordinate system so that they were relative to the center of the ellipsoid, but we didn't scale or rotate the coordinate system.  So, after you have found $t$, you can find the point it refers to, in the original coordinate system, using your original parametrised line,
$$P = P1 + t ( P2 - P1 )$$
i.e.
$$\left\lbrace ~ \begin{aligned}
x &= x_1 + t \chi_1 \\
y &= y_1 + t \gamma_1 \\
z &= z_1 + t \zeta_1 \\
\end{aligned} \right.$$
for each intersection point $t$.
</s>