Recreating a contour using coordinate points

2 Ansichten (letzte 30 Tage)
ttopal
ttopal am 13 Okt. 2017
Beantwortet: Rajesh Balagam am 16 Okt. 2017
Hi all,
I am reading contour points from an external file, which are not stored in order.
I want to set a start point and reconstruct the contour in counterclockwise direction.
I have the following code, it works when the points are equidistant and constructs the contour in clockwise direction.
How Can I change it in a way to force it in one direction so it will ignore the closest distance if the point in wrong direction?
Thanks a lot
%data=xlsread('known_point_set.xlsx');
startx=2;
starty=0;
data=[2 1;2 0;2 2;1 2;0 2;-1 2;-2 2;-2 -1;-2 -2;-1 -2;0 -2;-2 1;-2 0;-2 -1;-2 0;1 -2;2 -2;2 -1];
N = size(data,1);
idx=find(data(:,1)==startx & data(:,2)==starty);
data=circshift(data,N-idx+1,1);
dist = pdist2(data,data);
result = NaN(1,N);
result(1) = 1; % first point is first row in data matrix
for ii=2:N
dist(:,result(ii-1)) = Inf;
[~, closest_idx] = min(dist(result(ii-1),:));
result(ii) = closest_idx;
end
newset=data(result,:);
plot(newset(:,1),newset(:,2))
xlswrite('screen.xlsx',newset);

Akzeptierte Antwort

Rajesh Balagam
Rajesh Balagam am 16 Okt. 2017
You can try using a variant of Graham Scan algorithm:

Weitere Antworten (0)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by