Triangle2

public extension Triangle2 where Vector: Vector2Multiplicative
public extension Triangle2 where Vector: Vector2Multiplicative & VectorDivisible
public extension Triangle2 where Vector: Vector2Multiplicative & VectorDivisible & VectorSigned
extension Triangle2: VolumetricType where Vector: Vector2FloatingPoint
extension Triangle2: Convex2Type where Vector: Vector2FloatingPoint

Available where Vector: Vector2Multiplicative

  • Returns a unit triangle where a, b, and c take the following values:

    a = Vector(x: 0, y: 0)
    b = Vector(x: 1, y: 0)
    c = Vector(x: 0, y: 1)
    

    Declaration

    Swift

    static var unitTriangle: `Self` { get }
  • Returns the signed doubled area of this triangle.

    The triangle has a negative signed area if the parallelogram formed by the edge vectors CA and BA are counter-clockwise (in Cartesian space where Y grows positively up).

    For a 2D triangle, the doubled area is computed as the cross-product of CA and BA:

    (c.x  a.x) * (b.y  a.y) - (c.y  a.y) * (b.x  a.x)
    

    Seealso

    signedArea

    Declaration

    Swift

    var signedDoubleArea: Scalar { get }

Available where Vector: Vector2Multiplicative & VectorDivisible

  • Returns the signed area of this triangle.

    The triangle has a negative signed area if the parallelogram formed by the edge vectors CA and BA are counter-clockwise (in Cartesian space where Y grows positively up).

    For a 2D triangle, the area is computed as half of the cross-product of CA and BA:

    ((c.x  a.x) * (b.y  a.y) - (c.y  a.y) * (b.x  a.x)) / 2
    

    Declaration

    Swift

    var signedArea: Scalar { get }

Available where Vector: Vector2Multiplicative & VectorDivisible & VectorSigned

  • Returns the signed value of this triangle’s winding.

    In Cartesian space where Y grows positively up, the winding is -1 for clockwise windings and -1 for counter-clockwise windings.

    If the area of this triangle is == .zerp, 0 is returned, instead.

    Declaration

    Swift

    var winding: Scalar { get }

Available where Vector: Vector2FloatingPoint

  • Returns whether the given point vector is contained within this triangle.

    Points at the perimeter of the triangle, as well as the points forming the corners of the triangle, are considered as contained within the triangle (inclusive).

    Triangles where signedDoubleArea == .zero cannot contain points and return false for any containment check.

    This function is well-defined for signedDoubleArea of both negative and positive values.

    Declaration

    Swift

    @inlinable
    public func contains(_ vector: Vector) -> Bool
  • Performs a projection of a given set of coordinates onto this triangle as a set of barycentric coordinates.

    Declaration

    Swift

    public func toBarycentric(x: Scalar, y: Scalar) -> Coordinates
  • Performs a projection of a given vector onto this triangle as a set of barycentric coordinates.

    The resulting coordinates might have scalar values < .zero, indicating points that projected outside the area of the triangle.

    Declaration

    Swift

    @inlinable
    public func toBarycentric(_ vector: Vector) -> Coordinates
  • Performs an intersection test against the given line, returning up to two points representing the entrance and exit intersections against this 2D triangle’s outer perimeter.

    Declaration

    Swift

    public func intersection<Line>(with line: Line) -> ConvexLineIntersection<Vector> where Vector == Line.Vector, Line : Line2FloatingPoint