Package toxi.geom
Class Triangle2D
java.lang.Object
toxi.geom.Triangle2D
- All Implemented Interfaces:
Shape2D
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadjustTriangleSizeBy
(float offset) adjustTriangleSizeBy
(float offAB, float offBC, float offCA) boolean
Checks if the given point is inside the triangle created by the points a, b and c.copy()
static Triangle2D
float
getArea()
Computes the area of the shape.Computes the bounding circle of the shape.Returns the shape's axis-aligned bounding rect.float
Computes the shape's circumference.Finds and returns the closest point on any of the triangle edges to the point given.getEdges()
Returns a list of the shape's perimeter edges.Creates a random point within the triangle using barycentric coordinates.Vec2D[]
Vec2D[]
getVertexArray
(Vec2D[] array, int offset) boolean
Checks if this triangle intersects the given one.boolean
static boolean
isClockwise
(Vec2D a, Vec2D b, Vec2D c) void
Produces the barycentric coordinates of the given point within this triangle.Creates aPolygon2D
instance of the triangle.toString()
-
Field Details
-
a
-
b
-
c
-
centroid
-
-
Constructor Details
-
Triangle2D
public Triangle2D() -
Triangle2D
-
-
Method Details
-
createEquilateralFrom
-
isClockwise
-
adjustTriangleSizeBy
-
adjustTriangleSizeBy
-
computeCentroid
-
containsPoint
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 interfaceShape2D
- Returns:
- true, if point is in triangle.
-
copy
-
flipVertexOrder
-
fromBarycentric
-
getArea
public float getArea()Description copied from interface:Shape2D
Computes the area of the shape. -
getBoundingCircle
Description copied from interface:Shape2D
Computes the bounding circle of the shape.- Specified by:
getBoundingCircle
in interfaceShape2D
- Returns:
- circle
-
getBounds
Description copied from interface:Shape2D
Returns the shape's axis-aligned bounding rect. -
getCircumCircle
-
getCircumference
public float getCircumference()Description copied from interface:Shape2D
Computes the shape's circumference.- Specified by:
getCircumference
in interfaceShape2D
- Returns:
- circumference
-
getClosestPointTo
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
Description copied from interface:Shape2D
Returns a list of the shape's perimeter edges. -
getRandomPoint
Creates a random point within the triangle using barycentric coordinates.- Specified by:
getRandomPoint
in interfaceShape2D
- Returns:
- Vec2D
-
getVertexArray
-
getVertexArray
-
intersectsTriangle
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
-
toBarycentric
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 itsfromBarycentric(ReadonlyVec3D)
method.- Parameters:
p
- point in world space- Returns:
- barycentric coords as
Vec3D
-
toPolygon2D
Creates aPolygon2D
instance of the triangle. The vertices of this polygon are disconnected from the ones defining this triangle.- Specified by:
toPolygon2D
in interfaceShape2D
- Returns:
- triangle as polygon
-
toString
-