MATLAB Answers

Dividing an arc to a segment and comparing straightness among segments

1 ビュー (過去 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));
ax = gca;
ax.YDir = 'reverse';
axis([0 6600 0 5000])
for ii = 1:length(time_required)
% 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 );
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);

  0 件のコメント


回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by