Rearranging an array of vertices of a geometry to compute the perimeter

2 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2018-9-23
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 个)

类别

Help CenterFile Exchange 中查找有关 Computational Geometry 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by