Skip to content

Commit

Permalink
comp geo class to have some useful functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyBoivie authored and JimmyBoivie committed Dec 5, 2015
1 parent d56c045 commit 4b2b3a4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main/CompGeo.pde
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit 4b2b3a4

Please sign in to comment.