5

I have the general equation of an elipse and a point P0:

elipse=0.31368-0.113863x-0.00127066x^2+0.00329003y+0.000817666xy+0.0000929297y^2
P0={-6.4,172.0}

I would like to find the point on the curve which has the shortest distance from P0. What would it be the best solution? Is there a way to use Near function not only with tables?

Jane
  • 51
  • 1
  • Does this - https://stackoverflow.com/questions/22959698/distance-from-given-point-to-given-ellipse - give you what you need to answer your own question ? – High Performance Mark Apr 07 '20 at 15:08
  • 1
    0.31368-0.113863x-0.00127066x^2+0.00329003y+0.000817666x*y+0.0000929297y^2==0 determines a hyperbola, not an ellipse. – user64494 Apr 07 '20 at 15:25
  • This is the result from a FindFit applied to some points, i haven't check the fit yet...I wanted to write the full code before – Jane Apr 07 '20 at 15:39

2 Answers2

7

We can use RegionDistance:

ellipse = 0.31368 - 0.113863 x - 0.00127066 x^2 + 0.00329003 y + 0.000817666 x y + 0.0000929297 y^2;

P0 = {-6.4, 172.0};

RegionDistance[ImplicitRegion[ellipse == 0, {x, y}], P0]
37.5323

The nearest point can be found in a similar fashion:

RegionNearest[ImplicitRegion[ellipse == 0, {x, y}], P0]
{-43.9319, 172.17}
Greg Hurst
  • 35,921
  • 1
  • 90
  • 136
4

The given conic is not an ellipse. It is a hyperbole.

elipse = 0.31368 - 0.113863 x - 0.00127066 x^2 + 0.00329003 y + 0.000817666 x y + 0.0000929297 y^2
P0 = {-6.4, 172.0};
sol = NMinimize[{(P0 - {x, y}).(P0 - {x, y}), elipse == 0}, {x, y}];
dist = Sqrt[sol[[1]]]


gr1 = ContourPlot[elipse == 0, {x, -100, 50}, {y, 100, 250}, PlotPoints -> 25];
gr2 = Graphics[{Red, PointSize[0.02], Point[P0]}];
grn = Graphics[{Blue, PointSize[0.02], Point[{x, y} /. sol[[2]]]}];
Show[gr1, gr2, grn]
Cesareo
  • 3,963
  • 7
  • 11