Length of a 3D curve.
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
So I have created the code to calculate the length of a 3D curve which is:
function length_total = spacecurvelength(x,y,z,a,b,n)
% x, y and z are the curves
% a=lower limit b=upper limit n = number of straight lines used to approximate the curve length
syms s
N= a:(b-a)/n:b;
xi=subs(x,s,N);
yi=subs(y,s,N);
zi=subs(z,s,N);
length_total=0;
m=length(N);
% there are m-1 splines for m points
for i=1:1:m-1
dx=xi(i+1)-xi(i);
dy= yi(i+1)-yi(i);
dz=zi(i+1)-zi(i);
length_each=sqrt(dx^2+dy^2+dz^2);
length_total=length_total+length_each;
end
end
I am calling it with:
clear;
curvelength = spacecurvelength(@(s) 2*sin(s),3*cos(s)*exp(s),s.^2/10,-4*pi,pi,100)
But I'm getting the error
Undefined function or variable 's'.
0 Commenti
Risposte (2)
John D'Errico
il 29 Mag 2015
Modificato: John D'Errico
il 29 Mag 2015
Or, you could just use my arclength code which does the arclength computation using either a spline or a piecewise linear approximation when speed is needed.
0 Commenti
Dasharath Gulvady
il 29 Mag 2015
Modificato: Dasharath Gulvady
il 29 Mag 2015
You have declared 's' inside "spacecurvelength" function. I am guessing it needs to be declared outside.
>> syms s;
>> curvelength = spacecurvelength(@(s) 2*sin(s),3*cos(s)*exp(s),s.^2/10,-4*pi,pi,100)
0 Commenti
Vedere anche
Categorie
Scopri di più su Splines in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!