Catmull-Rom

Started by
3 comments, last by MARS_999 13 years, 3 months ago
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!
Advertisement
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.
Try something like (0,0,0), (10,0,0), (10,0,10), (0,0,10) 0.5

11.25, 0, 5 is the result

So how can 11.25 be a answer when 10 is the max range?

Thanks
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?
ah I see now, so the curve will probably have only one path for any given set of points...

Thanks

This topic is closed to new replies.

Advertisement