after a week of fruitless trials I have to ask for help, most probably it is a trivial problem, although I could not find an answer using results of related problems on several forums. The problem I'm struggling with is as follows:
I'm looking for the shortest distance between a line and an ellipsoid. the ellipsoid E is defined by:
In which $A=diag[1/a^2,1/b^2,1/c^2]$ with a,b and c being half the length of the principal axes and $x_p$ is a point on the ellipsoid.
A line L is defined by $x_l=s_a+\lambda r_a$ (2)
with $x_l$ a point in the line.
Now, my general strategy is to find a point on the ellipsoid at which the surface normal is tangent to the directional vector $r_a$ of the line L and then work out the distance between that point (or rather points, as there will be two, logically) and the line as defined.
I followed 2 approaches:
1/ find a line parallel to L for which the dot product of the surface normal on the ellipsoid (which is $2x_p^TA$) and the directional vector of the line is zero. This boils down to finding a plane that is tangent to the ellipsoid and contains the directional vector of the line and a vector defined by the cross product of the surface normal and the directional vector of the line. Once this plane has been found it is trivial to work out the distance between the plane and the original line $x_l=s_a+\lambda r_a$. As far as I can see this should work but for some reason I cannot get correct results out of this (nor analytically nor numerical using either the Nelder-Mead or a Levenberg-Marquart algorithm.
2/ plug in $x_l=\alpha s_a+\beta p+\lambda r_a$ in equation (1), treat $\lambda$ as a unknown and work out the determinant of the resulting quadratic equation for $\lambda$ and find a combination of $\alpha$ and $\beta$ that set the discriminant of this equation to zero (resulting in a value for $\lambda$ that yields the value for a double root for the intersection between the line and the ellipsoid that is automatically fulfilling the demand to have a surface normal tangent to the directional vector of the line). Also following that line of thought did not result in correct answers. As I stated I could not use results from other related problems that are discussed on this and other forums as most of these answers assume that the point sought after and the line lie within a plane that goes through the origin, which is true for an ellipsoid with two equal axis, but not for the general case, as far as I can see).
As I'm new to this forum I apologise in advance for maybe not being 100% clear or posing a trivial question, but I'm really stuck and need someone with experience and/or a new perspective to look at this (due to the virus I'm confined in my house without anyone around having a clue about what I'm doing).
thanks in advance
Coming back to the reference (math.stackexchange.com/q/895452 ) using Plucker coordinates: I coded this option in Matlab: %supportvector sa
sa=[8,0,2]; %directional vector ra
ra=[2,2,1]; % axes of the ellipsoid
a=8; b=4; c=1; %define matrix A
%derive the Plucker coordinates (e and p) in terms of vectors sa and ra
% define vector r ("A 3D plane tangent to the ellipsoid through the closest point is perpendicular to the plane defined in (2) above. To find the normal of this plane, we use the vector describing the point on the line closest to the origin. This is given by"
% and finally define the point on the ellipsoids sough for:
%the point on the line follows from:
The attached figure shows a plot of the results: the blue line is line L, the red arrows represent the surface normal in the two intersection point between L and E and the green line connects the points that are supposed to represent the shortest distance between L and E according to the 'Plucker coordinate based solution'. Where do I go wrong?????
As far as I can see I made no coding errors, yet I obtain incorrect results: