How to plot closed polygon from set of random points with edges not intersecting?
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
akash sonnad
el 11 de Mayo de 2018
Comentada: KSSV
el 14 de Mayo de 2018
I have set of random points in 2D plane, and have to make a closed polygon without any intersection between edges. There is a possibility that one or more polygons can be drawn. How do I get all those possible polygons along with their perimeter.
11 comentarios
Respuesta aceptada
KSSV
el 11 de Mayo de 2018
Editada: KSSV
el 11 de Mayo de 2018
How about this?
N = 100 ;
x = rand(1,N) ;
y = rand(1,N) ;
P = [x; y]; % coordinates / points
c = mean(P,2); % mean/ central point
d = P-c ; % vectors connecting the central point and the given points
th = atan2(d(2,:),d(1,:)); % angle above x axis
[th, idx] = sort(th); % sorting the angles
P = P(:,idx); % sorting the given points
P = [P P(:,1)]; % add the first at the end to close the polygon
plot( P(1,:), P(2,:), '.-r');
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Elementary Polygons 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!