# Mesaurement of curvature of Camull-Rom spline segment

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

## Recommended Posts

Hi, I've just been learning about curves and have started using Catmull-Rom splines in my game. I'd like to get a measurement of curvature of the spline (or at various points along the spline), but can't find anything through google that can help me. While I was reading, I was clicking random things in Wikipedia (as you do) and stumbled across pages for curvature and osculating circles. I just about understand the maths, but I wouldn't be able to apply that to Catmull-Rom splines and then convert it into C++. Is there any example code out there that will calculate curvature, or at least something that will help a little? Along the same lines but a little simpler, is there any example code out there for calculating the tangent to a Catmull-Rom spline segment at a given t? Currently I'm just approximating by taking the difference between positions either side of t, but that just feels nasty!

##### Share on other sites
yeah, take the derivative of the catmul rom equation, that will give you 'tangent' at a point. The second derivative will give you the... 'acceleration', but it's not continuous (it can flip around).

##### Share on other sites
Thanks - I figured that if I took the second derivative using the slightly dodgy 'difference across a point' method I'd get some measure of curvature, but probably not the actual curvature, the measurement I can invert to get the radius of the osculating circle at that point.

What's the 'proper' (mathematical) way to take the derivative and second derivative of a Catmull-Rom spline segment? My differentiation skills are a little rusty, and I'm sure this is something someone has tackled before (and hopefully codified in C++!).

##### Share on other sites
should be quite easy. the catmull rom is a polynomial, with (t) as a parameter. Simple derive the polynomial for (t).

q(t) = 0.5 *(  	                 (2 * P1) +                  (-P0 + P2) * t +                  (2*P0 - 5*P1 + 4*P2 - P3) * t2 +                  (-P0 + 3*P1- 3*P2 + P3) * t3             )

so :

q'(t) = 0.5 * (                 (2 * P1) + (-P0 + P2) +                 2 * (2*P0 - 5*P1 + 4*P2 - P3) * t +                3 * (-P0 + 3*P1- 3*P2 + P3) * t2               )

I think... bit rusty too.

##### Share on other sites
Quote:
 Original post by oliiiq'(t) = 0.5 * ( (2 * P1) + (-P0 + P2) + 2 * (2*P0 - 5*P1 + 4*P2 - P3) * t + 3 * (-P0 + 3*P1- 3*P2 + P3) * t2 )

Fixed [smile]

##### Share on other sites
Ah yes. It's all coming back to me now!

Remember kids, pay attention in maths classes, it's more relevant to game development than you realise :)

Thanks very much oliii and jjd!

• 41
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631371
• Total Posts
2999614
×