我有一个二维点列表 (x1,y1),(x2,y2)......(Xn,Yn) 代表一个曲线段,是否有任何公式可以确定绘制该段的方向是顺时针还是逆时针?
感谢任何帮助
最佳答案
或者,您可以使用一些线性代数。如果按顺序有 a、b 和 c 三点,则执行以下操作:
1) create the vectors u = (b-a) = (b.x-a.x,b.y-a.y) and v = (c-b) ...
2) calculate the cross product uxv = u.x*v.y-u.y*v.x
3) if uxv is -ve then a-b-c is curving in clockwise direction (and vice-versa).
通过以相同方式沿着更长的曲线行驶,您甚至可以检测到“s”形曲线何时从顺时针方向变为逆时针方向(如果这有用的话)。
关于algorithm - 判断线段的方向是顺时针还是逆时针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25252664/