panda3d.core.Triangulator

class Triangulator

This class can triangulate a convex or concave polygon, even one with holes. It is adapted from an algorithm published as:

Narkhede A. and Manocha D., Fast polygon triangulation algorithm based on Seidel’s Algorithm, UNC-CH, 1994.

http://www.cs.unc.edu/~dm/CODE/GEM/chapter.html

It works strictly on 2-d points. See Triangulator3 for 3-d points.

Inheritance diagram

Inheritance diagram of Triangulator

__init__() → None
__init__(param0: Triangulator) → None
clear() → None

Removes all vertices and polygon specifications from the Triangulator, and prepares it to start over.

addVertex(point: LPoint2d) → int

Adds a new vertex to the vertex pool. Returns the vertex index number.

addVertex(x: float, y: float) → int

Adds a new vertex to the vertex pool. Returns the vertex index number.

getNumVertices() → int

Returns the number of vertices in the pool. Note that the Triangulator might append new vertices, in addition to those added by the user, if any of the polygon is self-intersecting, or if any of the holes intersect some part of the polygon edges.

getVertex(n: int) → LPoint2d

Returns the nth vertex.

Return type

LPoint2d

clearPolygon() → None

Removes the current polygon definition (and its set of holes), but does not clear the vertex pool.

addPolygonVertex(index: int) → None

Adds the next consecutive vertex of the polygon. This vertex should index into the vertex pool established by repeated calls to addVertex().

The vertices may be listed in either clockwise or counterclockwise order. Vertices should not be repeated. In particular, do not repeat the first vertex at the end.

isLeftWinding() → bool

Returns true if the polygon vertices are listed in counterclockwise order, or false if they appear to be listed in clockwise order.

beginHole() → None

Finishes the previous hole, if any, and prepares to add a new hole.

addHoleVertex(index: int) → None

Adds the next consecutive vertex of the current hole. This vertex should index into the vertex pool established by repeated calls to addVertex().

The vertices may be listed in either clockwise or counterclockwise order. Vertices should not be repeated.

triangulate() → None

Does the work of triangulating the specified polygon. After this call, you may retrieve the new triangles one at a time by iterating through get_triangle_v0/1/2().

getNumTriangles() → int

Returns the number of triangles generated by the previous call to triangulate().

getTriangleV0(n: int) → int

Returns vertex 0 of the nth triangle generated by the previous call to triangulate().

This is a zero-based index into the vertices added by repeated calls to addVertex().

getTriangleV1(n: int) → int

Returns vertex 1 of the nth triangle generated by the previous call to triangulate().

This is a zero-based index into the vertices added by repeated calls to addVertex().

getTriangleV2(n: int) → int

Returns vertex 2 of the nth triangle generated by the previous call to triangulate().

This is a zero-based index into the vertices added by repeated calls to addVertex().

getVertices() → list
property vertices

Returns the nth vertex.

Return type

Sequence[LPoint2d]