int ccw(pair<int, int> a, pair<int, int> b, pair<int, int> c)
{
int op = a.first*b.second + b.first*c.second + c.first*a.second;
op -= (a.second*b.first + b.second*c.first + c.second*a.first);
if (op > 0)return 1;
else if (op == 0)return 0;
else return -1;
}
bool isIntersect(pair<pair<int, int>, pair<int, int>> x, pair<pair<int, int>, pair<int, int>> y)
{
pair<int, int> a = x.first;
pair<int, int> b = x.second;
pair<int, int> c = y.first;
pair<int, int> d = y.second;
int ab = ccw(a, b, c)*ccw(a, b, d);
int cd = ccw(c, d, a)*ccw(c, d, b);
if (ab == 0 && cd == 0)
{
if (a > b)swap(a, b);
if (c > d)swap(c, d);
return (c <= b&&a <= d);
}
return (ab <= 0 && cd <= 0);
}
출처: https://jason9319.tistory.com/358