Recreating a contour using coordinate points
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
ttopal
le 13 Oct 2017
Réponse apportée : Rajesh Balagam
le 16 Oct 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);
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!