判断3个点是顺时针方向、逆时针方向还是共线

struct Point
{
    int32_t x;
    int32_t y;
    
}    
enum Orientation
    {
        ORIENTATION_CCW = 1,            //逆时针
        ORIENTATION_CW = -1,            //顺时针
        ORIENTATION_COLINEAR = 0        //共线
    };
static inline Orientation orient(const Point& a,const Point& b,const Point& c)
{
        static_assert(sizeof(coord_t) * 2 == sizeof(int64_t),"orient works with 32 bit                 coordinates");
        int64_t u = int64_t(b.x()) * int64_t(c.y()) - int64_t(b.y()) * int64_t(c.x());
        int64_t v = int64_t(a.x()) * int64_t(c.y()) - int64_t(a.y()) * int64_t(c.x());
        int64_t w = int64_t(a.x()) * int64_t(b.y()) - int64_t(a.y()) * int64_t(b.x());
        int64_t d = u - v + w;
        return (d > 0) ? ORIENTATION_CCW : ((d == 0) ? ORIENTATION_COLINEAR : ORIENTATION_CW);
}

当叉积和大于0时,则逆时针方向。

                小于0时,顺时针方向。

                等于0时,共线。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值