# Question about catmull rom splines

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

## Recommended Posts

I've gone over several articles about catmull-rom splines from various places on the net. I am a little bit confused about the control points. There are 4 control points from D3DX that the spline will pass thru. But the thing is it doesn't include p0 and p3... so the weight is only used for points between p1 and p2 and points between p0 and p1/p2 and p3 are discarded? How do I establish the various control points... Thanks for any hints Jack

##### Share on other sites
Catmull rom spline will guarantee that the spline will pass through every point, but the first, and last points will not be included as they are need to define the gradient at the fisrt and last actual point on the spline

so you would have:

p0   p1---p2---p3---...---p[n-1]   p[n]

the spline cannot join p0 to p1, and p[n-1] to p[n] because there are not enough control points, a cubic hermite spline, of which the catmull rom spline is a part of, require there to always be 4 control points, to define a spline between the two in the middle.

The reason for that is that without the extra 2 points on either side, the spline cannot be uniquely defined, because the gradient at those two points could be anything and the spline would still be defined.

it is perfectly acceptable to have p0=p1, and p[n] = p[n-1], different values will change the shape of the last and first sections of the spline.

For example, if you want the ends of the spline to match seamlessly, so that a camera continously looping around the spline will be seamless, you would need to have:

p[0] = p[n-2]
p[n] = p[2]
and obviously, so that the actual start and end points of the spline actually meet:
p[n-1] = p[1]

[Edited by - luca-deltodesco on September 12, 2009 8:10:10 AM]

Whoops...

##### Share on other sites
Quote:
 Original post by luca-deltodescoCatmull rom spline will guarantee that the spline will pass through every point, but the first, and last points will not be included as they are need to define the gradient at the fisrt and last actual point on the splineso you would have:p0 p1---p2---p3---...---p[n-1] p[n]the spline cannot join p0 to p1, and p[n-1] to p[n] because there are not enough control points, a cubic hermite spline, of which the catmull rom spline is a part of, require there to always be 4 control points, to define a spline between the two in the middle.The reason for that is that without the extra 2 points on either side, the spline cannot be uniquely defined, because the gradient at those two points could be anything and the spline would still be defined.it is perfectly acceptable to have p0=p1, and p[n] = p[n-1], different values will change the shape of the last and first sections of the spline.For example, if you want the ends of the spline to match seamlessly, so that a camera continously looping around the spline will be seamless, you would need to have:p[0] = p[n-2]p[n] = p[2]and obviously, so that the actual start and end points of the spline actually meet:p[n-1] = p[1]

hi luca-deltodesco,
Thanks for the explanation. I'd like to know if there is any example(links) for this (pathfinding using catmull rom splines)? I'd also like to know whether Natrual cubic splines are easier to implement or not.. because I saw one of the threads here which discussed this thingy :)
Thanks
Jack

[Edited by - lucky6969b on September 12, 2009 11:48:19 PM]

##### Share on other sites
I do not have any links, perhaps a google search will bring some for you, nor can i comment on the pros and cons comparing natural cubic splines and catmull rom i'm afraid.

But essentially, interpolating accross your spline will give you the position of the camera, whilst differentiating the spline equation will give you the forward vector for your camera.

If you want the camera to move at a uniform speed, you would have to precalculate an approximiation to the arc length of each spline segment to weight the interpolation variable by.

##### Share on other sites
Given a span 0,1,2,3 Catmull Rom splines will only sample points between points 1 and 2.

There are two options for the end spans 0-1 and 2-3:

1) Double-up the end points: 0,0,1,2 and n-3,n-2,n-1,n-1.

or

2) For closed shapes n-1,0,1,2 and n-3,n-2,n-1,0.

(a third option is to predict where the other end point would be).

For splines with more than 4 points it is handled "piecewise" - the overlapping portions provide C1 continuity.

##### Share on other sites
Thank you to both of you first.
I have another related question.
If my path is generated from AStar,
how do I apply this to catmull rom splines? Which points should be mapped to which parameters of the basis function? etc

And to bigneilm3
I don't quite understand how to double up 2 points 0,0,1,2...
could you please elaborate on that? I mainly want to map astar points to catmull-rom...
Sorry if it sounds too slow.
Thanks
Jack

[Edited by - lucky6969b on September 14, 2009 2:44:21 AM]

##### Share on other sites
He's basicly just repeated what i said, in a more confusing manner :P (except for the need of two points to start and end the spline that the spline will not pass though)

if you're wanting to map a spline through a path generated by AStar, then you'll want to set it as in my example, with p[0] = p[1] = first point in path, p[n] = p[n-1] = last point in path, and depending on your situtation, it might suffice to simply use each point in the path, as a control point in the spline.

so, your list of control points for the spline might be as follows:

Vec3[] spline = {path[0],path[0],path[1],path[2]...path[n-1],path[n],path[n]}for(int i = 0; i<n-3; i++){   D3DSplineMethod(spline,spline[i+1],spline[i+2],spline[i+3])}and then to build the spline through that directx method, you might have

##### Share on other sites
Here's a quick example, modifying something i've already had on my computer, to have it render a catmull rom spline through the generated path rather than straight line.

(It's meant to be using AStar to find the cheapest path through a terrain)

##### Share on other sites
Thanks for the tips...
Give me some time, let me sort it out for myself
Jack

1. 1
2. 2
3. 3
Rutin
18
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633659
• Total Posts
3013216
×