23dfcca431 2011-02-23 kinaba: //------------------------------------------------------------- 23dfcca431 2011-02-23 kinaba: // ccw 23dfcca431 2011-02-23 kinaba: // 23dfcca431 2011-02-23 kinaba: // Verified by 23dfcca431 2011-02-23 kinaba: // - SRM 492 Div1 LV1 23dfcca431 2011-02-23 kinaba: //------------------------------------------------------------- 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: double outer_prod(const CMP& a, const CMP& b) { return imag(conj(a)*b); } 23dfcca431 2011-02-23 kinaba: double inner_prod(const CMP& a, const CMP& b) { return real(conj(a)*b); } 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: int ccw(const CMP& a, CMP b, CMP c) { 23dfcca431 2011-02-23 kinaba: b -= a; c -= a; 23dfcca431 2011-02-23 kinaba: if( outer_prod(b,c) > 0 ) return +1; // counter clockwise 23dfcca431 2011-02-23 kinaba: if( outer_prod(b,c) < 0 ) return -1; // clockwise 23dfcca431 2011-02-23 kinaba: if( inner_prod(b,c) < 0 ) return +2; // c--[a--b] on line 23dfcca431 2011-02-23 kinaba: if( norm(b) < norm(c) ) return -2; // [a--b]--c on line 23dfcca431 2011-02-23 kinaba: return 0; // [a--c--b] on line ba015e9217 2014-10-04 kinaba: } ba015e9217 2014-10-04 kinaba: ba015e9217 2014-10-04 kinaba: ba015e9217 2014-10-04 kinaba: // intersection of two line segments. ba015e9217 2014-10-04 kinaba: bool cross(CMP p1, CMP p2, CMP P1, CMP P2) { ba015e9217 2014-10-04 kinaba: return ccw(p1,p2,P1)*ccw(p1,p2,P2)<=0 && ccw(P1,P2,p1)*ccw(P1,P2,p2)<=0; 23dfcca431 2011-02-23 kinaba: }