-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
comp geo class to have some useful functions
- 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |