How to generate a 3d Spline curve can interp3 be of help
23 次查看(过去 30 天)
显示 更早的评论
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]
0 个评论
采纳的回答
Sven
2011-11-21
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'})
5 个评论
John D'Errico
2011-11-22
Actually, those points are not truly equally spaced along the curve, but any interpolation will be difficult with this set of data given what appears to be large jumps along the curve.
Sven
2011-11-22
True, there is a small deviation from perfectly equal spacing (more so in fact with the inclusion of the original points in the interpolation).
This extra request came to me by email and was unfortunately not made here.
@Anjani: This is another reason to avoid asking questions by email... nobody else knows why I changed the original code... especially after you deleted a comment that talked about that change
更多回答(5 个)
Fangjun Jiang
2011-11-21
Put the matrix you show in the variable d, are you trying to plot using plot3()?
plot3(d(:,1),d(:,2),d(:,3));
grid on;
7 个评论
Sean de Wolski
2011-11-21
Interp3 is not what you want since you don't have a three dimensional matrix.
John D'Errico
2011-11-22
No. interp3 is of no help at all, as it is designed to solve a different problem. You need to have data on a regular lattice for that code. Your data, while not truly scattered data, has no such property.
You can use an approach like that suggested by sven. Note his choice of the cubic (pchip) interpolant is surely correct here, as a true spline would give pure crapola for results from data like this. You can use my interparc code (on the file exchange) to interpolate this code. Use the pchip option in there for best results. It will be similar to the curve generated by sven.
2 个评论
Mark Shore
2011-12-13
John, interparc is no longer on the file exchange. It was in April, but not now.
Osama Fakron
2012-3-24
Hello guys , I am new in MATLAB , I have 3D data (X,Y,Z) , I want to generate a 3d Spline curve , and get the equation for this curve
this is my data X Y Z 1918.48 632.835 2297.817 1918.536 726.851 2459.797 1929.952 879.353 2529.59 1965.054 988.129 2454.932 1929.094 1082.949 2352.078 1971.033 1169.236 2277.469 2002.218 1301.162 2314.086 1958.643 1452.974 2369.691 1960.967 1551.384 2282.698 1931.032 1631.015 2207.752 1851.922 1688.935 2120.373 1836.266 1656.647 1895.852 1791.063 1718.026 1791.406 1795.121 1943.297 1723.486 1820.439 1999.193 1594.015 1718.434 2099.138 1599.257 1682.064 2129.556 1490.298
Thank you
Osama
1 个评论
Osama Fakron
2012-3-24
x y z
1918.48 632.835 2297.817
1918.536 726.851 2459.797
1929.952 879.353 2529.59
1965.054 988.129 2454.932
1929.094 1082.949 2352.078
1971.033 1169.236 2277.469
2002.218 1301.162 2314.086
1958.643 1452.974 2369.691
1960.967 1551.384 2282.698
1931.032 1631.015 2207.752
1851.922 1688.935 2120.373
1836.266 1656.647 1895.852
1791.063 1718.026 1791.406
1795.121 1943.297 1723.486
1820.439 1999.193 1594.015
1718.434 2099.138 1599.257
1682.064 2129.556 1490.298
Osama Fakron
2012-3-24
Hello guys , I am new in MATLAB , I have 3D data (X,Y,Z) , I want to generate a 3d Spline curve , and get the equation for this curve these are my points
x
1918.48
1918.536
1929.952
1965.054
1929.094
1971.033
2002.218
1958.643
1960.967
1931.032
1851.922
1836.266
1791.063
1795.121
1820.439
1718.434
1682.064
y
632.835
726.851
879.353
988.129
1082.949
1169.236
1301.162
1452.974
1551.384
1631.015
1688.935
1656.647
1718.026
1943.297
1999.193
2099.138
2129.556
z
2297.817
2459.797
2529.59
2454.932
2352.078
2277.469
2314.086
2369.691
2282.698
2207.752
2120.373
1895.852
1791.406
1723.486
1594.015
1599.257
1490.298
Thank you
Osama
0 个评论
jth A
2020-11-10
I think this is what you want:
https://ww2.mathworks.cn/help/robotics/ref/bsplinepolytraj.html
Other related functions also fit this question
https://ww2.mathworks.cn/help/robotics/ref/cubicpolytraj.html#mw_47df83f2-2417-4e3b-b5f6-b033a6a9de5d
https://ww2.mathworks.cn/help/robotics/ref/quinticpolytraj.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!