# Catmull-Rom

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

## 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 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 on other sites
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

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

Thanks

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632960
• Total Posts
3009474
• ### Who's Online (See full list)

There are no registered users currently online

×