Algorithm to cut a catmull-rom spline?

895 views Asked by At

I have a catmull-rom spline with 6 CVs and want to cut it at an arbitrary point along the spline.

How do I calculate the end points of the two new splines so that they keep the shape as they had before they were cut in two?

So, imagine this being the spline with 6 points:

p0      p2      p4
 \     / \     / \
  \   /   \C  /   \
   \ /     \ /     \
    p1      p3      p5

if I want to cut this spline at point C, I will then have two new splines with I guess 5 CVs each?

Spline #1: p0, p1, p2, X, C
Spline #2: C, X, p3, p4, p5

Where X is a CV that I need to add in order to maintain the shape of the spline. But how do I calculate the position that X needs to be at?

Or is my logic wrong altogether and there is a whole different solution to the problem?

Thank you!

1

There are 1 answers

0
fang On

Catmull-Rom spline is essentially a spline composed of multiple cubic Bezier curves. So, if you want to divide it at any parameter t, you just need to find out which Bezier curve the parameter lies on, then divide that Bezier curve using the famous De Casteljau algorithm. The divided results are still cubic Bezier curves. However, if you want to find new set of CVs from which the derived Catmull-Rom spline will have exactly the same shape as the split spline from original spline, I would say that is not possible. I will explain in details below.

From Catmull-Rom spline's definition, the original spline defined by 6 CVs:p0, p1,..., p5 will have tangent at p2 in the direction of vector(p1,p3). For a new Catmull-Rom spline defined by 5 CVs: p0, p1, p2, X and C, where C is any point on the original CR spline, the tangent at p2 will be in the direction of vector(p1,X).

If we want the new CR spline to exactly represent the split spline #1 of the original spline, then tangent at p2 from these two splines should at least be in the same direction, which means that point X should lie on the line defined by p1 and p3. This criteria makes it impossible for the new Catmull-Rom spline to exactly represent the shape of split spline #1 from original spline.