Jump to content
  • Advertisement
Sign in to follow this  
StealthNinja

Distance from curve

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!