4fd800b3a8 2011-02-23 kinaba: //------------------------------------------------------------- 4fd800b3a8 2011-02-23 kinaba: // ccw 4fd800b3a8 2011-02-23 kinaba: // 4fd800b3a8 2011-02-23 kinaba: // Verified by 4fd800b3a8 2011-02-23 kinaba: // - SRM 492 Div1 LV1 4fd800b3a8 2011-02-23 kinaba: //------------------------------------------------------------- 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: double outer_prod(const CMP& a, const CMP& b) { return imag(conj(a)*b); } 4fd800b3a8 2011-02-23 kinaba: double inner_prod(const CMP& a, const CMP& b) { return real(conj(a)*b); } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: int ccw(const CMP& a, CMP b, CMP c) { 4fd800b3a8 2011-02-23 kinaba: b -= a; c -= a; 4fd800b3a8 2011-02-23 kinaba: if( outer_prod(b,c) > 0 ) return +1; // counter clockwise 4fd800b3a8 2011-02-23 kinaba: if( outer_prod(b,c) < 0 ) return -1; // clockwise 4fd800b3a8 2011-02-23 kinaba: if( inner_prod(b,c) < 0 ) return +2; // c--[a--b] on line 4fd800b3a8 2011-02-23 kinaba: if( norm(b) < norm(c) ) return -2; // [a--b]--c on line 4fd800b3a8 2011-02-23 kinaba: return 0; // [a--c--b] on line 4fd800b3a8 2011-02-23 kinaba: }