MATLAB: How to generate a 3d Spline curve can interp3 be of help

interp3?

Hello everyone I am new to Matlab. I am trying to figure out a way to create a 3D Spline curve through a set of 3D data points example of my data set is as follows
d=[0.007773 0.649806 0.627914,
0.007773 0.652142 0.623493,
0.007861 0.654376 0.619330,
0.007846 0.654552 0.619330,
0.007846 0.656008 0.614547,
0.007889 0.657431 0.609919,
0.007884 0.657525 0.609919,
0.007884 0.658038 0.604945,
0.007910 0.658557 0.599996,
0.007910 0.658044 0.595022,
0.007925 0.657538 0.590064,
0.007915 0.657442 0.590064,
0.007915 0.656001 0.585276,
0.007928 0.654686 0.580892,
0.007922 0.654502 0.580892,
0.007922 0.652175 0.576467,
0.007927 0.649864 0.572070,
0.007926 0.649588 0.572070,
0.007926 0.646427 0.568196,
0.007966 0.643342 0.564396,
0.007924 0.557021 0.635591,
0.007924 0.560896 0.638751,
0.007926 0.564697 0.641852,
0.007917 0.565112 0.641852,
0.007917 0.569533 0.644188,
0.007925 0.573693 0.646389,
0.007917 0.574137 0.646389,
0.007917 0.578920 0.647845,
0.007917 0.583548 0.649253,
0.007893 0.584028 0.649253,
0.007893 0.589002 0.649766,
0.007906 0.593950 0.650276]

Best Answer

Hi Anjani, I think this is what you want to do:
Get your original data:
d=[0.007773 0.649806 0.627914,
0.007773 0.652142 0.623493,
0.007861 0.654376 0.619330,
0.007846 0.654552 0.619330,
0.007846 0.656008 0.614547,
0.007889 0.657431 0.609919,
0.007884 0.657525 0.609919,
0.007884 0.658038 0.604945,
0.007910 0.658557 0.599996,
0.007910 0.658044 0.595022,
0.007925 0.657538 0.590064,
0.007915 0.657442 0.590064,
0.007915 0.656001 0.585276,
0.007928 0.654686 0.580892,
0.007922 0.654502 0.580892,
0.007922 0.652175 0.576467,
0.007927 0.649864 0.572070,
0.007926 0.649588 0.572070,
0.007926 0.646427 0.568196,
0.007966 0.643342 0.564396,
0.007924 0.557021 0.635591,
0.007924 0.560896 0.638751,
0.007926 0.564697 0.641852,
0.007917 0.565112 0.641852,
0.007917 0.569533 0.644188,
0.007925 0.573693 0.646389,
0.007917 0.574137 0.646389,
0.007917 0.578920 0.647845,
0.007917 0.583548 0.649253,
0.007893 0.584028 0.649253,
0.007893 0.589002 0.649766,
0.007906 0.593950 0.650276]
Get the cumulative sum of distances between your points
CS = cat(1,0,cumsum(sqrt(sum(diff(d,[],1).^2,2))))
Interpolate at 100 equally spaced locations from the start to end of your curve. Use 'spline' interpolation. Also, throw in the original points as part of your output since this was requested.
dd = interp1(CS, d, unique([CS(:)' linspace(0,CS(end),100)]),'cubic')
Show the result:
figure, hold on
plot3(d(:,1),d(:,2),d(:,3),'.b-')
plot3(dd(:,1),dd(:,2),dd(:,3),'.r-')
axis image, view(3), legend({'Original','Interp. Spline'})