Record TTriangle3

Unit

Declaration

type TTriangle3 = record

Description

Triangle in 3D space.

Triangle's three points must not be collinear, i.e. routines in this unit generally don't accept "degenerated" triangles that are not really triangles. So 3D triangle must unambiguously define some plane in the 3D space. The only function in this unit that is able to handle "degenerated" triangles is TTriangle3.IsValid, which is exactly used to check whether the triangle is degenerated.

Source: src/transform/castletriangles.pas (line 46).

Overview

Nested Types

Public TIndex = 0..2;

Fields

Public Data: packed [TIndex] of TVector3;

Methods

Public function ToString: string;
Public function IsValid: boolean;
Public function Direction: TVector3;
Public function Normal: TVector3;
Public function Plane: TVector4;
Public function NormalizedPlane: TVector4;
Public function Transform(const M: TMatrix4): TTriangle3;
Public function Area: Single;
Public function AreaSqr: Single;
Public function RandomPoint: TVector3;
Public function Barycentric(const Point: TVector3): TVector3;

Properties

Public property Items [const Index: TIndex]: TVector3 read GetItems write SetItems;

Description

Nested Types

Public TIndex = 0..2;

This item has no description.

Source: src/transform/castletriangles.pas (line 46).

Fields

Public Data: packed [TIndex] of TVector3;

This item has no description.

Source: src/transform/castletriangles.pas (line 54).

Methods

Public function ToString: string;

Multiline triangle description.

Source: src/transform/castletriangles.pas (line 63).

Public function IsValid: boolean;

Check does the triangle define a correct plane in 3D space. That is, check does the triangle not degenerate to a point or line segment (which can happen when some points are at the same position, or are colinear).

Source: src/transform/castletriangles.pas (line 68).

Public function Direction: TVector3;

Like a normal vector of a triangle (see Normal), but not necessarily normalized.

Source: src/transform/castletriangles.pas (line 71).

Public function Normal: TVector3;

Normal vector of a triangle. Returns vector pointing our from CCW triangle side (for right-handed coordinate system), and orthogonal to triangle plane. For degenerated triangles (when IsValid would return False), we return zero vector.

Source: src/transform/castletriangles.pas (line 77).

Public function Plane: TVector4;

Plane of the triangle. Note that this has many possible solutions (plane representation as equation Ax + By + Cz + D = 0 is not unambiguous), this just returns some solution deterministically.

It's guaranteed that the direction of this plane (i.e. first 3 items of returned vector) will be in the same direction as calcualted by Direction, which means that it points outward from CCW side of the triangle (assuming right-handed coord system).

For NormalizedPlane, this direction is also normalized (makes a vector with length 1). This way NormalizedPlane calculates also Normal.

For three points that do not define a plane, a plane with first three components = 0 is returned. In fact, the 4th component will be zero too in this case (for now), but don't depend on it.

Source: src/transform/castletriangles.pas (line 96).

Public function NormalizedPlane: TVector4;

This item has no description.

Source: src/transform/castletriangles.pas (line 97).

Public function Transform(const M: TMatrix4): TTriangle3;

Transform triangle by 4x4 matrix. This simply transforms each triangle point.

Exceptions raised
ETransformedResultInvalid
Raised when matrix will transform some point to a direction (vector with 4th component equal zero). In this case we just cannot interpret the result as a 3D point.

Source: src/transform/castletriangles.pas (line 104).

Public function Area: Single;

Surface area of 3D triangle. This works for degenerated (equal to line segment or even single point) triangles too: returns 0 for them.

Source: src/transform/castletriangles.pas (line 111).

Public function AreaSqr: Single;

This item has no description.

Source: src/transform/castletriangles.pas (line 112).

Public function RandomPoint: TVector3;

Random triangle point, chosen with a constant density for triangle area.

Source: src/transform/castletriangles.pas (line 116).

Public function Barycentric(const Point: TVector3): TVector3;

For a given Point lying on a given Triangle, calculate it's barycentric coordinates.

The resulting Barycentric coordinates can be used for linearly interpolating values along the triangle, as they satisfy the equation:

Result.X * Triangle.Data[0] +
Result.Y * Triangle.Data[1] +
Result.Z * Triangle.Data[2] = Point

See also [http://en.wikipedia.org/wiki/Barycentric_coordinate_system_%28mathematics%29]

Source: src/transform/castletriangles.pas (line 131).

Properties

Public property Items [const Index: TIndex]: TVector3 read GetItems write SetItems;

Access the points of the triangle. This is the same as accessing Data field, it is also the default record property so you can just write MyTriangle[0] instead of MyTriangle.Items[0] or MyTriangle.Data[0].

Source: src/transform/castletriangles.pas (line 60).


Generated by PasDoc 0.17.0.snapshot.