Let denote a point. For a curve segment defined by points and knot sequence, the centripetal Catmull–Rom spline can be produced by: where and in which ranges from 0 to 1 for knot parameterization, and with. For centripetal Catmull–Rom spline, the value of is. When, the resulting curve is the standard uniform Catmull–Rom spline; when, the product is a chordal Catmull–Rom spline. Plugging into the spline equations and shows that the value of the spline curve at is. Similarly, substituting into the spline equations shows that at. This is true independent of the value of since the equation for is not needed to calculate the value of at points and. The extension to 3D points is simply achieved by considering a generic 3D point and
Advantages
Centripetal Catmull–Rom spline has several desirable mathematical properties compared to the original and the other types of Catmull-Rom formulation. First, it will not form loop or self-intersection within a curve segment. Second, cusp will never occur within a curve segment. Third, it follows the control points more tightly.
Other uses
In computer vision, centripetal Catmull-Rom spline has been used to formulate an active model for segmentation. The method is termed active spline model. The model is devised on the basis of active shape model, but uses centripetal Catmull-Rom spline to join two successive points, so that the total number of points necessary to depict a shape is less. The use of centripetal Catmull-Rom spline makes the training of a shape model much simpler, and it enables a better way to edit a contour after segmentation.
Code example in Python
The following is an implementation of the Catmull–Rom spline in Python. import numpy import pylab as plt def CatmullRomSpline: """ P0, P1, P2, and P3 should be point pairs that define the Catmull-Rom spline. nPoints is the number of points to include in this curve segment. """ # Convert the points to numpy so that we can do array multiplication P0, P1, P2, P3 = map # Parametric constant: 0.5 for the centripetal spline, 0.0 for the uniform spline, 1.0 for the chordal spline. alpha = 0.5 # Premultiplied power constant for the following tj function. alpha = alpha/2 def tj: xi, yi = Pi xj, yj = Pj return **2 + **alpha + ti # Calculate t0 to t4 t0 = 0 t1 = tj t2 = tj t3 = tj # Only calculate points between P1 and P2 t = numpy.linspace # Reshape so that we can multiply by the points P0 to P3 # and get a point for each value of t. t = t.reshape print A1 = /*P0 + /*P1 A2 = /*P1 + /*P2 A3 = /*P2 + /*P3 print print print B1 = /*A1 + /*A2 B2 = /*A2 + /*A3 C = /*B1 + /*B2 return C def CatmullRomChain: """ Calculate Catmull–Rom for a chain of points and return the combined curve. """ sz = len # The curve C will contain an array of points. C = for i in range: c = CatmullRomSpline C.extend return C
using UnityEngine; using System.Collections; using System.Collections.Generic; public class Catmul : MonoBehaviour
For an implementation in 3D space, after converting Vector2 to Vector3 points, the first line of function GetT should be changed to this: Mathf.Pow + Mathf.Pow + Mathf.Pow;