# catmull-rom question

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

## Recommended Posts

G'day! I’m working on implementing the catmull-rom spline algorithm, based on this document: http://www.mvps.org/directx/articles/catmull/ One thing I can’t work out is how to draw the start and end points (im using it to simply graph data). It appears that each CV needs a CV before and after to work (eg to define p1-p2 you need p0 and p3). I’m sure it’s all spelled out in that document, but I can’t quite get my head around it ;) Cheers, Nick

##### Share on other sites
Just ignore the first and last point of a Catmull Rom curve.

##### Share on other sites
Perhaps BlackPawns Common Spline Equations for Graphics might help, they've got a nice clear visual representation.

Catmull-Rom only works between the two mid-points p1-p2 but are controlled with the p0 and p3 points. For chaining them up to make a full spline you'd overlap them so that the first section was p0-p1-p2-p3 == p1-p2 but the second section would be p1-p2-p3-p4 == p2-p3 and so on.

If you want something that will pass through all of the control points you might be better of with a standard quadratic spline. Such as is described here: Linear and Quadratic Splines

Andy

EDIT: or as someone else points out ignore them, you can do this simply by simply making p0=p1 and p3=p2, of course the effect of doing this is that you'll end up with a straight line.

##### Share on other sites
Ok, maybe an example will help:

So, with this graph, the user has specified those 4 CVs. And we get a graph. But, there has to be CVs at the beginning and end that we don’t see to draw this graph according to the Catmul-Rom algorithm. How are they calculated? Are they just using the same values as the start and end CVS?

Cheers,

Nick

edit: cheers andy, ill have a look at standard quadratic spline

##### Share on other sites
Quote:
 Original post by ndeboarSo, with this graph, the user has specified those 4 CVs. And we get a graph. But, there has to be CVs at the beginning and end that we don’t see to draw this graph according to the Catmul-Rom algorithm. How are they calculated? Are they just using the same values as the start and end CVS?

Well it's been a while since I had to do any of this but they've got a spline through all four points, so they've either used a method that passes through all of their control points OR they've been a bit clever.

You could define that first segment as P0-P0-P1-P2, the middle segment as P0-P1-P2-P3 and the end segment as P1-P2-P3-P3. So you just feed each of those four control points into your catmull-rom equation and pull out a sequence of points along the length of your curve.

Obviously this way is a bit better than just always assuming you've only got 4 control points and can be extended to N control points.

Hope that helped.

Andy

##### Share on other sites
To only draw/render the spline you JUST need points on the spline and interpolate over them.

That's the key.

To allow editing you will need control points. But for each 2-point segment you will need another 2 for extra control. From these 3 segments formed only the one in the 'middle' is visible - the curve itself. But nothing stops you to recycle the loose segments for other curves - thus building a bigger picture.

From the original doc you linked:
Quote:
 While a spline segment is defined using four control points, a spline may have any number of additional control points. This results in a continuous chain of segments, each defined by the two control points that form the endpoints of the segments, plus an additional control point on either side of the endpoints. Thus for a given segment with endpoints Pn and Pn+1, the segment would be calculated using [Pn-1, Pn, Pn+1, Pn+2].

You can fix in place the 2 outer-most control points (that won't have visible segments), and thus loose a bit of 'editing power'

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

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

• Total Topics
632959
• Total Posts
3009476
• ### Who's Online (See full list)

There are no registered users currently online

×