APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.math

public Class ConvexHull

extends Object
Class Inheritance
Imports
com.badlogic.gdx.utils.FloatArray, .IntArray, .ShortArray

Computes the convex hull of a set of points using the monotone chain convex hull algorithm (aka Andrew's algorithm).
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
private final FloatArray
private final IntArray
private final ShortArray
private final IntArray
private float[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private float
ccw(float p3x, float p3y)

Returns > 0 if the points are a counterclockwise turn, < 0 if clockwise, and 0 if colinear.

public IntArray
computeIndices(FloatArray points, boolean sorted, boolean yDown)

public IntArray
computeIndices(float[] polygon, boolean sorted, boolean yDown)

public IntArray
computeIndices(float[] points, int offset, int count, boolean sorted, boolean yDown)

Computes a hull the same as computePolygon(float[], int, int, boolean) but returns indices of the specified points.

public FloatArray
computePolygon(FloatArray points, boolean sorted)

public FloatArray
computePolygon(float[] polygon, boolean sorted)

public FloatArray

Returns:

pairs of coordinates that describe the convex hull polygon in counterclockwise order. Note the returned array is reused for later calls to the same method.
computePolygon
(float[]
x,y pairs describing points in counter-clockwise order. Duplicate points will result in undefined behavior.
points
,
int offset, int count, boolean
If false, the points will be sorted by the x coordinate then the y coordinate, which is required by the convex hull algorithm. If sorting is done the input array is not modified and count additional working memory is needed.
sorted
)

Returns the convex hull polygon for the given point cloud.

private int
quicksortPartition(final float[] values, int lower, int upper)

private int
quicksortPartitionWithIndices(final float[] values, int lower, int upper, boolean yDown, short[] originalIndices)

private void
sort(float[] values, int
Number of indices, must be even.
count
)

Sorts x,y pairs of values by the x value, then the y value.

private void
sortWithIndices(float[] values, int
Number of indices, must be even.
count
,
boolean yDown)

Sorts x,y pairs of values by the x value, then the y value and stores unsorted original indices.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hullback to summary
private final FloatArray hull
indicesback to summary
private final IntArray indices
originalIndicesback to summary
private final ShortArray originalIndices
quicksortStackback to summary
private final IntArray quicksortStack
sortedPointsback to summary
private float[] sortedPoints

Constructor Detail

ConvexHullback to summary
public ConvexHull()

Method Detail

ccwback to summary
private float ccw(float p3x, float p3y)

Returns > 0 if the points are a counterclockwise turn, < 0 if clockwise, and 0 if colinear.

computeIndicesback to summary
public IntArray computeIndices(FloatArray points, boolean sorted, boolean yDown)
See Also
computeIndices(float[], int, int, boolean, boolean)
computeIndicesback to summary
public IntArray computeIndices(float[] polygon, boolean sorted, boolean yDown)
See Also
computeIndices(float[], int, int, boolean, boolean)
computeIndicesback to summary
public IntArray computeIndices(float[] points, int offset, int count, boolean sorted, boolean yDown)

Computes a hull the same as computePolygon(float[], int, int, boolean) but returns indices of the specified points.

computePolygonback to summary
public FloatArray computePolygon(FloatArray points, boolean sorted)
See Also
computePolygon(float[], int, int, boolean)
computePolygonback to summary
public FloatArray computePolygon(float[] polygon, boolean sorted)
See Also
computePolygon(float[], int, int, boolean)
computePolygonback to summary
public FloatArray computePolygon(float[] points, int offset, int count, boolean sorted)

Returns the convex hull polygon for the given point cloud.

Parameters
points:float[]

x,y pairs describing points in counter-clockwise order. Duplicate points will result in undefined behavior.

sorted:boolean

If false, the points will be sorted by the x coordinate then the y coordinate, which is required by the convex hull algorithm. If sorting is done the input array is not modified and count additional working memory is needed.

Returns:FloatArray

pairs of coordinates that describe the convex hull polygon in counterclockwise order. Note the returned array is reused for later calls to the same method.

quicksortPartitionback to summary
private int quicksortPartition(final float[] values, int lower, int upper)
quicksortPartitionWithIndicesback to summary
private int quicksortPartitionWithIndices(final float[] values, int lower, int upper, boolean yDown, short[] originalIndices)
sortback to summary
private void sort(float[] values, int count)

Sorts x,y pairs of values by the x value, then the y value.

Parameters
count:int

Number of indices, must be even.

sortWithIndicesback to summary
private void sortWithIndices(float[] values, int count, boolean yDown)

Sorts x,y pairs of values by the x value, then the y value and stores unsorted original indices.

Parameters
count:int

Number of indices, must be even.