How to find the distance between two points along a curve?
19 次查看(过去 30 天)
显示 更早的评论
I have a set of generated X and Y axis data, which have given a curved line. Now, I need to find the distance between two specified points along the curve, not the straight shortest distance between two points but along the curve path. Can someone help me finding this numerically?
7 个评论
Mathieu NOE
2024-4-26
dr represents only the increment of arc length (quite constant in this example)
now you need to do a sum of them - see my answer
回答(2 个)
Mathieu NOE
2024-4-26
编辑:Mathieu NOE
2024-4-26
hello
try this
th = linspace(-pi/2, pi/2, 100);
R = 200;
X = R * sin(th) ; % X-coordinates
Y = R * cos(th) ; % Y-coordinates
dx = diff(X);
dy = diff(Y);
ds = sqrt(dx.^2+dy.^2); % increment of arc length
s = cumsum(ds); % integration => total arc length
s = [0 s]; % add first point : arc length = 0
% compute arc length between two points (defined by index position)
k1 = 25;
k2 = 59;
d = s(k2) - s(k1)
plot(X, Y, 'r.-',X(k1:k2), Y(k1:k2), 'db');
axis square
4 个评论
Torsten
2024-4-27
If you have an explicit equation of your curve, you can use the usual formula for arclength:
R = 200;
fun = @(t)sqrt((R*cos(t)).^2+(R*(-sin(t))).^2)
length_of_curve = integral(fun,-pi/2,pi/2)
2*pi*R/2
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!