Class Tri
A memory-efficient representation of a triangle in a triangulation.
Contains three vertices, and links to adjacent Tri
s for each edge.
Tri
s are constructed independently, and if needed linked
into a triangulation using TriangulationBuilder.
The set of Tris containing boundary edges are called the triangulation border.
Inherited Members
Namespace: NetTopologySuite.Triangulate.Tri
Assembly: NetTopologySuite.dll
Syntax
public class Tri
Constructors
| Edit this page View SourceTri(Coordinate, Coordinate, Coordinate)
Creates a triangle with the given vertices. The vertices should be oriented clockwise.
Declaration
public Tri(Coordinate p0, Coordinate p1, Coordinate p2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p0 | The first triangle vertex |
Coordinate | p1 | The second triangle vertex |
Coordinate | p2 | The third triangle vertex |
Properties
| Edit this page View SourceArea
Gets the area of the triangle.
Declaration
public double Area { get; }
Property Value
Type | Description |
---|---|
double | The area of the triangle |
Length
Gets the perimeter length of the perimeter of the triangle.
Declaration
public double Length { get; }
Property Value
Type | Description |
---|---|
double |
NumAdjacent
Computes the number of triangle adjacent to this triangle. This is a number in the range [0,2].
Declaration
public int NumAdjacent { get; }
Property Value
Type | Description |
---|---|
int | The number of adjacent triangles |
P0
Gets a value indicating the 1st point of this Tri
.
Declaration
protected Coordinate P0 { get; }
Property Value
Type | Description |
---|---|
Coordinate |
P1
Gets a value indicating the 2nd point of this Tri
.
Declaration
protected Coordinate P1 { get; }
Property Value
Type | Description |
---|---|
Coordinate |
P2
Gets a value indicating the 3rd point of this Tri
.
Declaration
protected Coordinate P2 { get; }
Property Value
Type | Description |
---|---|
Coordinate |
Tri0
Gets a value indicating the adjacent Tri
across the edge P0 clockwise towards the next point.
Declaration
protected Tri Tri0 { get; }
Property Value
Type | Description |
---|---|
Tri |
Tri1
Gets a value indicating the adjacent Tri
across the edge P1 clockwise towards the next point.
Declaration
protected Tri Tri1 { get; }
Property Value
Type | Description |
---|---|
Tri |
Tri2
Gets a value indicating the adjacent Tri
across the edge P2 clockwise towards the next point.
Declaration
protected Tri Tri2 { get; }
Property Value
Type | Description |
---|---|
Tri |
Methods
| Edit this page View SourceAreaOf(IEnumerable<Tri>)
Computes the area of a set of Tris.
Declaration
public static double AreaOf(IEnumerable<Tri> triList)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Tri> | triList | A set of tris |
Returns
Type | Description |
---|---|
double | The total area of the triangles |
Create(Coordinate, Coordinate, Coordinate)
Creates a triangle with the given vertices. The vertices should be oriented clockwise.
Declaration
public static Tri Create(Coordinate p0, Coordinate p1, Coordinate p2)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p0 | The first triangle vertex |
Coordinate | p1 | The second triangle vertex |
Coordinate | p2 | The third triangle vertex |
Returns
Type | Description |
---|---|
Tri | The created trianlge |
Create(Coordinate[])
Creates a triangle from an array with three vertex coordinates. The vertices should be oriented clockwise.
Declaration
public static Tri Create(Coordinate[] pts)
Parameters
Type | Name | Description |
---|---|---|
Coordinate[] | pts | The array of vertex coordinates |
Returns
Type | Description |
---|---|
Tri | The created triangle |
Degree(int, IList<Tri>)
Computes the degree of a Tri vertex, which is the number of tris containing it. This must be done by searching the entire triangulation, since the containing tris may not be adjacent or edge-connected.
Declaration
public int Degree(int index, IList<Tri> triList)
Parameters
Type | Name | Description |
---|---|---|
int | index | The vertex index |
IList<Tri> | triList | The triangulation |
Returns
Type | Description |
---|---|
int | The degree of the vertex |
Flip(int)
Interchanges the vertices of this triangle and a neighbor so that their common edge becomes the the other diagonal of the quadrilateral they form. Neighbour triangle links are modified accordingly.
Declaration
public void Flip(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the adjacent tri to flip with |
GetAdjacent(int)
Gets the triangle adjacent to an edge.
Declaration
public Tri GetAdjacent(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The edge index |
Returns
Type | Description |
---|---|
Tri | The adjacent triangle (may be |
GetCoordinate(int)
Gets the coordinate for a vertex. This is the start vertex of the edge.
Declaration
public Coordinate GetCoordinate(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The vertex (edge) index |
Returns
Type | Description |
---|---|
Coordinate | The vertex coordinate |
GetIndex(Coordinate)
Gets the index of the triangle vertex which has a given coordinate (if any). This is also the index of the edge which originates at the vertex.
Declaration
public int GetIndex(Coordinate p)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p | The coordinate to find |
Returns
Type | Description |
---|---|
int | The vertex index, or -1 if it is not in the triangle |
GetIndex(Tri)
Gets the edge index which a triangle is adjacent to (if any), based on the adjacent triangle link.
Declaration
public int GetIndex(Tri tri)
Parameters
Type | Name | Description |
---|---|---|
Tri | tri | The |
Returns
Type | Description |
---|---|
int | The index of the edge adjacent to the triangle, or -1 if not found |
GetLength(int)
Gets the length of an edge of the triangle.
Declaration
public double GetLength(int edgeIndex)
Parameters
Type | Name | Description |
---|---|---|
int | edgeIndex | The edge index |
Returns
Type | Description |
---|---|
double | The edge length |
HasAdjacent()
Tests if this tri has any adjacent tris.
Declaration
public bool HasAdjacent()
Returns
Type | Description |
---|---|
bool |
|
HasAdjacent(int)
Tests if there is an adjacent triangle to an edge.
Declaration
public bool HasAdjacent(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The edge index |
Returns
Type | Description |
---|---|
bool |
|
IsAdjacent(Tri)
Tests if a triangle is adjacent to some edge of this triangle.
Declaration
public bool IsAdjacent(Tri tri)
Parameters
Type | Name | Description |
---|---|---|
Tri | tri | The triangle to test |
Returns
Type | Description |
---|---|
bool |
|
IsBorder()
Tests if a tri contains a boundary edge, and thus on the border of the triangulation containing it.
Declaration
public bool IsBorder()
Returns
Type | Description |
---|---|
bool |
|
IsBoundary(int)
Tests if an edge is on the boundary of a triangulation.
Declaration
public bool IsBoundary(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of an edge |
Returns
Type | Description |
---|---|
bool |
|
IsInteriorVertex(int)
Tests if a tri vertex is interior. A vertex of a triangle is interior if it is fully surrounded by other triangles.
Declaration
public bool IsInteriorVertex(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The vertex index |
Returns
Type | Description |
---|---|
bool |
|
MidPoint(int)
Computes a coordinate for the midpoint of a triangle edge.
Declaration
public Coordinate MidPoint(int edgeIndex)
Parameters
Type | Name | Description |
---|---|---|
int | edgeIndex | The edge index |
Returns
Type | Description |
---|---|
Coordinate | the midpoint of the triangle edge |
Next(int)
Computes the vertex or edge index which is the next one (counter-clockwise) around the triangle.
Declaration
public static int Next(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index |
Returns
Type | Description |
---|---|
int | The next index value |
OppEdge(int)
Gets the index of the edge opposite a vertex.
Declaration
public static int OppEdge(int vertexIndex)
Parameters
Type | Name | Description |
---|---|---|
int | vertexIndex | The index of the vertex |
Returns
Type | Description |
---|---|
int | The index of the opposite edge |
OppVertex(int)
Gets the index of the vertex opposite an edge.
Declaration
public static int OppVertex(int edgeIndex)
Parameters
Type | Name | Description |
---|---|---|
int | edgeIndex | The edge index |
Returns
Type | Description |
---|---|
int | The index of the opposite vertex |
Prev(int)
Computes the vertex or edge index which is the previous one (counter-clockwise) around the triangle.
Declaration
public static int Prev(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index |
Returns
Type | Description |
---|---|
int | The previous index value |
Remove()
Removes this triangle from a triangulation.
All adjacent references and the references to this
Tri in the adjacent Tris are set to null
.
Declaration
public void Remove()
Remove(IList<Tri>)
Removes this tri from the triangulation containing it. All links between the tri and adjacent ones are nulled.
Declaration
public void Remove(IList<Tri> triList)
Parameters
Type | Name | Description |
---|---|---|
IList<Tri> | triList | The triangulation |
SetAdjacent(Coordinate, Tri)
Sets the triangle adjacent to the edge originating
at a given vertex.
The vertices of the adjacent triangles are
assumed to match the appropriate vertices in this triangle.
Declaration
public void SetAdjacent(Coordinate pt, Tri tri)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | pt | The edge start point |
Tri | tri | The adjacent triangle |
SetAdjacent(Tri, Tri, Tri)
Sets the adjacent triangles.
The vertices of the adjacent triangles are
assumed to match the appropriate vertices in this triangle.
Declaration
public void SetAdjacent(Tri tri0, Tri tri1, Tri tri2)
Parameters
Type | Name | Description |
---|---|---|
Tri | tri0 | The triangle adjacent to edge 0 |
Tri | tri1 | The triangle adjacent to edge 1 |
Tri | tri2 | The triangle adjacent to edge 2 |
SetTri(int, Tri)
Sets the triangle adjacent to an edge.
The vertices of the adjacent triangle are
assumed to match the appropriate vertices in this triangle.
Declaration
public void SetTri(int edgeIndex, Tri tri)
Parameters
Type | Name | Description |
---|---|---|
int | edgeIndex | The edge triangle is adjacent to |
Tri | tri | The adjacent triangle |
Split(Coordinate)
Splits a triangle by a point located inside the triangle. Creates the three new resulting triangles with adjacent links set correctly. Returns the new triangle whose 0'th vertex is the splitting point.
Declaration
public Tri Split(Coordinate p)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | p | The point to insert |
Returns
Type | Description |
---|---|
Tri | The new triangle whose 0'th vertex is |
ToGeometry(ICollection<Tri>, GeometryFactory)
Creates a GeometryCollection of NetTopologySuite.Triangulate.Polygons representing the triangles in a list.
Declaration
public static Geometry ToGeometry(ICollection<Tri> tris, GeometryFactory geomFact)
Parameters
Type | Name | Description |
---|---|---|
ICollection<Tri> | tris | A collection of |
GeometryFactory | geomFact | The GeometryFactory to use |
Returns
Type | Description |
---|---|
Geometry | The |
ToPolygon(GeometryFactory)
Creates a NetTopologySuite.Triangulate.Polygon representing this triangle.
Declaration
public Polygon ToPolygon(GeometryFactory geomFact)
Parameters
Type | Name | Description |
---|---|---|
GeometryFactory | geomFact | The geometry factory |
Returns
Type | Description |
---|---|
Polygon | A polygon |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string |
Overrides
| Edit this page View SourceValidate()
Validates that a Tri is correct. Currently just checks that orientation is CW.
Declaration
public void Validate()
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if Tri is not valid |
Validate(IEnumerable<Tri>)
Validates a list of Tri
s.
Declaration
public static void Validate(IEnumerable<Tri> triList)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Tri> | triList | The list of |
ValidateAdjacent(int)
Validates that the vertices of an adjacent linked triangle are correct.
Declaration
public void ValidateAdjacent(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the adjacent triangle |