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时,共线。