Dividing an arc to a segment and comparing straightness among segments

조회 수: 9 (최근 30일)
Hari krishnan
Hari krishnan 2019년 1월 7일
편집: Hari krishnan 2019년 1월 7일
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개)

카테고리

Help CenterFile 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!

Translated by