Recreating a contour using coordinate points
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ttopal
el 13 de Oct. de 2017
Respondida: Rajesh Balagam
el 16 de Oct. de 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 comentarios
Respuesta aceptada
Rajesh Balagam
el 16 de Oct. de 2017
You can try using a variant of Graham Scan algorithm:
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Graph and Network Algorithms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!