Fast Cardinal and Catmull-Rom Spline Interpolation

Version 1.0.3 (1.81 KB) by Moreno, M.
Optimal generation of cardinal splines of arbitrary dimensions, comprising Catmull-Rom (centripetal) types.

12 Downloads

Updated 8 Jun 2022

View License

Syntax
y = cspl(x)
y = cspl(x,n)
y = cspl(x,n,k)
Description
y = cspl(x,n,k) Returns a cardinal spline 'y' from its nodes 'x' and resolution 'n'. The parameter 'k' can optionally specify the tension of the curve, which is set to zero by default (centripetal). As per:
[1] Catmull, E. & Rom, R. 'A class of local interpolating splines'. CAGD, R. E. Barnhill and R. F. Reisenfeld, Eds. Academic Press. New York, 1974, pp. 317–326.
[2] Twigg, C. 'Catmull-Rom Splines' CMU School of Computer Science. Online Resource, 2003.
The function operates column-wise along the dimensions of 'x' and it is optimised for speed.
See also: bspl
Examples
% Generate random nodes
x = rand(4,2);
% Interpolate different splines
a = cspl(x);
b = cspl(x,[],0.25);
c = cspl(x,100,0.5);
% Plot curves
figure, hold on
plot(a(:,1), a(:,2))
plot(b(:,1), b(:,2))
plot(c(:,1), c(:,2))
plot(x(:,1), x(:,2), 'o')
legend 'Centripetal (0)' 'Cardinal (0.25)' ...
'Cardinal (0.50)' 'Random Nodes'
% Interpolate in N-dimensions
figure
plot(cspl(rand(4),100),'.');
legend 'dim 1' 'dim 2' 'dim 3' 'dim 4'

Cite As

Moreno, M. (2023). Fast Cardinal and Catmull-Rom Spline Interpolation (https://www.mathworks.com/matlabcentral/fileexchange/112810-fast-cardinal-and-catmull-rom-spline-interpolation), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2022a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.3

The default function call y = cspl(x) produces curves with at least 100 points of resolution.

1.0.2

Faster processing of duplicates by initialising 'y' with the last 'x' value, and using a knot vector with open interval [0,1). Change of interpolation method from 'makima' to 'spline' if a resolution is queried. Removed minimum interval resolution.

1.0.1

Removal of duplicate values and interpolation to query resolution if 'n' is not parsed. Enhancement of the function description text. As a result, the function is faster when resolution values are not parsed, and it is exempt of duplicate values.

1.0.0