Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Order set of 2d points to convert to a poligon
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
You can’t perform that action at this time.