Created
August 3, 2015 00:33
-
-
Save facundoq/39b4772151291fd41543 to your computer and use it in GitHub Desktop.
Order set of 2d points to convert to a poligon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [poligon,indices]=poligon_from_set_of_points(points,max_distance) | |
% | |
% Note that a subset of the points may be selected if the distance between | |
% two points exceeds max_distance | |
dist = pdist2(points,points); | |
N = size(points,1); | |
indices = NaN(1,N); | |
indices(1) = 1; % first point is first row in x matrix | |
for i=2:N | |
dist(:,indices(i-1)) = Inf; | |
[distance, closest_idx] = min(dist(indices(i-1),:)); | |
if (distance<max_distance) | |
indices(i) = closest_idx; | |
else | |
indices(i:end)=[]; | |
break; | |
end | |
end | |
poligon=points(indices,:); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment