判断有序的3个点是顺时针还是逆时针 (Orientation of 3 ordered points)

1. 从叉乘的含义,设3点为ABC,ABxAC:代表平行四边形的面积,为0说明3点共线,大于0说明顺时针,小于0说明逆时针

如果展开到3位,其实就是在看z的正负

ref:https://zhidao.baidu.com/question/102397466.html

 

2. 从2条线段的斜率着手

The idea is to use slope.  



Slope of line segment (p1, p2): σ = (y2 - y1)/(x2 - x1)
Slope of line segment (p2, p3): τ = (y3 - y2)/(x3 - x2)

If  σ < τ, the orientation is counterclockwise (left turn)
If  σ = τ, the orientation is collinear
If  σ > τ, the orientation is clockwise (right turn)

Using above values of σ and τ, we can conclude that, 
the orientation depends on sign of  below expression: 
(y2 - y1)*(x3 - x2) - (y3 - y2)*(x2 - x1)

Above expression is negative when σ < τ, i.e., counterclockwise
Above expression is 0 when σ = τ, i.e., collinear
Above expression is positive when σ > τ, i.e., clockwise

其结果与第一种方法计算方式相同

ref:https://www.geeksforgeeks.org/orientation-3-ordered-points/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值