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

public Class EarClippingTriangulator

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

A simple implementation of the ear cutting algorithm to triangulate simple polygons without holes. For more information: If the input polygon is not simple (self-intersects), there will be output but it is of unspecified quality (garbage in, garbage out).

If the polygon vertices are very large or very close together then GeometryUtils#isClockwise(float[], int, int) may not be able to properly assess the winding (because it uses floats). In that case the vertices should be adjusted, eg by finding the smallest X and Y values and subtracting that from each vertex.

Authors
[email protected], Nicolas Gramlich (optimizations, collinear edge support), Eric Spitz, Thomas ten Cate (bugfixes, optimizations), Nathan Sweet (rewrite, return indices, no allocation, optimizations)

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private short[]
private final ShortArray
private final ShortArray
private int
private final IntArray
private float[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private int
classifyVertex(int index)

Returns: CONCAVE or CONVEX

private static int
computeSpannedAreaSign(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y)

public ShortArray
public ShortArray
computeTriangles(float[] vertices)

public ShortArray

Returns:

triples of triangle indices in clockwise order. Note the returned array is reused for later calls to the same method.
computeTriangles
(float[]
pairs describing vertices of the polygon, in either clockwise or counterclockwise order.
vertices
,
int offset, int count)

Triangulates the given (convex or concave) simple polygon to a list of triangle vertices.

private void
cutEarTip(int earTipIndex)

private int
private boolean
isEarTip(int earTipIndex)

private int
nextIndex(int index)

private int
previousIndex(int index)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CONCAVEback to summary
private static final int CONCAVE
CONVEXback to summary
private static final int CONVEX
indicesback to summary
private short[] indices
indicesArrayback to summary
private final ShortArray indicesArray
trianglesback to summary
private final ShortArray triangles
vertexCountback to summary
private int vertexCount
vertexTypesback to summary
private final IntArray vertexTypes
verticesback to summary
private float[] vertices

Constructor Detail

EarClippingTriangulatorback to summary
public EarClippingTriangulator()

Method Detail

classifyVertexback to summary
private int classifyVertex(int index)
Returns:int

CONCAVE or CONVEX

computeSpannedAreaSignback to summary
private static int computeSpannedAreaSign(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y)
computeTrianglesback to summary
public ShortArray computeTriangles(FloatArray vertices)
See Also
computeTriangles(float[], int, int)
computeTrianglesback to summary
public ShortArray computeTriangles(float[] vertices)
See Also
computeTriangles(float[], int, int)
computeTrianglesback to summary
public ShortArray computeTriangles(float[] vertices, int offset, int count)

Triangulates the given (convex or concave) simple polygon to a list of triangle vertices.

Parameters
vertices:float[]

pairs describing vertices of the polygon, in either clockwise or counterclockwise order.

Returns:ShortArray

triples of triangle indices in clockwise order. Note the returned array is reused for later calls to the same method.

cutEarTipback to summary
private void cutEarTip(int earTipIndex)
findEarTipback to summary
private int findEarTip()
isEarTipback to summary
private boolean isEarTip(int earTipIndex)
nextIndexback to summary
private int nextIndex(int index)
previousIndexback to summary
private int previousIndex(int index)
triangulateback to summary
private void triangulate()