Find the derivative of a spline curve obtained using cscvn

9 views (last 30 days)
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
ans = 15×4
-0.0305 0 1.1668 -15.3388 0.0159 0 -0.1862 -29.7289 0.0013 -0.0000 0.5646 34.5601 0.1578 -0.1156 1.0207 -13.9258 -0.0125 0.0603 -0.1100 -29.9321 -0.0034 0.0051 0.5711 35.2764 -0.0770 0.4834 1.4860 -12.5000 -0.0023 0.0129 -0.0173 -30.0000 0.0206 -0.0080 0.5674 36.0000 0.0385 -0.0446 2.4887 -7.5000
fnplt(spline_func,'r',2)
sp_df=fnder(spline_func,1);
sp_df.coefs
ans = 15×3
-0.0914 0 1.1668 0.0477 0 -0.1862 0.0040 -0.0000 0.5646 0.4735 -0.2311 1.0207 -0.0375 0.1206 -0.1100 -0.0103 0.0102 0.5711 -0.2311 0.9668 1.4860 -0.0070 0.0259 -0.0173 0.0617 -0.0160 0.5674 0.1154 -0.0892 2.4887
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
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.
Taleb
Taleb on 17 May 2023
Thanks Torsten! I appreciate the help! this was what I was looking for, I couldn't find much on the form of the function so I couldn't find the meaning of the coefficients. Have a good day mate!

Sign in to comment.

Answers (1)

John D'Errico
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.
  1 Comment
Taleb
Taleb on 16 May 2023
No worries, I do not know what a spline is honestly, I just used the method to complete a task I was given. The point behind this task is to do different segments of a roller coaster and then put them together, being that the segments are continuous and smooth. The derivative is to respect to time, I want to obtain the tangent and normal vectors of the rollercoaster.
I ended up using this method since I had a hard time joining the different curves I have and figured this would be an easier way to do it but I guess I have to find another alternative.
Thanks for the answer.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!