Skip to main content

Triangle

A geometric triangle as defined by three Vector3s representing its three corners.

Constructor

Triangle

function Triangle( a: Vector3, b: Vector3, c: Vector3 ): void;  

a - the first corner of the triangle. Default is a Vector3 at (0, 0, 0).
b - the second corner of the triangle. Default is a Vector3 at (0, 0, 0).
c - the final corner of the triangle. Default is a Vector3 at (0, 0, 0).

Creates a new Triangle.

Properties

a

a: Vector3;  

The first corner of the triangle. Default is a Vector3 at (0, 0, 0).

b

b: Vector3;  

The second corner of the triangle. Default is a Vector3 at (0, 0, 0).

c

c: Vector3;  

The final corner of the triangle. Default is a Vector3 at (0, 0, 0).

Methods

clone

function clone( ): Triangle;  

Returns a new triangle with the same .a, .b and .c properties as this one.

closestPointToPoint

function closestPointToPoint( point: Vector3, target: Vector3 ): Vector3;  

point - Vector3
target — the result will be copied into this Vector3.

Returns the closest point on the triangle to point.

containsPoint

function containsPoint( point: Vector3 ): Boolean;  

point - Vector3 to check.

Returns true if the passed point, when projected onto the plane of the triangle, lies within the triangle.

copy

function copy( triangle: Triangle ): this;  

Copies the values of the passed triangles's .a, .b and .c properties to this triangle.

equals

function equals( triangle: Triangle ): Boolean;  

Returns true if the two triangles have identical .a, .b and .c properties.

getArea

function getArea( ): Float;  

Return the area of the triangle.

getBarycoord

function getBarycoord( point: Vector3, target: Vector3 ): Vector3;  

point - Vector3
target — the result will be copied into this Vector3.

Return a barycentric coordinate from the given vector.

Picture of barycentric coordinates

getMidpoint

function getMidpoint( target: Vector3 ): Vector3;  

target — the result will be copied into this Vector3.

Calculate the midpoint of the triangle.

getNormal

function getNormal( target: Vector3 ): Vector3;  

target — the result will be copied into this Vector3.

Calculate the normal vector of the triangle.

getPlane

function getPlane( target: Plane ): Plane;  

target — the result will be copied into this Plane.

Calculate a plane based on the triangle. .

getInterpolation

function getInterpolation( point: Vector3, p1: Vector3, p2: Vector3, p3:
Vector3, v1: Vector, v2: Vector, v3: Vector, target: Vector ): Vector;

point - Position of interpolated point.
p1 - Position of first vertex.
p2 - Position of second vertex.
p3 - Position of third vertex.
v1 - Value of first vertex.
v2 - Value of second vertex.
v3 - Value of third vertex.
target — Result will be copied into this Vector.

Returns the value barycentrically interpolated for the given point on the triangle.

intersectsBox

function intersectsBox( box: Box3 ): Boolean;  

box - Box to check for intersection against.

Determines whether or not this triangle intersects box.

isFrontFacing

function isFrontFacing( direction: Vector3 ): Boolean;  

direction - The direction to test.

Whether the triangle is oriented towards the given direction or not.

set

function set( a: Vector3, b: Vector3, c: Vector3 ): this;  

Sets the triangle's .a, .b and .c properties to the passed .ector3.
Please note that this method only copies the values from the given objects.

setFromAttributeAndIndices

function setFromAttributeAndIndices( attribute: BufferAttribute, i0: Integer,
i1: Integer, i2: Integer ): this;

attribute - BufferAttribute of vertex data
i0 - Integer index
i1 - Integer index
i2 - Integer index

Sets the triangle's vertices from the buffer attribute vertex data.

setFromPointsAndIndices

function setFromPointsAndIndices( points: Array, i0: Integer, i1: Integer, i2:
Integer ): this;

points - Array of Vector3s
i0 - Integer index
i1 - Integer index
i2 - Integer index

Sets the triangle's vectors to the vectors in the array.

Source

src/math/Triangle.js