# Distance from curve

This topic is 4230 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a curve defined by y = abs(x)^3, and a point. How do I find the exact distance from the point to the nearest point on the curve? Thanks in advance.

##### Share on other sites
The curve is parameterized as (x(t),y(t)) = (t,t^3). The point of interest is (x0,y0). You need a point (x(t),y(t)) so that the vector (x(t)-x0,y(t)-y0) is perpendicular to the curve at (x(t),y(t)). The tangent to the curve is (x'(t),y'(t)) = (1,3*t^2), so you need 0 = Dot((x'(t),y'(t)),(x(t)-x0,y(t)-y0)). This condition reduces to 0 = (t-x0) + 3*t^2*(t^3-y0), which is a degree 5 polynomial in t. Numerically solve the polynomial equation for t.

##### Share on other sites
I was basically going to say what Dave said before he ninja'd me to it, but you also need to be careful regarding that absolute value sign. What I would do is solve the polynomial for both x3 and -x3, and sort the solutions (by distance of course). Then return the first "good" solution, i.e. you have a solution where x is positive but it came from solving -x3 (which gives you a negative value), it doesn't satisfy |x|3 and you skip it.

##### Share on other sites
In regards to the absolute value, you can move it from the function to the point you're checking since you know the closest point on the polynomial will have the same x sign as the point you're comparing it to. So take the absolute value of X at the start and ignore it in the function and it should work out right.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633734
• Total Posts
3013587
×