Sign in to follow this  

Catmull-Rom

This topic is 2551 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 this code so far for a Catmull-Rom calculation would these be close?


template<typename T, unsigned int size>
cml::vector<T, cml::fixed<size>>& CatmullRom(const cml::vector<T, cml::fixed<size>>& vP0,
const cml::vector<T, cml::fixed<size>>& vP1,
const cml::vector<T, cml::fixed<size>>& vP2,
const cml::vector<T, cml::fixed<size>>& vP3,
cml::vector<T, cml::fixed<size>>& result,
T t)
{
T t2 = t * t;
T t3 = t2 * t;
result = 0.5 * ((2 * vP1) + (-vP0 + vP2) * t +
(2 * vP0 - 5 *vP1 + 4 * vP2 - vP3) * t2 +
(-vP0 + 3 * vP1 - 3 * vP2 + vP3) * t3);
return result;
}



NX::MATH::CatmullRom<float, 3>(cml::vector3f(1,0,1),
cml::vector3f(2,0,2),
cml::vector3f(3,0,3),
cml::vector3f(4,0,4),
temp,
0);

I get 2,0,2 for a result, if that is correct... But this seems more like a linear interpolation, but I am unsure...

Thanks!

Share this post


Link to post
Share on other sites
I've not checked the code but passing in 0 for 't' will give you P1 back - as it has done. Catmull-Rom interpolates between P1 and P2 where (t>=0 && t<=1) using P0 and P3 as control points. If you pass in 0.5 you will get the value halfway between P1 and P2.

In this case that will still be linearly interpolated because your points are all in a straight line!

Try something like (0,0,0), (10,0,0), (10,0,10), (0,0,10) 0.5

Sketching the points out and drawing a smooth line through then will help you visualise what should happen.

Share this post


Link to post
Share on other sites
10 is not the max range. A Catmull-Rom spline passes through all of the control points, and as a result usually is not fully within the convex hull of the control points. Consider -- how would it pass through p2 smoothly on its way from p1, and continue smoothly towards p3, without either an instant turn or approaching and leaving from outside the hull?

Share this post


Link to post
Share on other sites

This topic is 2551 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this