Reference

std/geometry/triangle2

std/geometry/src/triangle2.trb

Triangle2, the triangle in the plane: the smallest shape that has an inside, and the one every mesh and every tessellation is made of.

type Triangle2

type Triangle2<Scalar: Numeric = Float>

Three corners in the plane.

The winding is not fixed: Triangle2.signedArea is positive where the corners run from the first axis towards the second and negative where they run the other way, and every other member works for both.

Examples

const face = Triangle2 Vector2(0, 0), Vector2(4, 0), Vector2(0, 4)
print "{face.contains(Vector2(1, 1))} {face.signedArea()}"

Related

  • Polygon - more than three corners.
  • Triangle3 - the same in space, which additionally has a normal.

field first

first: Vector2<Scalar>

The first corner.

field second

second: Vector2<Scalar>

The second corner.

field third

third: Vector2<Scalar>

The third corner.

fn signedArea

fn signedArea(): Scalar

Twice the area, with a sign that says which way the corners run. Zero where the three lie on one line.

fn bounds

fn bounds(): Rectangle<Scalar>

The smallest rectangle that holds the triangle.

fn edges

fn edges(): List<Segment2<Scalar>>

The three edges, in the order the corners are written.

fn contains

fn contains(point: Vector2<Scalar>): Bool

Whether the point is inside the triangle, an edge included.

The test is the sign of the three edge cross products: a point is inside where it is on the same side of all three, whichever way the corners run.

fn translated

fn translated(by: Vector2<Scalar>): Triangle2<Scalar>

The same triangle moved.

extend Triangle2<Scalar>

extend<Scalar: Signed> Triangle2<Scalar>

What a sign buys: the area without its sign.

fn doubledArea

fn doubledArea(): Scalar

Twice the area, without a sign: the whole number a whole-number triangle has instead of a halved one.

extend Triangle2<Scalar>

extend<Scalar: Real> Triangle2<Scalar>

What a halving and a root buy: the area, the midpoint and the nearest point.

fn area

fn area(): Scalar

How much of the plane the triangle covers.

fn center

fn center(): Vector2<Scalar>

The midpoint of the three corners, which is where the triangle balances.

fn closestPoint

fn closestPoint(to: Vector2<Scalar>): Vector2<Scalar>

The point of the triangle that is nearest to the one given.

fn distanceTo

fn distanceTo(point: Vector2<Scalar>): Scalar

The distance from the point to the nearest point of the triangle. Zero where it is inside.