Home Reference Source Test Repository
public class | source

Triangle2D

Class representing a 2D triangle.

Test:

Constructor Summary

Public Constructor
public

Constructs a Triangle2D object.

Member Summary

Public Members
public

a: *

public get

area: number: *

Getter for the (signed) area of the triangle.

public

b: *

public

c: *

Method Summary

Public Methods
public

Find the barycentric coordinates of a point relative to this triangle.

public

Find the cartesian coordinates of a point given its barycentric coordinates.

Public Constructors

public constructor(a: Point2D, b: Point2D, c: Point2D) source

Constructs a Triangle2D object.

Params:

NameTypeAttributeDescription
a Point2D

First vertex of the triangle.

b Point2D

Second vertex of the triangle.

c Point2D

Third vertex of the triangle.

Test:

Public Members

public a: * source

public get area: number: * source

Getter for the (signed) area of the triangle.

     1  | x1 y1 1 |

area = --- | x2 y2 1 | 2 | x3 y3 1 |

Source: http://mathworld.wolfram.com/TriangleArea.html

Return:

number

Signed area of the triangle.

Test:

public b: * source

public c: * source

Public Methods

public getBarycentricCoordinates(point: Point2D): Point2D source

Find the barycentric coordinates of a point relative to this triangle. Source: http://stackoverflow.com/a/14382692/1418962 More info: https://en.wikipedia.org/wiki/Barycentric_coordinate_system#Conversion_between_barycentric_and_Cartesian_coordinates

Params:

NameTypeAttributeDescription
point Point2D

The point to find the barycentric coordinates of.

Return:

Point2D

Point object containing the barycentric coordinates.

Test:

public getPointFromBarycentricCoordinates(point: Point2D): Point2D source

Find the cartesian coordinates of a point given its barycentric coordinates.

Params:

NameTypeAttributeDescription
point Point2D

The point to find the coordinates of.

Return:

Point2D

Point object containing the cartesian coordinates.

Test: