How to correctly order polygon vertices?

32 ビュー (過去 30 日間)
Tyler
Tyler 2017 年 11 月 10 日
コメント済み: Guy Tsror 2017 年 11 月 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?

採用された回答

Matt J
Matt J 2017 年 11 月 10 日
編集済み: Matt J 2017 年 11 月 10 日
  1. Compute the centroid of the "polygon"
  2. Compute the rays from the centroid to each of your "vertices".
  3. Use atan2 to compute the angle of this ray from the horizontal
  4. Sort the vertices according to this angle.
  5 件のコメント
Tyler
Tyler 2017 年 11 月 30 日
You need rays to compute the angle from the horizontal, but the angle is independent of the ray length. So technically, if I understand it correctly, you don't even need to use the centroid. You could originate the rays from any point inside the polygon. The ray lengths would be different, but the angles from the horizontal will still give the correct order.
Guy Tsror
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 ExchangeBounding Regions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by