java.lang.Object
imagingbook.common.geometry.delaunay.guibas.Triangle2D
All Implemented Interfaces:
Triangle, ShapeProducer

public class Triangle2D extends Object implements Triangle
Represents a 2D triangle, specified by three corner points. Instances of this class are immutable.
  • Field Details

  • Constructor Details

    • Triangle2D

      public Triangle2D(Pnt2d a, Pnt2d b, Pnt2d c)
      Constructor of the 2D triangle class used to create a new triangle instance from three 2D vectors describing the triangle's vertices.
      Parameters:
      a - the first vertex of the triangle
      b - the second vertex of the triangle
      c - the third vertex of the triangle
    • Triangle2D

      public Triangle2D(Pnt2d[] points)
  • Method Details

    • containsPoint

      public boolean containsPoint(Pnt2d point)
      Tests if a 2D point lies inside this 2D triangle. See See Christer Ericson, Real-Time Collision Detection, CRC Press, 2004 (Ch. 5, p. 206).
      Parameters:
      point - the point to be checked
      Returns:
      true iff the point lies inside this 2D triangle
    • isPointInCircumCircle

      protected boolean isPointInCircumCircle(Pnt2d point)
      Tests if a given point lies in the circumcircle of this triangle. Let the triangle ABC appear in counterclockwise (CCW) order. Then when det > 0, the point lies inside the circumcircle through the three points a, b and c. If instead det < 0, the point lies outside the circumcircle. When det = 0, the four points are cocircular. If the triangle is oriented clockwise (CW) the result is reversed. See Christer Ericson, Real-Time Collision Detection, CRC Press, 2004 (Ch. 3, p. 34).
      Parameters:
      point - the point to be checked
      Returns:
      true iff the point lies inside the circumcircle through the three points a, b, and c of the triangle
    • isOrientedCCW

      protected boolean isOrientedCCW()
      Test if this triangle is oriented counterclockwise (CCW). This property is pre-calculated.
      Returns:
      true iff the triangle ABC is oriented counterclockwise (CCW)
    • containsEdge

      public boolean containsEdge(Edge2D edge)
      Returns true if this triangle contains the given edge.
      Parameters:
      edge - the edge to be tested
      Returns:
      true iff this triangle contains the specified edge
    • getOppositeVertex

      Returns the vertex of this triangle opposite to the specified edge.
      Parameters:
      edge - the edge (which must be contained in this triangle)
      Returns:
      the triangle vertex opposite to the specified edge
    • hasVertex

      public boolean hasVertex(Pnt2d vertex)
      Checks if the given vertex is amongst the triangle's vertices.
      Parameters:
      vertex - the vertex to be checked
      Returns:
      true if the vertex is one of the corners of this triangle
    • findMinEdgeDistance

      Calculates the minimum distance from the specified point to this triangle. The result is returned as an Edge2D.Distance instance, representing the point's distance to the closest edge of this triangle.
      Parameters:
      point - the point to be checked
      Returns:
      the edge of this triangle that is closest to the specified point
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPoints

      public Pnt2d[] getPoints()
      Description copied from interface: Triangle
      Returns an array of points used by the triangulation in the order of their insertion.
      Specified by:
      getPoints in interface Triangle
      Returns:
      an array of points