public static int PlanarCcw(R2Vector a, R2Vector b) { // Return +1 if the edge AB is CCW around the origin, etc. double sab = (a.DotProd(b) > 0) ? -1 : 1; var vab = a + (b * sab); var da = a.Norm2; var db = b.Norm2; double sign; if (da < db || (da == db && a < b)) { sign = a.CrossProd(vab) * sab; } else { sign = vab.CrossProd(b); } if (sign > 0) { return(1); } if (sign < 0) { return(-1); } return(0); }
public static int PlanarOrderedCcw(R2Vector a, R2Vector b, R2Vector c) { var sum = 0; sum += PlanarCcw(a, b); sum += PlanarCcw(b, c); sum += PlanarCcw(c, a); if (sum > 0) { return(1); } if (sum < 0) { return(-1); } return(0); }