diff --git a/main/CompGeo.pde b/main/CompGeo.pde new file mode 100644 index 0000000..ff8fb22 --- /dev/null +++ b/main/CompGeo.pde @@ -0,0 +1,16 @@ +public static class CompGeo { + + public int CCW(Vertex a, Vertex b, Vertex c) { + // Return 1 if turn abc is ccw -1 if turn abc is cw 0 if no turn + float f = (b.getX() - a.getX())*(c.getY() - a.getY()) - (c.getX() - a.getX())*(b.getY()-a.getY()); + if (f < 0) { return -1; } + if (f > 0) { return 1; } + return 0; + } + + public int immediateCCW(Vertex parent, Vertex child, Vertex v1, Vertex v2) { + if (CCW(parent, child, v1) > CCW(parent, child, v2)) { return 1; } + return CCW(parent, v1, v2); + } + +} \ No newline at end of file