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.

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.

Fields

Public Data: packed [TIndex] of TVector3;

This item has no description.

Methods

Public function ToString: string;

Multiline triangle description.

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).

Public function Direction: TVector3;

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

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.

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.

Public function NormalizedPlane: TVector4;

This item has no description.

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.
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.

Public function AreaSqr: Single;

This item has no description.

Public function RandomPoint: TVector3;

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

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]

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].


Generated by PasDoc 0.16.0-snapshot.