Class Tri
java.lang.Object
org.locationtech.jts.triangulate.tri.Tri
A memory-efficient representation of a triangle in a triangulation.
Contains three vertices, and links to adjacent Tris for each edge.
Tris are constructed independently, and if needed linked
into a triangulation using
TriangulationBuilder
.
An edge of a Tri in a triangulation is called a boundary edge if it has no adjacent triangle. The set of Tris containing boundary edges are called the triangulation border.
- Author:
- Martin Davis
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Coordinate
protected Coordinate
protected Coordinate
protected Tri
triN is the adjacent triangle across the edge pN - pNN.protected Tri
protected Tri
-
Constructor Summary
ConstructorsConstructorDescriptionTri
(Coordinate p0, Coordinate p1, Coordinate p2) Creates a triangle with the given vertices. -
Method Summary
Modifier and TypeMethodDescriptionstatic double
Computes the area of a set of Tris.static Tri
create
(Coordinate[] pts) Creates a triangle from an array with three vertex coordinates.static Tri
create
(Coordinate p0, Coordinate p1, Coordinate p2) Creates a triangle with the given vertices.int
Computes the degree of a Tri vertex, which is the number of tris containing it.void
flip
(int index) Interchanges the vertices of this triangle and a neighbor so that their common edge becomes the the other diagonal of the quadrilateral they form.getAdjacent
(int index) Gets the triangle adjacent to an edge.double
getArea()
Gets the area of the triangle.getCoordinate
(int index) Gets the coordinate for a vertex.int
Gets the index of the triangle vertex which has a given coordinate (if any).int
Gets the edge index which a triangle is adjacent to (if any), based on the adjacent triangle link.double
Gets the perimeter length of the triangle.double
getLength
(int edgeIndex) Gets the length of an edge of the triangle.boolean
Tests if this tri has any adjacent tris.boolean
hasAdjacent
(int index) Tests if there is an adjacent triangle to an edge.boolean
isAdjacent
(Tri tri) Tests if a triangle is adjacent to some edge of this triangle.boolean
isBorder()
Tests if a tri contains a boundary edge, and thus on the border of the triangulation containing it.boolean
isBoundary
(int index) Tests if an edge is on the boundary of a triangulation.boolean
isInteriorVertex
(int index) Tests if a tri vertex is interior.midpoint
(int edgeIndex) Computes a coordinate for the midpoint of a triangle edge.static int
next
(int index) Computes the vertex or edge index which is the next one (clockwise) around the triangle.int
Computes the number of triangle adjacent to this triangle.static int
oppEdge
(int vertexIndex) Gets the index of the edge opposite a vertex.static int
oppVertex
(int edgeIndex) Gets the index of the vertex opposite an edge.static int
prev
(int index) Computes the vertex or edge index which is the previous one (counter-clockwise) around the triangle.void
remove()
Removes this triangle from a triangulation.void
Removes this tri from the triangulation containing it.void
setAdjacent
(Coordinate pt, Tri tri) Sets the triangle adjacent to the edge originating at a given vertex.void
setAdjacent
(Tri tri0, Tri tri1, Tri tri2) Sets the adjacent triangles.void
Sets the triangle adjacent to an edge.split
(Coordinate p) Spits a triangle by a point located inside the triangle.static Geometry
toGeometry
(Collection<Tri> tris, GeometryFactory geomFact) Creates ainvalid reference
GeometryCollection
Polygon
s representing the triangles in a list.toPolygon
(GeometryFactory geomFact) Creates aPolygon
representing this triangle.toString()
void
validate()
Validates that a tri is correct.static void
Validates a list of Tris.void
validateAdjacent
(int index) Validates that the vertices of an adjacent linked triangle are correct.
-
Field Details
-
p0
-
p1
-
p2
-
tri0
triN is the adjacent triangle across the edge pN - pNN. pNN is the next vertex CW from pN. -
tri1
-
tri2
-
-
Constructor Details
-
Tri
Creates a triangle with the given vertices. The vertices should be oriented clockwise.- Parameters:
p0
- the first triangle vertexp1
- the second triangle vertexp2
- the third triangle vertex
-
-
Method Details
-
toGeometry
Creates ainvalid reference
GeometryCollection
Polygon
s representing the triangles in a list.- Parameters:
tris
- a collection of TrisgeomFact
- the GeometryFactory to use- Returns:
- the polygons for the triangles
-
area
Computes the area of a set of Tris.- Parameters:
triList
- a set of Tris- Returns:
- the total area of the triangles
-
validate
Validates a list of Tris.- Parameters:
triList
- the tris to validate
-
create
Creates a triangle with the given vertices. The vertices should be oriented clockwise.- Parameters:
p0
- the first triangle vertexp1
- the second triangle vertexp2
- the third triangle vertex- Returns:
- the created triangle
-
create
Creates a triangle from an array with three vertex coordinates. The vertices should be oriented clockwise.- Parameters:
pts
- the array of vertex coordinates- Returns:
- the created triangle
-
setAdjacent
Sets the adjacent triangles. The vertices of the adjacent triangles are assumed to match the appropriate vertices in this triangle.- Parameters:
tri0
- the triangle adjacent to edge 0tri1
- the triangle adjacent to edge 1tri2
- the triangle adjacent to edge 2
-
setAdjacent
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.- Parameters:
pt
- the edge start pointtri
- the adjacent triangle
-
setTri
Sets the triangle adjacent to an edge. The vertices of the adjacent triangle are assumed to match the appropriate vertices in this triangle.- Parameters:
edgeIndex
- the edge triangle is adjacent totri
- the adjacent triangle
-
split
Spits 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.- Parameters:
p
- the point to insert- Returns:
- the new triangle whose 0'th vertex is p
-
flip
public void flip(int index) 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.- Parameters:
index
- the index of the adjacent tri to flip with
-
degree
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.- Parameters:
index
- the vertex indextriList
- the triangulation- Returns:
- the degree of the vertex
-
remove
Removes this tri from the triangulation containing it. All links between the tri and adjacent ones are nulled.- Parameters:
triList
- the triangulation
-
remove
public void remove()Removes this triangle from a triangulation. All adjacent references and the references to this Tri in the adjacent Tris are set tonullinvalid input: '<'/code.
-
validate
public void validate()Validates that a tri is correct. Currently just checks that orientation is CW. -
validateAdjacent
public void validateAdjacent(int index) Validates that the vertices of an adjacent linked triangle are correct.- Parameters:
index
- the index of the adjacent triangle
-
getCoordinate
Gets the coordinate for a vertex. This is the start vertex of the edge.- Parameters:
index
- the vertex (edge) index- Returns:
- the vertex coordinate
-
getIndex
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.- Parameters:
p
- the coordinate to find- Returns:
- the vertex index, or -1 if it is not in the triangle
-
getIndex
Gets the edge index which a triangle is adjacent to (if any), based on the adjacent triangle link.- Parameters:
tri
- the tri to find- Returns:
- the index of the edge adjacent to the triangle, or -1 if not found
-
getAdjacent
Gets the triangle adjacent to an edge.- Parameters:
index
- the edge index- Returns:
- the adjacent triangle (may be null)
-
hasAdjacent
public boolean hasAdjacent()Tests if this tri has any adjacent tris.- Returns:
- true if there is at least one adjacent tri
-
hasAdjacent
public boolean hasAdjacent(int index) Tests if there is an adjacent triangle to an edge.- Parameters:
index
- the edge index- Returns:
- true if there is a triangle adjacent to edge
-
isAdjacent
Tests if a triangle is adjacent to some edge of this triangle.- Parameters:
tri
- the triangle to test- Returns:
- true if the triangle is adjacent
- See Also:
-
numAdjacent
public int numAdjacent()Computes the number of triangle adjacent to this triangle. This is a number in the range [0,2].- Returns:
- the number of adjacent triangles
-
isInteriorVertex
public boolean isInteriorVertex(int index) Tests if a tri vertex is interior. A vertex of a triangle is interior if it is fully surrounded by other triangles.- Parameters:
index
- the vertex index- Returns:
- true if the vertex is interior
-
isBorder
public boolean isBorder()Tests if a tri contains a boundary edge, and thus on the border of the triangulation containing it.- Returns:
- true if the tri is on the border of the triangulation
-
isBoundary
public boolean isBoundary(int index) Tests if an edge is on the boundary of a triangulation.- Parameters:
index
- index of an edge- Returns:
- true if the edge is on the boundary
-
next
public static int next(int index) Computes the vertex or edge index which is the next one (clockwise) around the triangle.- Parameters:
index
- the index- Returns:
- the next index value
-
prev
public static int prev(int index) Computes the vertex or edge index which is the previous one (counter-clockwise) around the triangle.- Parameters:
index
- the index- Returns:
- the previous index value
-
oppVertex
public static int oppVertex(int edgeIndex) Gets the index of the vertex opposite an edge.- Parameters:
edgeIndex
- the edge index- Returns:
- the index of the opposite vertex
-
oppEdge
public static int oppEdge(int vertexIndex) Gets the index of the edge opposite a vertex.- Parameters:
vertexIndex
- the index of the vertex- Returns:
- the index of the opposite edge
-
midpoint
Computes a coordinate for the midpoint of a triangle edge.- Parameters:
edgeIndex
- the edge index- Returns:
- the midpoint of the triangle edge
-
getArea
public double getArea()Gets the area of the triangle.- Returns:
- the area of the triangle
-
getLength
public double getLength()Gets the perimeter length of the triangle.- Returns:
- the perimeter length
-
getLength
public double getLength(int edgeIndex) Gets the length of an edge of the triangle.- Parameters:
edgeIndex
- the edge index- Returns:
- the edge length
-
toPolygon
Creates aPolygon
representing this triangle.- Parameters:
geomFact
- the geometry factory- Returns:
- a polygon
-
toString
-