public final class GrahamScan
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
protected static class |
GrahamScan.Turn
An enum denoting a directional-turn between 3 points (vectors).
|
| Modifier | Constructor and Description |
|---|---|
protected |
GrahamScan() |
| Modifier and Type | Method and Description |
|---|---|
protected static boolean |
areAllCollinear(java.util.List<java.awt.Point> points)
Returns true iff all points in
points are collinear. |
static java.util.List<java.awt.Point> |
getConvexHull(int[] xs,
int[] ys)
Returns the convex hull of the points created from
xs and ys. |
static java.util.List<java.awt.Point> |
getConvexHull(java.util.List<java.awt.Point> points)
Returns the convex hull of the points created from the list
points. |
protected static java.awt.Point |
getLowestPoint(java.util.List<java.awt.Point> points)
Returns the points with the lowest y coordinate.
|
protected static java.util.Set<java.awt.Point> |
getSortedPointSet(java.util.List<java.awt.Point> points)
Returns a sorted set of points from the list
points. |
protected static GrahamScan.Turn |
getTurn(java.awt.Point a,
java.awt.Point b,
java.awt.Point c)
Returns the GrahamScan#Turn formed by traversing through the ordered points
a,
b and c. |
protected static boolean areAllCollinear(java.util.List<java.awt.Point> points)
points are collinear.points - the list of points.points are collinear.public static java.util.List<java.awt.Point> getConvexHull(int[] xs,
int[] ys)
xs and ys. Note
that the first and last point in the returned List<java.awt.Point> are the
same point.xs - the x coordinates.ys - the y coordinates.xs and ys.java.lang.IllegalArgumentException - if xs and ys don't have the same
size, if all points are collinear or if there are less than 3 unique points present.public static java.util.List<java.awt.Point> getConvexHull(java.util.List<java.awt.Point> points)
points. Note that the
first and last point in the returned List<java.awt.Point> are the same
point.points - the list of points.points.java.lang.IllegalArgumentException - if all points are collinear or if there are less than 3 unique
points present.protected static java.awt.Point getLowestPoint(java.util.List<java.awt.Point> points)
points - the list of points to return the lowest point from.protected static java.util.Set<java.awt.Point> getSortedPointSet(java.util.List<java.awt.Point> points)
points. The set of points are sorted
in increasing order of the angle they and the lowest point P make with the x-axis. If
tow (or more) points form the same angle towards P, the one closest to P
comes first.points - the list of points to sort.points.getLowestPoint(java.util.List)protected static GrahamScan.Turn getTurn(java.awt.Point a, java.awt.Point b, java.awt.Point c)
a,
b and c. More specifically, the cross product C between the
3 points (vectors) is calculated: (b.x-a.x * c.y-a.y) - (b.y-a.y * c.x-a.x) and if
C is less than 0, the turn is CLOCKWISE, if C is more than 0, the turn is
COUNTER_CLOCKWISE, else the three points are COLLINEAR.a - the starting point.b - the second point.c - the end point.a,
b and c.