Dividing an arc to a segment and comparing straightness among segments
4 次查看(过去 30 天)
显示 更早的评论
I have a line segment as shown in the figure. What i want to do is to divide the line segments in to 'n' equal sections and calculate the straightness of these segments. The straightness of the line segment is calculated as the arc-length / eucledian distance between initial and final point. I used linspace to divide the line segment to specified number of line segments. But when i try to plot the segment created using linspace i am getting a straight line rather than the actual segment. Can anyone suggest me an accurate method to perform this (ie, divide the line segments in to 'n' equal segments and compare the straightness of these segments) with each other?
Sample 'X and Y coordinates' are attached as matfiles.
%this is for visualising the segment
clear all;
data_req = load('required_data_obj_203.mat');
time = data_req.required_data_obj_203(2:end,1);
X_coord = data_req.required_data_obj_203(2:end,2);
Y_coord = data_req.required_data_obj_203(2:end,3);
idx_required_time = (time >= 1932 & time <= 1980);
time_required = time(idx_required_time);
X_coord_req = X_coord(idx_required_time);
Y_coord_req = Y_coord(idx_required_time);
plot_the_initial_coordinates = plot(X_coord_req(1),Y_coord_req(1));
xlabel('X')
ylabel('Y')
ax = gca;
ax.YDir = 'reverse';
axis([0 6600 0 5000])
for ii = 1:length(time_required)
set(plot_the_initial_coordinates,'Xdata',X_coord_req(1:ii,1),'Ydata',Y_coord_req(1:ii,1),'Color','Red')
drawnow
end
% Code for straightness
n = numel(X_coord_req);
a = 0.0;
length = zeros(n,1);
for i = 1:n-1
length(i) = a + sqrt( (X_coord_req(i+1)-X_coord_req(i))^2 + (Y_coord_req(i+1)-Y_coord_req(i))^2 );
end
arc_length = sum(length);
straight_line_distance = sqrt( (X_coord_req(end)-X_coord_req(1))^2 + (Y_coord_req(end)-Y_coord_req(1))^2);
straigtness = arc_length/straight_line_distance;
% Part for dividng to segments for visualisation
x_segment = linspace(X_coord_req(1),X_coord_req(end),10);
y_segment = linspace(Y_coord_req(1),Y_coord_req(end),10);
plot([x_segment(1,1);x_segment(1,2)],[y_segment(1,1);y_segment(1,2)]);
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!