如何确定多边形点列表是否按顺时针顺序排列? [英] How to determine if a list of polygon points are in clockwise order?
问题描述
例如:
我有一个积分列表,如何查找它们是否按顺时针顺序排列?
point [0] =(5,0)
point [1] =(6,4)
point [2] =(4,5)
point [3] =(1,5)
point [4] =(1,0)
会说它是逆时针的(或者对于一些人是逆时针的)。
一些建议的方法在非凸多边形(例如新月形)的情况下会失败。这是一个简单的方法,它可以与非凸多边形一起工作(它甚至可以像八分之一的自交多边形一样工作,告诉你它是否大多数情况下是顺时针方向)。
b$ b
在边上求和,(x 2 - x 1)y(y 2 + y) > 1 子>)。如果结果为正值,则曲线为顺时针,如果为负值,则曲线为逆时针。 (结果是封闭区域的两倍,带有+/-约定。)
point [0] =(5,0 )边缘[0]:(6-5)(4 + 0)= 4
point [1] =(6,4)边缘[1]:(4-6)(5 + 4)= -18 (1)(5 + 5)= -30
point [3] =(1,5)edge [3] :(1-1)(0 + 5)= 0
point [4] =(1,0)edge [4]:(5-1)(0 + 0)= 0
- -
-44逆时针
Having a list of points, how do I find if they are in clockwise order?
For example:
point[0] = (5,0)
point[1] = (6,4)
point[2] = (4,5)
point[3] = (1,5)
point[4] = (1,0)
would say that it is anti-clockwise (or counter-clockwise, for some people).
Some of the suggested methods will fail in the case of a non-convex polygon, such as a crescent. Here's a simple one that will work with non-convex polygons (it'll even work with a self-intersecting polygon like a figure-eight, telling you whether it's mostly clockwise).
Sum over the edges, (x2 − x1)(y2 + y1). If the result is positive the curve is clockwise, if it's negative the curve is counter-clockwise. (The result is twice the enclosed area, with a +/- convention.)
point[0] = (5,0) edge[0]: (6-5)(4+0) = 4
point[1] = (6,4) edge[1]: (4-6)(5+4) = -18
point[2] = (4,5) edge[2]: (1-4)(5+5) = -30
point[3] = (1,5) edge[3]: (1-1)(0+5) = 0
point[4] = (1,0) edge[4]: (5-1)(0+0) = 0
---
-44 counter-clockwise
这篇关于如何确定多边形点列表是否按顺时针顺序排列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!