5
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ Does this - stackoverflow.com/questions/22959698/… - give you what you need to answer your own question ? $\endgroup$ – High Performance Mark Apr 7 at 15:08
  • 1
    $\begingroup$ 0.31368-0.113863x-0.00127066x^2+0.00329003y+0.000817666x*y+0.0000929297y^2==0 determines a hyperbola, not an ellipse. $\endgroup$ – user64494 Apr 7 at 15:25
  • $\begingroup$ 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 $\endgroup$ – Jane Apr 7 at 15:39
7
$\begingroup$

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}
| improve this answer | |
$\endgroup$
  • $\begingroup$ And is this the x or the y of the point on the ellipse? $\endgroup$ – Jane Apr 7 at 15:40
  • 2
    $\begingroup$ That's the distance. you can use RegionNearest to find the point. $\endgroup$ – Chip Hurst Apr 7 at 15:45
  • $\begingroup$ could I use RegionNearest when a region is defined by solutions of a given differential problem? $\endgroup$ – Jane Apr 7 at 17:37
  • $\begingroup$ In principle it can work with anything that is RegionQ. If you have a curve defined by an equation, wrapping it in ImplicitRegion gives a valid input. $\endgroup$ – Chip Hurst Apr 7 at 17:47
4
$\begingroup$

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]
| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ Alternatively, you could Minimize or NMinimize either Norm[P0 - {x, y}] or EuclideanDistance[P0, {x, y}] $\endgroup$ – Bob Hanlon Apr 7 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.