Effacer les filtres
Effacer les filtres

Is there an easy way of finding the shortest distance from a point to a polynomial?

18 vues (au cours des 30 derniers jours)
With access to the point and the coefficients of the polynomial, is there an easy way of getting the perpendicular distance? Currently I'm having to find the distance from the point to every point in the curve and find the shortest manually, and its sloooooow.

Réponse acceptée

Matt J
Matt J le 3 Juil 2013
Modifié(e) : Matt J le 3 Juil 2013
The analytical solution boils down to finding the roots of another polynomial. If your fixed point is (x,y) and your polynomial is p(t), then the distance squared is
f(t) = (t-x)^2 +(p(t)-y)^2
Setting the derivative of f(t) to zero leads to
(t-x)+ (p(t)-y)*dp/dt = 0
which is just a problem of finding the roots of the polynomial on the left hand side. Once you find its roots using the ROOTS command, you then test f(t) at the real roots for the minimum distance.
  1 commentaire
Simon
Simon le 3 Juil 2013
Thanks. As it happens, I actually found an even quicker method (which required less code) - dsearchn, which uses the quickhull method

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Polynomials dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by