If I have a point P, how do I project it onto a Catmull-Rom spline (ie. get the point on the spline closest to P)?(adsbygoogle = window.adsbygoogle || []).push({});

This is how I calculate the spline, t goes from 0 to 1 (C++):

Which I derived from the forumla on this page. Should I use the, whats it called, the smallest square solution or something? My math skills does not go beyond one variable calculus and linear algebra so I have no clue whatsoever.Code (Text):

float t2 = t * t;

float t3 = t2 * t;

out.x = 0.5f * ( ( 2.0f * p1.x ) +

( -p0.x + p2.x ) * t +

( 2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x ) * t2 +

( -p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x ) * t3 );

out.y = 0.5f * ( ( 2.0f * p1.y ) +

( -p0.y + p2.y ) * t +

( 2.0f * p0.y - 5.0f * p1.y + 4 * p2.y - p3.y ) * t2 +

( -p0.y + 3.0f * p1.y - 3.0f * p2.y + p3.y ) * t3 );

out.z = 0.5f * ( ( 2.0f * p1.z ) +

( -p0.z + p2.z ) * t +

( 2.0f * p0.z - 5.0f * p1.z + 4 * p2.z - p3.z ) * t2 +

( -p0.z + 3.0f * p1.z - 3.0f * p2.z + p3.z ) * t3 );

Regards,

Lantz

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Shortest distance from point to Catmull-Rom spline

Loading...

Similar Threads - Shortest distance point | Date |
---|---|

I Finding shortest distance between skew lines, checking work. | Aug 4, 2016 |

A check: shortest distance from point to line | Jan 19, 2016 |

Proof the shortest path on a sphere is the great circle. | May 10, 2015 |

Shortest distance between lines . | May 2, 2009 |

Shortest distance from a point to a line | Jul 25, 2007 |

**Physics Forums - The Fusion of Science and Community**