Find the derivative of a spline curve obtained using cscvn
9 views (last 30 days)
Show older comments
Im trying to get the derivative of a 3D spline curve obtained with the cscvn function, I found that you can use fnder to obtain the derivative, but they use other spline methods (which are in 2D). If there is no way to obtain the derivative, can I at least get the function of the spline?
Here is my code:
xyz=[-15.3388,-13.9258,-12.5000,-7.5,0, 15;-29.7289,-29.9321,-30,-30, -30,-30; 34.5601, 35.2764, 36, 37.5, 40,40];
plot3(xyz(1,:),xyz(2,:),xyz(3,:),'ro');
box on
hold on
spline_func=cscvn(xyz(:,[1:end]));
spline_func.coefs
fnplt(spline_func,'r',2)
sp_df=fnder(spline_func,1);
sp_df.coefs
fnplt(sp_df)
grid on
xlabel('x(t)')
ylabel('y(t)')
zlabel('z(t)')
hold off
The sp_df returns a structure that has different fields, form, breaks, coefficients, pieces, order, and dimension, does anything of these has relation to the derivative?
The yellow graph is supposed to be the derivative" but I want to see the a table of the values.
2 Comments
Torsten
on 16 May 2023
Edited: Torsten
on 17 May 2023
See the coefficients of the spline and its derivative in your code above.
On each interval, the spline has the form a*t^3+b*t^2+c*t+d. The derivative of this function is 3*a*t^2+2*b*t+c.
So if the coefficients of the spline are (a, b, c, d), the coefficients of the derivative are (3*a,2*b,c).
If you look at the matrices above, you see this is reflected by the printed numerical values.
Answers (1)
John D'Errico
on 16 May 2023
No. There is no simple "function" of a spline. It is a mess of coefficients that by themselves are fairly meaningless to those who don't fully understand splines. And even if you do understand them, even I won't gain much useful information by looking at them. Just a slew of numbers. And if you are asking to know the "function", then you don't understand splines. (Hey. I'm sorry, but this is the truth.)
Anyway, what is the derivative of a function that falls along some general curved path through space? What derivative are you hoping to see? Derivative, with respect to what? Yes, you can compute a derivative. But remember what I just asked. What exactly are you hoping to compute?
The curve computed by cscvn is a parametric function of what I call the connect-the-dots arc-length along the curve. As I recall, it is a version of a centripetal Catmull-Rom spline.
So, again, what are you trying to compute? Remember the definition of derivative.
See Also
Categories
Find more on Splines in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!