Skip to content

Instantly share code, notes, and snippets.

@jcchurch
Created April 21, 2011 16:55
Show Gist options
  • Save jcchurch/934980 to your computer and use it in GitHub Desktop.
Save jcchurch/934980 to your computer and use it in GitHub Desktop.
This function computes the 3D spline interpolation of a 3D dataset. I did not write this code.
function newCurve = spline3d(curve, dt)
% interpote a 3d curve using spline
% path 3*x
% newPath 3*x
x = curve(1, :);
y = curve(2, :);
z = curve(3, :);
t = cumsum([0;sqrt(diff(x(:)).^2 + diff(y(:)).^2 + diff(z(:)).^2)]);
sx = spline(t,x);
sy = spline(t,y);
sz = spline(t,z);
tt = t(1):dt:t(end);
xp = ppval(sx, tt);
yp = ppval(sy, tt);
zp = ppval(sz, tt);
newCurve = [xp; yp; zp];
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment