public class Tri extends Object
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.
Constructor and Description |
---|
Tri(Coordinate p0,
Coordinate p1,
Coordinate p2)
Creates a triangle with the given vertices.
|
Modifier and Type | Method and Description |
---|---|
static double |
area(List<? extends Tri> triList)
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 |
degree(int index,
List<? extends Tri> triList)
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.
|
Tri |
getAdjacent(int index)
Gets the triangle adjacent to an edge.
|
double |
getArea()
Gets the area of the triangle.
|
Coordinate |
getCoordinate(int index)
Gets the coordinate for a vertex.
|
int |
getIndex(Coordinate p)
Gets the index of the triangle vertex which has a given coordinate (if any).
|
int |
getIndex(Tri tri)
Gets the edge index which a triangle is adjacent to (if any),
based on the adjacent triangle link.
|
double |
getLength()
Gets the perimeter length of the triangle.
|
double |
getLength(int edgeIndex)
Gets the length of an edge of the triangle.
|
boolean |
hasAdjacent()
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.
|
Coordinate |
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 |
numAdjacent()
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 |
remove(List<? extends Tri> triList)
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 |
setTri(int edgeIndex,
Tri tri)
Sets the triangle adjacent to an edge.
|
Tri |
split(Coordinate p)
Spits a triangle by a point located inside the triangle.
|
static Geometry |
toGeometry(Collection<Tri> tris,
GeometryFactory geomFact)
Creates a
GeometryCollection of Polygon s
representing the triangles in a list. |
Polygon |
toPolygon(GeometryFactory geomFact)
Creates a
Polygon representing this triangle. |
String |
toString() |
void |
validate()
Validates that a tri is correct.
|
static void |
validate(List<Tri> triList)
Validates a list of Tris.
|
void |
validateAdjacent(int index)
Validates that the vertices of an adjacent linked triangle are correct.
|
public Tri(Coordinate p0, Coordinate p1, Coordinate p2)
p0
- the first triangle vertexp1
- the second triangle vertexp2
- the third triangle vertexpublic static Geometry toGeometry(Collection<Tri> tris, GeometryFactory geomFact)
GeometryCollection
of Polygon
s
representing the triangles in a list.tris
- a collection of TrisgeomFact
- the GeometryFactory to usepublic static double area(List<? extends Tri> triList)
triList
- a set of Trispublic static void validate(List<Tri> triList)
triList
- the tris to validatepublic static Tri create(Coordinate p0, Coordinate p1, Coordinate p2)
p0
- the first triangle vertexp1
- the second triangle vertexp2
- the third triangle vertexpublic static Tri create(Coordinate[] pts)
pts
- the array of vertex coordinatespublic void setAdjacent(Tri tri0, Tri tri1, Tri tri2)
tri0
- the triangle adjacent to edge 0tri1
- the triangle adjacent to edge 1tri2
- the triangle adjacent to edge 2public void setAdjacent(Coordinate pt, Tri tri)
pt
- the edge start pointtri
- the adjacent trianglepublic void setTri(int edgeIndex, Tri tri)
edgeIndex
- the edge triangle is adjacent totri
- the adjacent trianglepublic Tri split(Coordinate p)
p
- the point to insertpublic void flip(int index)
index
- the index of the adjacent tri to flip withpublic int degree(int index, List<? extends Tri> triList)
index
- the vertex indextriList
- the triangulationpublic void remove(List<? extends Tri> triList)
triList
- the triangulationpublic void remove()
null
-
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
public Coordinate getCoordinate(int index)
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
public int getIndex(Coordinate p)
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
public int getIndex(Tri tri)
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
public Tri getAdjacent(int index)
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
public boolean isAdjacent(Tri tri)
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:
getIndex(Tri)
-
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
public Coordinate midpoint(int edgeIndex)
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
public Polygon toPolygon(GeometryFactory geomFact)
Creates a Polygon
representing this triangle.
- Parameters:
geomFact
- the geometry factory
- Returns:
- a polygon
Copyright © 2024. All rights reserved.