确定线段的方向是顺时针还是逆时针 [英] Determine whether the direction of a line segment is clockwise or anti clockwise

查看:152
本文介绍了确定线段的方向是顺时针还是逆时针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个2D点(x1,y1),(x2,y2)......(Xn,Yn)代表弯曲线段的列表,是否有任何公式可以确定绘制该线段的方向是顺时针还是逆时针?

I have a list of 2D points (x1,y1),(x2,y2)......(Xn,Yn) representing a curved segment, is there any formula to determine whether the direction of drawing that segment is clockwise or anti clockwise ?

感谢您的帮助

推荐答案

一种可能的方法.如果您的点列表所代表的线的采样足够均匀且平滑,并且该线足够简单,则应该可以很好地工作.

One possible approach. It should work reasonably well if the sampling of the line represented by your list of points is uniform and smooth enough, and if the line is sufficiently simple.

  1. 减去均值以使直线居中".
  2. 转换为极坐标以获取角度.
  3. 展开角度,以确保其增量有意义.
  4. 检查总增量是正数还是负数.

我假设您具有 x y 向量中的数据.

I'm assuming you have the data in x and y vectors.

theta = cart2pol(x-mean(x), y-mean(y)); %// steps 1 and 2
theta = unwrap(theta); %// step 3
clockwise = theta(end)<theta(1); %// step 4. Gives 1 if CW, 0 if ACW

这仅考虑所有点的整合效应.它不会告诉您沿途是否存在扭结"或具有不同转向方向的部分.

This only considers the integrated effect of all points. It doesn't tell you if there are "kinks" or sections with different directions of turn along the way.

一个可能的改进是用某种积分代替 x y 的平均值.原因是:如果某个区域的采样比较密集,则平均值将偏向该区域,而积分则不会.

A possible improvement would be to replace the average of x and y by some kind of integral. The reason is: if sampling is denser in a region the average will be biased towards that, whereas the integral wouldn't.

这篇关于确定线段的方向是顺时针还是逆时针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆