de.lmu.ifi.dbs.elki.math
Class ConvexHull2D

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.math.ConvexHull2D

@Reference(authors="Paul Graham",
           title="An Efficient Algorithm for Determining the Convex Hull of a Finite Planar Set",
           booktitle="Information Processing Letters 1")
public class ConvexHull2D
extends Object

Classes to compute the convex hull of a set of points in 2D, using the classic Grahams scan. Also computes a bounding box.


Field Summary
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  List<Vector> points
          The current set of points
 
Constructor Summary
ConvexHull2D()
          Constructor.
 
Method Summary
 void add(Vector 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(Vector a, Vector origin)
          Get the relative X coordinate to the origin.
private  double getRY(Vector a, Vector origin)
          Get the relative Y coordinate to the origin.
private  void grahamScan()
          The actual graham scan main loop.
private  boolean isConvex(Vector a, Vector b, Vector c)
          Simple convexity test.
protected  boolean isLeft(Vector a, Vector b, Vector o)
          Test whether a point is left of the other wrt. the origin.
private  double mdist(Vector a, Vector b)
          Manhattan distance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

points

private List<Vector> points
The current set of points


minmaxX

private DoubleMinMax minmaxX
Min/Max in X


minmaxY

private DoubleMinMax minmaxY
Min/Max in Y


ok

private boolean ok
Flag to indicate that the hull has been computed.


factor

private double factor
Scaling factor if we have very small polygons. TODO: needed? Does this actually improve things?

Constructor Detail

ConvexHull2D

public ConvexHull2D()
Constructor.

Method Detail

add

public void add(Vector point)
Add a single point to the list (this does not compute the hull!)

Parameters:
point - Point to add

computeConvexHull

private void computeConvexHull()
Compute the convex hull.


findStartingPoint

private void findStartingPoint()
Find the starting point, and sort it to the beginning of the list. The starting point must be on the outer hull. Any "skyline" point will do, e.g. the one with the lowest Y coordinate and for ties with the lowest X.


getRX

private final double getRX(Vector a,
                           Vector origin)
Get the relative X coordinate to the origin.

Parameters:
a -
origin - origin vector
Returns:
relative X coordinate

getRY

private final double getRY(Vector a,
                           Vector origin)
Get the relative Y coordinate to the origin.

Parameters:
a -
origin - origin vector
Returns:
relative Y coordinate

isLeft

protected final boolean isLeft(Vector a,
                               Vector b,
                               Vector o)
Test whether a point is left of the other wrt. the origin.

Parameters:
a - Vector A
b - Vector B
o - Origin vector
Returns:
true when left

mdist

private double mdist(Vector a,
                     Vector b)
Manhattan distance.

Parameters:
a - Vector A
b - Vector B
Returns:
Manhattan distance

isConvex

private final boolean isConvex(Vector a,
                               Vector b,
                               Vector c)
Simple convexity test.

Parameters:
a - Vector A
b - Vector B
c - Vector C
Returns:
convexity

grahamScan

private void grahamScan()
The actual graham scan main loop.


getHull

public Polygon getHull()
Compute the convex hull, and return the resulting polygon.

Returns:
Polygon of the hull

Release 0.4.0 (2011-09-20_1324)