Rearranging an array of vertices of a geometry to compute the perimeter
3 次查看(过去 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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!