Package toxi.geom

Class Triangle2D

java.lang.Object
toxi.geom.Triangle2D
All Implemented Interfaces:
Shape2D

public class Triangle2D extends Object implements Shape2D
  • Field Details

  • Constructor Details

  • Method Details

    • createEquilateralFrom

      public static Triangle2D createEquilateralFrom(ReadonlyVec2D a, ReadonlyVec2D b)
    • isClockwise

      public static boolean isClockwise(Vec2D a, Vec2D b, Vec2D c)
    • adjustTriangleSizeBy

      public Triangle2D adjustTriangleSizeBy(float offset)
    • adjustTriangleSizeBy

      public Triangle2D adjustTriangleSizeBy(float offAB, float offBC, float offCA)
    • computeCentroid

      public Vec2D computeCentroid()
    • containsPoint

      public boolean containsPoint(ReadonlyVec2D p)
      Checks if the given point is inside the triangle created by the points a, b and c. The triangle vertices are inclusive themselves.
      Specified by:
      containsPoint in interface Shape2D
      Returns:
      true, if point is in triangle.
    • copy

      public Triangle2D copy()
    • flipVertexOrder

      public Triangle2D flipVertexOrder()
    • fromBarycentric

      public Vec2D fromBarycentric(ReadonlyVec3D p)
    • getArea

      public float getArea()
      Description copied from interface: Shape2D
      Computes the area of the shape.
      Specified by:
      getArea in interface Shape2D
      Returns:
      area
    • getBoundingCircle

      public Circle getBoundingCircle()
      Description copied from interface: Shape2D
      Computes the bounding circle of the shape.
      Specified by:
      getBoundingCircle in interface Shape2D
      Returns:
      circle
    • getBounds

      public Rect getBounds()
      Description copied from interface: Shape2D
      Returns the shape's axis-aligned bounding rect.
      Specified by:
      getBounds in interface Shape2D
      Returns:
      bounding rect
    • getCircumCircle

      public Circle getCircumCircle()
    • getCircumference

      public float getCircumference()
      Description copied from interface: Shape2D
      Computes the shape's circumference.
      Specified by:
      getCircumference in interface Shape2D
      Returns:
      circumference
    • getClosestPointTo

      public Vec2D getClosestPointTo(ReadonlyVec2D p)
      Finds and returns the closest point on any of the triangle edges to the point given.
      Parameters:
      p - point to check
      Returns:
      closest point
    • getEdges

      public List<Line2D> getEdges()
      Description copied from interface: Shape2D
      Returns a list of the shape's perimeter edges.
      Specified by:
      getEdges in interface Shape2D
      Returns:
      list of Line2D elements
    • getRandomPoint

      public Vec2D getRandomPoint()
      Creates a random point within the triangle using barycentric coordinates.
      Specified by:
      getRandomPoint in interface Shape2D
      Returns:
      Vec2D
    • getVertexArray

      public Vec2D[] getVertexArray()
    • getVertexArray

      public Vec2D[] getVertexArray(Vec2D[] array, int offset)
    • intersectsTriangle

      public boolean intersectsTriangle(Triangle2D tri)
      Checks if this triangle intersects the given one. The check handles both partial and total containment as well as intersections of all edges.
      Parameters:
      tri -
      Returns:
      true, if intersecting
    • isClockwise

      public boolean isClockwise()
    • set

      public void set(Vec2D a2, Vec2D b2, Vec2D c2)
    • toBarycentric

      public Vec3D toBarycentric(ReadonlyVec2D p)
      Produces the barycentric coordinates of the given point within this triangle. These coordinates can then be used to re-project the point into a different triangle using its fromBarycentric(ReadonlyVec3D) method.
      Parameters:
      p - point in world space
      Returns:
      barycentric coords as Vec3D
    • toPolygon2D

      public Polygon2D toPolygon2D()
      Creates a Polygon2D instance of the triangle. The vertices of this polygon are disconnected from the ones defining this triangle.
      Specified by:
      toPolygon2D in interface Shape2D
      Returns:
      triangle as polygon
    • toString

      public String toString()
      Overrides:
      toString in class Object