Length of a 3D curve.
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
John D'Errico
el 29 de Mayo de 2015
Editada: John D'Errico
el 29 de Mayo de 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 comentarios
Dasharath Gulvady
el 29 de Mayo de 2015
Editada: Dasharath Gulvady
el 29 de Mayo de 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 comentarios
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!