java.lang.Object
org.locationtech.jts.triangulate.tri.Tri

public class Tri extends Object
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
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a triangle with the given vertices.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    area(List<? extends Tri> triList)
    Computes the area of a set of Tris.
    static Tri
    Creates a triangle from an array with three vertex coordinates.
    static Tri
    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.
    getAdjacent(int index)
    Gets the triangle adjacent to an edge.
    double
    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
    Tests if a triangle is adjacent to some edge of this triangle.
    boolean
    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
    Removes this triangle from a triangulation.
    void
    remove(List<? extends Tri> triList)
    Removes this tri from the triangulation containing it.
    void
    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.
    Spits a triangle by a point located inside the triangle.
    static Geometry
    Creates a
    invalid reference
    GeometryCollection
    of Polygons representing the triangles in a list.
    Creates a Polygon representing this triangle.
     
    void
    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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Tri

      public Tri(Coordinate p0, Coordinate p1, Coordinate p2)
      Creates a triangle with the given vertices. The vertices should be oriented clockwise.
      Parameters:
      p0 - the first triangle vertex
      p1 - the second triangle vertex
      p2 - the third triangle vertex
  • Method Details

    • toGeometry

      public static Geometry toGeometry(Collection<Tri> tris, GeometryFactory geomFact)
      Creates a
      invalid reference
      GeometryCollection
      of Polygons representing the triangles in a list.
      Parameters:
      tris - a collection of Tris
      geomFact - the GeometryFactory to use
      Returns:
      the polygons for the triangles
    • area

      public static double area(List<? extends Tri> triList)
      Computes the area of a set of Tris.
      Parameters:
      triList - a set of Tris
      Returns:
      the total area of the triangles
    • validate

      public static void validate(List<Tri> triList)
      Validates a list of Tris.
      Parameters:
      triList - the tris to validate
    • create

      public static Tri create(Coordinate p0, Coordinate p1, Coordinate p2)
      Creates a triangle with the given vertices. The vertices should be oriented clockwise.
      Parameters:
      p0 - the first triangle vertex
      p1 - the second triangle vertex
      p2 - the third triangle vertex
      Returns:
      the created triangle
    • create

      public static Tri create(Coordinate[] pts)
      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

      public void setAdjacent(Tri tri0, Tri tri1, Tri tri2)
      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 0
      tri1 - the triangle adjacent to edge 1
      tri2 - the triangle adjacent to edge 2
    • setAdjacent

      public void setAdjacent(Coordinate pt, Tri 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.
      Parameters:
      pt - the edge start point
      tri - the adjacent triangle
    • setTri

      public void setTri(int edgeIndex, Tri tri)
      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 to
      tri - the adjacent triangle
    • split

      public Tri split(Coordinate p)
      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

      public int degree(int index, List<? extends Tri> triList)
      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 index
      triList - the triangulation
      Returns:
      the degree of the vertex
    • remove

      public void remove(List<? extends Tri> triList)
      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 to nullinvalid 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

      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:
    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object