Length of a 3D curve.
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
John D'Errico
2015-5-29
编辑:John D'Errico
2015-5-29
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 个评论
Dasharath Gulvady
2015-5-29
编辑:Dasharath Gulvady
2015-5-29
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Splines 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!