Length of a 3D curve.
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
John D'Errico
le 29 Mai 2015
Modifié(e) : John D'Errico
le 29 Mai 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 commentaires
Dasharath Gulvady
le 29 Mai 2015
Modifié(e) : Dasharath Gulvady
le 29 Mai 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 commentaires
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!