Triangle is a TTriangle<point-type> type. Where <point-type> is such suffix that vector type TVector<point-type> exists. For example, we have TVector3Single type that represents a point in 3D space, so you can use TTriangle3Single to represent triangle in 3D space. There are also 2D triangles like TTriangle2Single and TTriangle2Double.
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 IsValidTriangle, which is exactly used to check whether the triangle is degenerated.
Since every valid triangle unambiguously determines some plane in the 3D space, it also determines it's normal vector. In this unit, when dealing with normal vectors, I use two names:
TriangleNormal means that this is the normalized (i.e. scaled to length 1.0) normal vector.
TriangleDir means that this is not necessarily normalized normal vector.
function IsValidTriangle(const Tri: TTriangle3Single): boolean; overload;
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).
function IsValidTriangle(const Tri: TTriangle3Double): boolean; overload;
Normal vector of a triangle. Returns vector pointing our from CCW triangle side (for right-handed coordinate system), and orthogonal to triangle plane. The version "Dir" (TriangleDir) doesn't normalize the result (it may not have length equal 1).
For degenerated triangles (when IsValidTriangle would return false), we return zero vector.
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.
Normal vector of a triangle defined as three indexes intro vertex array. VerticesStride is the shift between vertex values in the array, VerticesStride = 0 behaves like VerticesStride = SizeOf(TVector3Single).
function TriangleArea(const Tri: TTriangle3Single): Single; overload;
Surface area of 3D triangle. This works for degenerated (equal to line segment or even single point) triangles too: returns 0 for them.
function TriangleArea(const Tri: TTriangle3Double): Double; overload;
function TriangleAreaSqr(const Tri: TTriangle3Single): Single; overload;
function TriangleAreaSqr(const Tri: TTriangle3Double): Double; overload;
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 TriangleDir, which means that it points outward from CCW side of the triangle (assuming right-handed coord system).
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.
Calculates normalized normal vector for polygon composed from indexed vertices. Polygon is defines as vertices Verts[Indices[0]], Verts[Indices[1]] ... Verts[Indices[IndicesCount-1]]. Returns normal pointing from CCW.
It's secured against invalid indexes on Indices list (that's the only reason why it takes VertsCount parameter, after all): they are ignored.
If the polygon is degenerated, that is it doesn't determine a plane in 3D space (this includes, but is not limited, to cases when there are less than 3 valid points, like when IndicesCount < 3) then it returns ResultForIncorrectPoly.
function IsPolygon2dCCW(Verts: PArray_Vector2Single; const VertsCount: Integer): Single; overload;
Are the polygon points ordered CCW (counter-clockwise). When viewed with typical camera settings, that is +Y goes up and +X goes right.
Polygon doesn't have to be convex. Polygon doesn't have to have all triangles valid, that is it's OK if some polygon triangles degenerate into points or line segments.
Returns something > 0 if polygon is CCW, or < 0 when it's not. Returns zero when polygon has area 0.
function IsPolygon2dCCW(const Verts: array of TVector2Single): Single; overload;
function Polygon2dArea(Verts: PArray_Vector2Single; const VertsCount: Integer): Single; overload;
Calculate polygon area.
Polygon doesn't have to be convex. Polygon doesn't have to have all triangles valid, that is it's OK if some polygon triangles degenerate into points or line segments.
function Polygon2dArea(const Verts: array of TVector2Single): Single; overload;
function TriangleToNiceStr(const t: TTriangle2Single): string; overload;
function TriangleToNiceStr(const t: TTriangle2Double): string; overload;
function TriangleToNiceStr(const t: TTriangle3Single): string; overload;
function TriangleToNiceStr(const t: TTriangle3Double): string; overload;
function TriangleToRawStr(const t: TTriangle3Single): string; overload;
function TriangleToRawStr(const t: TTriangle3Double): string; overload;