public abstract class Triangle

Known direct subclasses
ImmutableTriangle

An immutable triangle, defined by its three corners p0, p1 and p2 in order.

MutableTriangle

Represents a mutable triangle, defined by its three corners p0, p1 and p2 in order.


A triangle defined by its three corners p0, p1 and p2. The order of these points matter - a triangle with p0, p1, p2 is not the same as the permuted p1, p0, p2, or even the rotated p2, p0, p1.

A Triangle may be degenerate, meaning it is constructed with its 3 points colinear. One way that a Triangle may be degenerate is if two or three of its points are at the same location (coincident).

This is a read-only interface that has mutable and immutable implementations. See MutableTriangle and ImmutableTriangle.

Summary

Public methods

final @NonNull ImmutableBox

Returns the minimum bounding box containing the Triangle.

final @NonNull MutableBox

Populates outBox with the minimum bounding box containing the Triangle and returns outBox.

final @NonNull ImmutableSegment
computeEdge(@IntRange(from = 0, to = 2) int index)

Returns the segment of the Triangle between the point at index and the point at index + 1 modulo 3.

final @NonNull MutableSegment
computeEdge(
    @IntRange(from = 0, to = 2) int index,
    @NonNull MutableSegment outSegment
)

Fills outSegment with the segment of the Triangle between the point at index and the point at index + 1 modulo 3.

final float

Return the signed area of the Triangle.

final boolean

Returns true if the given point is contained within the Triangle.

abstract @NonNull Vec

One of the three points that define the Triangle.

abstract @NonNull Vec

One of the three points that define the Triangle.

abstract @NonNull Vec

One of the three points that define the Triangle.

final boolean
isAlmostEqual(
    @NonNull Triangle other,
    @FloatRange(from = 0.0) float tolerance
)

Public methods

computeBoundingBox

Added in 1.0.0-alpha01
public final @NonNull ImmutableBox computeBoundingBox()

Returns the minimum bounding box containing the Triangle.

computeBoundingBox

Added in 1.0.0-alpha01
public final @NonNull MutableBox computeBoundingBox(@NonNull MutableBox outBox)

Populates outBox with the minimum bounding box containing the Triangle and returns outBox.

computeEdge

Added in 1.0.0-alpha01
public final @NonNull ImmutableSegment computeEdge(@IntRange(from = 0, to = 2) int index)

Returns the segment of the Triangle between the point at index and the point at index + 1 modulo 3.

computeEdge

Added in 1.0.0-alpha01
public final @NonNull MutableSegment computeEdge(
    @IntRange(from = 0, to = 2) int index,
    @NonNull MutableSegment outSegment
)

Fills outSegment with the segment of the Triangle between the point at index and the point at index + 1 modulo 3. Returns outSegment.

computeSignedArea

Added in 1.0.0-alpha01
public final float computeSignedArea()

Return the signed area of the Triangle. If the Triangle is degenerate, meaning its 3 points are all colinear, then the result will be zero. If its points wind in a positive direction (as defined by Angle), then the result will be positive. Otherwise, it will be negative.

contains

Added in 1.0.0-alpha01
public final boolean contains(@NonNull Vec point)

Returns true if the given point is contained within the Triangle. Points that lie exactly on the Triangle's boundary are considered to be contained.

getP0

Added in 1.0.0-alpha01
public abstract @NonNull Vec getP0()

One of the three points that define the Triangle.

getP1

Added in 1.0.0-alpha01
public abstract @NonNull Vec getP1()

One of the three points that define the Triangle.

getP2

Added in 1.0.0-alpha01
public abstract @NonNull Vec getP2()

One of the three points that define the Triangle.

isAlmostEqual

Added in 1.0.0-alpha01
public final boolean isAlmostEqual(
    @NonNull Triangle other,
    @FloatRange(from = 0.0) float tolerance
)