Rearranging an array of vertices of a geometry to compute the perimeter
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SAMUEL AYINDE
el 23 de Sept. de 2018
Respondida: Image Analyst
el 23 de Sept. de 2018
Please, find the attached picture. I have the following x and y coordinates of a geometry which are the vertices of a geometry but they are not orderly arranged (1). I need the vertices to be arranged following a counterclockwise direction in order to be able to estimate the perimeter correctly (2). Please, how can I achieve this with matlab code? Thank you so much.
(1) unordered vertices
x y
0 1
0.5 0
0 0.5
0.5 0.8
0.5 0.5
0.3 1
0.5 0.2
0.5 1
0 0
0.4 0
0.1 1
0.1 0
0 0.8
0 0
(2) ordered vertices in counterclockwise direction
x y
0 0
0.1 0
0.4 0
0.5 0
0.5 0.2
0.5 0.5
0.5 0.8
0.5 1
0.3 1
0.1 1
0 1
0 0.8
0 0.5
0 0
0 comentarios
Respuesta aceptada
Image Analyst
el 23 de Sept. de 2018
Use mean() to get the middle of the set of points. Then use atan2d() to get the angle from the center to each of the points. Then use sort(). It's really super easy. Try it and write back if you can't figure it out. Here's a start:
xCenter = mean(x);
yCenter = mean(y);
angles = atan2d(y - yCenter, x - xCenter);
[sortedAngles, sortOrder] = sort(angles);
x = x(sortOrder);
y = y(sortOrder);
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Polar Plots 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!