![]() | |
Triangulator Class |
Namespace: Ab3d.Utilities
public class Triangulator
The Triangulator type exposes the following members.
Name | Description | |
---|---|---|
![]() | Triangulator(IListPoint) |
Constructor.
|
![]() | Triangulator(IListPoint, IListInt32) |
Constructor.
|
Name | Description | |
---|---|---|
![]() | IsClockwise |
Gets a boolean that specifies if the specified points are oriented in clockwise direction.
|
![]() | IsClosed |
Gets a boolean that specifies if the specified points define a close path.
|
![]() | IsPolygonConvex |
Gets a boolean that specifies if the specified points define a convex polygon.
In convex polygon every internal angle is less than or equal to 180 degrees and every line segment between two vertices remains inside or on the boundary of the polygon.
For example square is convex, but star is not (it is concave).
|
![]() | PolygonArea |
Gets a double that specifies the area defined by the specified points.
|
Name | Description | |
---|---|---|
![]() | CreateTriangleIndices |
CreateTriangleIndices method triangulates the specified points and creates a list of triangle indices that define the polygon.
|
![]() ![]() | Project3DPositionTo2D(IListPoint3D) |
Returns a List of 2D points that are created with projecting the 3D positions onto the xy, xz or yz plane (removing one of the coordinates).
The plane is determined with checking the normal of the first triangle and determining which component of the normal vector is the biggest (this coordinate is removing).
This requires that the positions lie on the same plane. Input positions must not be null or have less that 3 elements.
|
![]() ![]() | Project3DPositionTo2D(IListPoint3D, IListInt32) |
Returns a List of 2D points that are created with projecting the 3D positions onto the xy, xz or yz plane (removing one of the coordinates).
The plane is determined with checking the normal of the first triangle and determining which component of the normal vector is the biggest (this coordinate is removing).
This requires that the positions lie on the same plane. Input positions and polygonIndices must not be null or have less that 3 elements.
|
![]() ![]() | Triangulate |
Triangulate method triangulates the specified points and creates a list of triangle indices that define the polygon.
|
Triangulator uses a process that is called triangulation. Triangulation gets a list of 2D points and creates triangles in such a way that they define a polygon. The triangles can be than used to create 3D objects.
To triangulate a 3D polygon where positions lie on the same plane, use the static Project3DPositionTo2D(IListPoint3D) or Project3DPositionTo2D(IListPoint3D, IListInt32) to convert 3D polygon into 2D polygon. Then you can use this triangulator.
The algorithm that is used in Triangulator first analyzes the polygon defined by the specified points. If the polygon is convex, than a simple triangle fan algorithm is used. Otherwise the ear clipping algorithm is used (based on algorithm defined defined by David Eberly - http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf). The current implementation of Triangulator does not support polygons with holes.
Triangulator can be used in two ways:
- with its static Triangulate(IListPoint) method,
- with creating an instance of Triangulator class and than calling its CreateTriangleIndices method.
When creating an instance of Triangulator you need to specify the list of points. After that it is possible to get some of the properties of the polygon defined by the points: IsClockwise, IsClosed, IsPolygonConvex and PolygonArea. For example the IsClockwise property is useful when creating extruded objects from polygons - if the IsClockwise is false, the normals for the extruded object need to be flipped.
Both Triangulate(IListPoint) and CreateTriangleIndices methods return a List of integer values that can be used as TriangleIndices in the mesh (points can be used as Positions in the mesh).
IMPORTANT:
When the points define an invalid polygon (for example when the polygon lines intersect each other) both Triangulate and CreateTriangleIndices can return a FormatException.
Therefore if you do not control the way the points are defined (for example when user can define them in any way), than you need to catch the FormatException.