- Compute the centroid of the "polygon"
- Compute the rays from the centroid to each of your "vertices".
- Use atan2 to compute the angle of this ray from the horizontal
- Sort the vertices according to this angle.
How to correctly order polygon vertices?
22 次查看(过去 30 天)
显示 更早的评论
I have a set of vertices [x,y] for a specific polygon. I want to use the inpolygon function to determine points within the polygon. However, the vertices are currently out of order and do not work with inpolygon. I have tried using convhull to clean up the ordering, but doing this ignores some of the vertices, and I need to keep all of them.
I've attached an image of what this looks like.
The blue line is the plot of the vertices in their current order. The blue circles are each of the vertices, and the red stars are the points considered when using the convex hull (due to slight curvature in some of the edges, the blue circles without red stars are excluded from the convex hull). What approach would allow me to correctly re-order my vertices?
0 个评论
采纳的回答
Matt J
2017-11-10
编辑:Matt J
2017-11-10
5 个评论
Guy Tsror
2017-11-30
I did use the centroid when calculating this - it gives you the length of the triangle sides when you consider the vertices of the polygon.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computational Geometry 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!