std/geometry/triangle3
std/geometry/src/triangle3.trb
Triangle3, the triangle in space: one face of a mesh, and what a ray is tested against once the broad phase has
narrowed the search.
type Triangle3
type Triangle3<Scalar: Numeric = Float>
Three corners in space.
The normal follows the right-handed order of the corners: (second - first) x (third - first). A mesh that wants the
other side writes its corners the other way round.
Examples
const face = Triangle3 Vector3(0.0, 0.0, 0.0), Vector3(1.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0)
print "{face.normal()} {face.area()}"
Related
Triangle2- the same in the plane.Plane- whatTriangle3.planeanswers, and what a clipping test needs.
field first
first: Vector3<Scalar>
The first corner.
field second
second: Vector3<Scalar>
The second corner.
field third
third: Vector3<Scalar>
The third corner.
fn firstEdge
fn firstEdge(): Vector3<Scalar>
The step from the first corner to the second.
fn secondEdge
fn secondEdge(): Vector3<Scalar>
The step from the first corner to the third.
fn doubledAreaVector
fn doubledAreaVector(): Vector3<Scalar>
The cross product of the two edges: a vector perpendicular to the triangle whose length is twice the area. Zero where the three corners lie on one line.
fn bounds
fn bounds(): Box<Scalar>
The smallest box that holds the triangle.
fn translated
fn translated(by: Vector3<Scalar>): Triangle3<Scalar>
The same triangle moved.
extend Triangle3<Scalar>
extend<Scalar: Real> Triangle3<Scalar>
What a root and a halving buy: the normal, the area, the plane and the nearest point.
fn normal
fn normal(): Vector3<Scalar>
The direction perpendicular to the triangle, with length one, in the right-handed order of the corners.
fn area
fn area(): Scalar
How much surface the triangle covers.
fn plane
fn plane(): Plane<Scalar>
The plane the triangle lies in.
fn center
fn center(): Vector3<Scalar>
The midpoint of the three corners, which is where the triangle balances.
fn weightsOf
fn weightsOf(point: Vector3<Scalar>): (first: Scalar, second: Scalar, third: Scalar)
How the point is written as a mix of the three corners: the three weights add up to one, and all three are between zero and one exactly where the point is inside the triangle.
Every hit test against a triangle ends here, because this is what says whether a crossing of the plane is a crossing of the face.
fn contains
fn contains(point: Vector3<Scalar>): Bool
Whether the point lies in the triangle, which for a point off the plane means its shadow on the plane does.