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
-
Returns a unit triangle where
a
,b
, andc
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
andBA
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
andBA
:(c.x − a.x) * (b.y − a.y) - (c.y − a.y) * (b.x − a.x)
Seealso
signedArea
Declaration
Swift
var signedDoubleArea: Scalar { get }
-
Returns the signed area of this triangle.
The triangle has a negative signed area if the parallelogram formed by the edge vectors
CA
andBA
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
andBA
:((c.x − a.x) * (b.y − a.y) - (c.y − a.y) * (b.x − a.x)) / 2
Seealso
signedDoubleArea
Declaration
Swift
var signedArea: Scalar { get }
-
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
== .zero
,0
is returned, instead.Declaration
Swift
var winding: Scalar { get }
-
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 returnfalse
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 Line : Line2FloatingPoint, Vector == Line.Vector