Length of a 3D curve.
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
John D'Errico
am 29 Mai 2015
Bearbeitet: John D'Errico
am 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 Kommentare
Dasharath Gulvady
am 29 Mai 2015
Bearbeitet: Dasharath Gulvady
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Splines finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!