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 23dfcca431 2011-02-23 kinaba: }