Skip to content

Instantly share code, notes, and snippets.

@asw456
Forked from jcchurch/spline3d.m
Created June 9, 2013 05:00
Show Gist options
  • Save asw456/5737717 to your computer and use it in GitHub Desktop.
Save asw456/5737717 to your computer and use it in GitHub Desktop.
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