Triangle

public struct Triangle<Vector> : GeometricType where Vector : VectorType
extension Triangle: BoundableType where Vector: VectorComparable

Represents a [triangle] as a trio of N-dimensional vectors which describe a 2-dimensional enclosed surface on an euclidean space.

  • Convenience for Vector.Scalar

    Declaration

    Swift

    public typealias Scalar = Vector.Scalar
  • a

    The first point of this triangle.

    Declaration

    Swift

    public var a: Vector
  • b

    The second point of this triangle.

    Declaration

    Swift

    public var b: Vector
  • c

    The third point of this triangle.

    Declaration

    Swift

    public var c: Vector
  • Undocumented

    Declaration

    Swift

    public init(a: Vector, b: Vector, c: Vector)

Available where Scalar: Equatable

  • Defines the normalized barycentric coordinates for a Triangle.

    See more

    Declaration

    Swift

    struct Coordinates : Equatable
  • Returns a line segment for the edge between the points a -> b.

    Declaration

    Swift

    var lineAB: LineSegment<Vector> { get }
  • Returns a line segment for the edge between the points a -> c.

    Declaration

    Swift

    var lineAC: LineSegment<Vector> { get }
  • Returns a line segment for the edge between the points b -> c.

    Declaration

    Swift

    var lineBC: LineSegment<Vector> { get }
  • Returns a line segment for the edge between the points b -> a.

    Declaration

    Swift

    var lineBA: LineSegment<Vector> { get }
  • Returns a line segment for the edge between the points c -> a.

    Declaration

    Swift

    var lineCA: LineSegment<Vector> { get }
  • Returns a line segment for the edge between the points c -> b.

    Declaration

    Swift

    var lineCB: LineSegment<Vector> { get }

Available where Vector: VectorMultiplicative

  • Projects the given barycentric coordinates back into world space.

    Declaration

    Swift

    @inlinable
    public func projectToWorld(_ proj: Coordinates) -> Vector

Available where Vector: VectorComparable

  • Declaration

    Swift

    public var bounds: AABB<Vector> { get }

Available where Vector: VectorDivisible

  • Returns the geometric center of this triangle.

    Equivalent to the arithmetic mean of the three points of this triangle:

    (a + b + c) / 3
    

    Declaration

    Swift

    var center: Vector { get }

Available where Vector: VectorFloatingPoint

  • Returns the positive area of this triangle.

    Performs the following operation:

    1÷2 (|AB|² |AC|² - (AB  AC)²)
    

    Where AB is the vector going from a to b, and AC from a to c:

    let AB = a - b
    let AC = a - c
    

    (the area of the triangle is half of the area of the parallelogram formed by the vectors AB / AC on the plane of those vertices).

    Triangles with internal angles of 0° or 180° have an area of zero.

    Declaration

    Swift

    @inlinable
    var area: Scalar { get }