I am trying to compute the closest distance between a point a curve (polynom of 2rd degree) :
$$f(x)=a*x^2+b*x+c$$
$a,b,c$ are established. So if we denote that D(x) is an distance from $(x,f(x))$ to $(p,q)$ so we get:
$$ D(x)= \sqrt {(x-q)^2+(f(x)-p)^2}$$
To get the minimum of $D(x)$ we take the derivate of $D(x)'=0$ and the only way when $D(x)'$ becomes zero is when the numerator becomes $0$. So i get:
$$2(x-q)+2(f(x)-p)*f'(x)=0$$
But to solve this equation for multiple points takes much computation time I need a faster solution. Is there a approximation or algorithm to speed up the compution for a big set($n>5000$) of points?
I would try the following:
Your equation $$ 2(x-p)+2(f(x)-q)*f'(x)=0 $$
Is actually an equation of degree three. Write it out and you will get something like
$$a^2x^3+px^2+...$$
and so on.
Do a for loop over all points:
Solve is a matlab command and doing this 5000 times should not take more than a second. Tell me if it works and if you have any questions.