@Reference(authors="P. Graham", title="An Efficient Algorithm for Determining the Convex Hull of a Finite Planar Set", booktitle="Information Processing Letters 1", url="https://doi.org/10.1016/0020-0190(72)90045-2", bibkey="DBLP:journals/ipl/Graham72") public class GrahamScanConvexHull2D extends java.lang.Object
Reference:
P. Graham
An Efficient Algorithm for Determining the Convex Hull of a Finite Planar
Set
Information Processing Letters 1
Modifier and Type | Field and Description |
---|---|
private double |
factor
Scaling factor if we have very small polygons.
|
private DoubleMinMax |
minmaxX
Min/Max in X
|
private DoubleMinMax |
minmaxY
Min/Max in Y
|
private boolean |
ok
Flag to indicate that the hull has been computed.
|
private java.util.List<double[]> |
points
The current set of points
|
Constructor and Description |
---|
GrahamScanConvexHull2D()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(double... point)
Add a single point to the list (this does not compute the hull!)
|
private void |
computeConvexHull()
Compute the convex hull.
|
private void |
findStartingPoint()
Find the starting point, and sort it to the beginning of the list.
|
Polygon |
getHull()
Compute the convex hull, and return the resulting polygon.
|
private double |
getRX(double[] a,
double[] origin)
Get the relative X coordinate to the origin.
|
private double |
getRY(double[] a,
double[] origin)
Get the relative Y coordinate to the origin.
|
private void |
grahamScan()
The actual graham scan main loop.
|
private boolean |
isConvex(double[] a,
double[] b,
double[] c)
Simple convexity test.
|
protected int |
isLeft(double[] a,
double[] b,
double[] o)
Test whether a point is left of the other wrt. the origin.
|
private double |
mdist(double[] a,
double[] b)
Manhattan distance.
|
private java.util.List<double[]> points
private DoubleMinMax minmaxX
private DoubleMinMax minmaxY
private boolean ok
private double factor
public void add(double... point)
point
- Point to addprivate void computeConvexHull()
private void findStartingPoint()
private double getRX(double[] a, double[] origin)
a
- origin
- origin double[]private double getRY(double[] a, double[] origin)
a
- origin
- origin double[]protected final int isLeft(double[] a, double[] b, double[] o)
a
- double[] Ab
- double[] Bo
- Origin double[]private double mdist(double[] a, double[] b)
a
- double[] Ab
- double[] Bprivate boolean isConvex(double[] a, double[] b, double[] c)
a
- double[] Ab
- double[] Bc
- double[] Cprivate void grahamScan()
public Polygon getHull()
Copyright © 2019 ELKI Development Team. License information.