Table of Contents

Struct FixedTriangle

Namespace
FixedMathSharp.Geometry
Assembly
FixedMathSharp.dll

Represents an ordered triangle in three-dimensional fixed-point space.

[MemoryPackable(GenerateType.Object)]
public struct FixedTriangle : IEquatable<FixedTriangle>, IMemoryPackable<FixedTriangle>, IMemoryPackFormatterRegister
Implements
IMemoryPackable<FixedTriangle>
IMemoryPackFormatterRegister
Inherited Members

Remarks

Triangle queries preserve complete raw-coordinate differences and exact wide predicates until their final public Fixed64 conversion.

Constructors

FixedTriangle(Vector3d, Vector3d, Vector3d)

Initializes a triangle from ordered vertices.

[JsonConstructor]
public FixedTriangle(Vector3d a, Vector3d b, Vector3d c)

Parameters

a Vector3d
b Vector3d
c Vector3d

Fields

A

The first vertex.

[JsonInclude]
[MemoryPackOrder(0)]
public Vector3d A

Field Value

Vector3d

B

The second vertex.

[JsonInclude]
[MemoryPackOrder(1)]
public Vector3d B

Field Value

Vector3d

C

The third vertex.

[JsonInclude]
[MemoryPackOrder(2)]
public Vector3d C

Field Value

Vector3d

EdgeCount

The number of edges in a triangle.

public const int EdgeCount = 3

Field Value

int

VertexCount

The number of vertices in a triangle.

public const int VertexCount = 3

Field Value

int

Properties

Area

The non-negative surface area of the triangle.

[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 Area { get; }

Property Value

Fixed64

Remarks

The exact cross-product magnitude is halved and rounded once, half to even. Results beyond the positive Q32.32 range saturate to MaxValue.

Bounds

The normalized axis-aligned box that contains all vertices.

[JsonIgnore]
[MemoryPackIgnore]
public FixedBoundBox Bounds { get; }

Property Value

FixedBoundBox

Centroid

The arithmetic center of the three vertices, rounded half to even per component.

[JsonIgnore]
[MemoryPackIgnore]
public Vector3d Centroid { get; }

Property Value

Vector3d

IsDegenerate

Returns true when the exact squared normal magnitude is at or below the inclusive Epsilon threshold.

[JsonIgnore]
[MemoryPackIgnore]
public bool IsDegenerate { get; }

Property Value

bool

Normal

The normalized triangle normal derived from the exact cross product.

[JsonIgnore]
[MemoryPackIgnore]
public Vector3d Normal { get; }

Property Value

Vector3d

Remarks

Components are rounded half to even from the exact squared magnitude. Triangles at or below the inclusive degeneracy threshold return Zero.

UnnormalizedNormal

The unnormalized triangle normal from cross(B - A, C - A).

[JsonIgnore]
[MemoryPackIgnore]
public Vector3d UnnormalizedNormal { get; }

Property Value

Vector3d

Remarks

Each exact cross component is rounded once, half to even, and saturates independently at the public Q32.32 boundary.

Methods

ClosestPoint(Vector3d)

Finds the closest point on or inside this triangle to the supplied point.

public Vector3d ClosestPoint(Vector3d point)

Parameters

point Vector3d

Returns

Vector3d

Remarks

Voronoi-region predicates and degenerate edge distances use exact wide intermediates. Degenerate candidates are visited in AB, BC, CA order, and an exact distance tie retains the first candidate.

Contains(Vector3d)

Determines whether the point is within the inclusive squared-distance epsilon of this triangle.

public bool Contains(Vector3d point)

Parameters

point Vector3d

Returns

bool

ContainsProjection(Vector3d)

Determines whether the supplied point projects within or onto this triangle without requiring the point to lie on its plane.

public bool ContainsProjection(Vector3d point)

Parameters

point Vector3d

Returns

bool

Remarks

The projected barycentric signs are classified from exact wide numerators. Degenerate triangles have no projected face and return false.

Deconstruct(out Vector3d, out Vector3d, out Vector3d)

Deconstructs the triangle into ordered vertices.

public void Deconstruct(out Vector3d a, out Vector3d b, out Vector3d c)

Parameters

a Vector3d
b Vector3d
c Vector3d

DistanceSquared(Vector3d)

Computes the squared distance from the supplied point to this triangle, rounded once and positively saturated at the public boundary.

public Fixed64 DistanceSquared(Vector3d point)

Parameters

point Vector3d

Returns

Fixed64

DoesCenteredCapsuleOverlap(Vector3d, Vector3d, Fixed64, Fixed64)

Returns whether this triangle inclusively overlaps a conceptual centered capsule without materializing either contact witness.

public readonly bool DoesCenteredCapsuleOverlap(Vector3d center, Vector3d axisDirection, Fixed64 axisLength, Fixed64 radius)

Parameters

center Vector3d
axisDirection Vector3d
axisLength Fixed64
radius Fixed64

Returns

bool

Equals(FixedTriangle)

public bool Equals(FixedTriangle other)

Parameters

other FixedTriangle

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetClosestPointAnchor(Vector3d, FixedQuaternion, in FixedPointAnchor)

Gets the closest point on this triangle to a point carried by another rigid frame without materializing either absolute world point.

public FixedPointAnchor GetClosestPointAnchor(Vector3d triangleOrigin, FixedQuaternion triangleRotation, in FixedPointAnchor point)

Parameters

triangleOrigin Vector3d
triangleRotation FixedQuaternion
point FixedPointAnchor

Returns

FixedPointAnchor

Remarks

The returned anchor remains in the triangle's rigid frame. Voronoi predicates retain the complete relative-frame displacement until the final local barycentric conversion.

GetEdge(int)

Gets an edge by stable index: 0 = AB, 1 = BC, 2 = CA.

public FixedSegment GetEdge(int index)

Parameters

index int

Returns

FixedSegment

GetHashCode()

public override int GetHashCode()

Returns

int

GetPoint(Fixed64, Fixed64)

Gets the point represented by barycentric weights for vertices B and C without saturating intermediate differences.

public Vector3d GetPoint(Fixed64 weightB, Fixed64 weightC)

Parameters

weightB Fixed64
weightC Fixed64

Returns

Vector3d

GetVertex(int)

Gets a vertex by stable index: 0 = A, 1 = B, 2 = C.

public Vector3d GetVertex(int index)

Parameters

index int

Returns

Vector3d

TryGetCenteredCapsuleContact(Vector3d, FixedQuaternion, Vector3d, FixedQuaternion, Fixed64, Fixed64, Vector3d, out FixedContactAnchors)

Attempts to construct an exact contact between this rigidly transformed triangle and a centered capsule.

public readonly bool TryGetCenteredCapsuleContact(Vector3d triangleOrigin, FixedQuaternion triangleRotation, Vector3d capsuleCenter, FixedQuaternion capsuleRotation, Fixed64 capsuleAxisLength, Fixed64 capsuleRadius, Vector3d fallbackNormal, out FixedContactAnchors contact)

Parameters

triangleOrigin Vector3d
triangleRotation FixedQuaternion
capsuleCenter Vector3d
capsuleRotation FixedQuaternion
capsuleAxisLength Fixed64
capsuleRadius Fixed64
fallbackNormal Vector3d
contact FixedContactAnchors

Returns

bool

Remarks

The returned triangle witness remains in the supplied triangle frame. The capsule witness remains in the supplied capsule frame so callers can retain stable rigid-frame feature identity independently of world pose.

TryGetCenteredCapsuleContact(Vector3d, Vector3d, Fixed64, Fixed64, Vector3d, out Vector3d, out Vector3d, out Vector3d, out Fixed64)

Attempts to create an inclusive contact between this triangle and a conceptual centered capsule.

public readonly bool TryGetCenteredCapsuleContact(Vector3d center, Vector3d axisDirection, Fixed64 axisLength, Fixed64 radius, Vector3d fallbackNormal, out Vector3d pointOnTriangle, out Vector3d pointOnCapsule, out Vector3d normal, out Fixed64 depth)

Parameters

center Vector3d
axisDirection Vector3d
axisLength Fixed64
radius Fixed64
fallbackNormal Vector3d
pointOnTriangle Vector3d
pointOnCapsule Vector3d
normal Vector3d
depth Fixed64

Returns

bool

Remarks

The returned normal points from the triangle toward the capsule. fallbackNormal is used only when the closest axis and triangle points coincide. A false result means that the contact is separated or that at least one final output is not representable; use DoesCenteredCapsuleOverlap(Vector3d, Vector3d, Fixed64, Fixed64) when classification must remain independent of witness materialization.

TryGetCenteredCapsuleSlabContact(Vector3d, FixedQuaternion, Vector3d, Fixed64, Vector2d, Fixed64, Fixed64, Fixed64, out FixedContactAnchors)

Attempts to construct canonical contact anchors between this rigidly transformed triangle and one vertical centered-capsule slab.

public readonly bool TryGetCenteredCapsuleSlabContact(Vector3d triangleOrigin, FixedQuaternion triangleRotation, Vector3d slabCenter, Fixed64 capsuleFrameRotation, Vector2d localCapsuleAxisDirection, Fixed64 capsuleAxisLength, Fixed64 capsuleRadius, Fixed64 slabHalfThickness, out FixedContactAnchors contact)

Parameters

triangleOrigin Vector3d
triangleRotation FixedQuaternion
slabCenter Vector3d
capsuleFrameRotation Fixed64
localCapsuleAxisDirection Vector2d
capsuleAxisLength Fixed64
capsuleRadius Fixed64
slabHalfThickness Fixed64
contact FixedContactAnchors

Returns

bool

TryGetCenteredFiniteConeSupportContact(Vector3d, FixedQuaternion, Vector3d, FixedQuaternion, Fixed64, Fixed64, Vector3d, Vector3d, out FixedContactAnchors)

Attempts to project one centered finite-cone support onto this rigidly transformed triangle.

public readonly bool TryGetCenteredFiniteConeSupportContact(Vector3d triangleOrigin, FixedQuaternion triangleRotation, Vector3d coneCenter, FixedQuaternion coneRotation, Fixed64 coneHeight, Fixed64 coneRadius, Vector3d supportDirection, Vector3d normalTriangleToCone, out FixedContactAnchors contact)

Parameters

triangleOrigin Vector3d
triangleRotation FixedQuaternion
coneCenter Vector3d
coneRotation FixedQuaternion
coneHeight Fixed64
coneRadius Fixed64
supportDirection Vector3d
normalTriangleToCone Vector3d
contact FixedContactAnchors

Returns

bool

TryGetCenteredFiniteCylinderSupportContact(Vector3d, FixedQuaternion, Vector3d, FixedQuaternion, Fixed64, Fixed64, Vector3d, Vector3d, out FixedContactAnchors)

Attempts to project one centered finite-cylinder support onto this rigidly transformed triangle.

public readonly bool TryGetCenteredFiniteCylinderSupportContact(Vector3d triangleOrigin, FixedQuaternion triangleRotation, Vector3d cylinderCenter, FixedQuaternion cylinderRotation, Fixed64 cylinderHeight, Fixed64 cylinderRadius, Vector3d supportDirection, Vector3d normalTriangleToCylinder, out FixedContactAnchors contact)

Parameters

triangleOrigin Vector3d
triangleRotation FixedQuaternion
cylinderCenter Vector3d
cylinderRotation FixedQuaternion
cylinderHeight Fixed64
cylinderRadius Fixed64
supportDirection Vector3d
normalTriangleToCylinder Vector3d
contact FixedContactAnchors

Returns

bool

TryGetCircleSlabContact(Vector3d, FixedQuaternion, Vector3d, Fixed64, Fixed64, Fixed64, out FixedContactAnchors)

Attempts to construct canonical contact anchors between this rigidly transformed triangle and one vertical circle slab.

public readonly bool TryGetCircleSlabContact(Vector3d triangleOrigin, FixedQuaternion triangleRotation, Vector3d slabCenter, Fixed64 circleFrameRotation, Fixed64 slabHalfThickness, Fixed64 circleRadius, out FixedContactAnchors contact)

Parameters

triangleOrigin Vector3d
triangleRotation FixedQuaternion
slabCenter Vector3d
circleFrameRotation Fixed64
slabHalfThickness Fixed64
circleRadius Fixed64
contact FixedContactAnchors

Returns

bool

TryGetClosestPointsToCenteredAxis(Vector3d, Vector3d, Fixed64, out Vector3d, out Vector3d)

Attempts to return the closest points on this triangle and a conceptual centered finite axis without materializing its endpoints.

public readonly bool TryGetClosestPointsToCenteredAxis(Vector3d center, Vector3d axisDirection, Fixed64 axisLength, out Vector3d pointOnTriangle, out Vector3d pointOnAxis)

Parameters

center Vector3d
axisDirection Vector3d
axisLength Fixed64
pointOnTriangle Vector3d
pointOnAxis Vector3d

Returns

bool

TryGetContact(Vector3d, FixedQuaternion, Vector3d, FixedQuaternion, FixedTriangle, out FixedContactAnchors)

Attempts to construct an exact full-domain contact relation between this triangle and second in their respective rigid frames.

public readonly bool TryGetContact(Vector3d firstOrigin, FixedQuaternion firstRotation, Vector3d secondOrigin, FixedQuaternion secondRotation, FixedTriangle second, out FixedContactAnchors contact)

Parameters

firstOrigin Vector3d
firstRotation FixedQuaternion
secondOrigin Vector3d
secondRotation FixedQuaternion
second FixedTriangle
contact FixedContactAnchors

Returns

bool

false when either triangle has an exact-zero normal or when a separating axis has negative overlap; otherwise true.

Remarks

Exact touching is a contact with zero depth. The normal points from the first triangle toward the second, and each returned anchor remains in its input frame. The winning depth is rounded half to even once; an unrepresentable positive depth is returned as MaxValue with DepthIsClamped set.

Exceptions

ArgumentException

firstRotation is not normalized.

ArgumentException

secondRotation is not normalized.

TryGetFiniteConeIntersectionMinimumAxialPoint(Vector3d, Vector3d, Fixed64, Fixed64, out Vector3d)

Finds the intersecting point with the smallest axial parameter in an apex-authored finite cone.

public bool TryGetFiniteConeIntersectionMinimumAxialPoint(Vector3d apex, Vector3d apexToBaseDirection, Fixed64 height, Fixed64 baseRadius, out Vector3d point)

Parameters

apex Vector3d
apexToBaseDirection Vector3d
height Fixed64
baseRadius Fixed64
point Vector3d

Returns

bool

Remarks

Boundary candidates are visited in AB, BC, CA, face order. Triangle-face roots use a MaxValue-scaled parameter lattice; exact wide predicates select the witness before one final point rounding.

TryGetFiniteSlabProjectedCircleContact(Vector3d, FixedQuaternion, Vector2d, Fixed64, Fixed64, Fixed64, out FixedPointAnchor)

Attempts to find a triangle witness where a world-X/Z circle overlaps the triangle portion inside one finite world-Y slab.

public readonly bool TryGetFiniteSlabProjectedCircleContact(Vector3d triangleOrigin, FixedQuaternion triangleRotation, Vector2d circleCenter, Fixed64 circleRadius, Fixed64 slabCenterY, Fixed64 slabHalfThickness, out FixedPointAnchor triangleContact)

Parameters

triangleOrigin Vector3d
triangleRotation FixedQuaternion
circleCenter Vector2d
circleRadius Fixed64
slabCenterY Fixed64
slabHalfThickness Fixed64
triangleContact FixedPointAnchor

Returns

bool

TryGetFiniteSlabProjectedCircleSweep(Vector3d, FixedQuaternion, Vector2d, Vector2d, Fixed64, Fixed64, Fixed64, Fixed64, out Fixed64, out FixedPointAnchor)

Finds the first distance where a circle swept in world X/Z reaches the triangle portion inside one finite world-Y slab.

public readonly bool TryGetFiniteSlabProjectedCircleSweep(Vector3d triangleOrigin, FixedQuaternion triangleRotation, Vector2d circleStart, Vector2d normalizedDirection, Fixed64 maximumDistance, Fixed64 circleRadius, Fixed64 slabCenterY, Fixed64 slabHalfThickness, out Fixed64 distance, out FixedPointAnchor triangleContact)

Parameters

triangleOrigin Vector3d
triangleRotation FixedQuaternion
circleStart Vector2d
normalizedDirection Vector2d
maximumDistance Fixed64
circleRadius Fixed64
slabCenterY Fixed64
slabHalfThickness Fixed64
distance Fixed64
triangleContact FixedPointAnchor

Returns

bool

Remarks

Triangle transformation, slab clipping, and time-of-impact classification remain exact until the final Q32.32 distance and local triangle witness are rounded.

TryGetProjectedBarycentricWeights(Vector3d, out Fixed64, out Fixed64, out Fixed64)

Computes barycentric weights for the point projected onto this triangle's plane.

public bool TryGetProjectedBarycentricWeights(Vector3d point, out Fixed64 weightA, out Fixed64 weightB, out Fixed64 weightC)

Parameters

point Vector3d
weightA Fixed64
weightB Fixed64
weightC Fixed64

Returns

bool

True when the exact Gram denominator is outside the inclusive Epsilon failure threshold; otherwise false with all three weights set to zero.

Remarks

Successful weights are computed from independent exact numerators, then rounded half to even and saturated independently at the public boundary. The point is projected onto the triangle plane; it need not lie on it.

TryGetSphereContact(Vector3d, FixedQuaternion, Vector3d, FixedQuaternion, Fixed64, out FixedContactAnchors)

Attempts to construct an exact contact between this rigidly transformed triangle and a sphere.

public readonly bool TryGetSphereContact(Vector3d triangleOrigin, FixedQuaternion triangleRotation, Vector3d sphereCenter, FixedQuaternion sphereRotation, Fixed64 sphereRadius, out FixedContactAnchors contact)

Parameters

triangleOrigin Vector3d
triangleRotation FixedQuaternion
sphereCenter Vector3d
sphereRotation FixedQuaternion
sphereRadius Fixed64
contact FixedContactAnchors

Returns

bool

Remarks

The relation selects whichever exact coordinate chart can represent the interacting features. The returned triangle witness always remains in the supplied triangle frame.

Operators

operator ==(FixedTriangle, FixedTriangle)

Determines whether two triangles have the same ordered vertices.

public static bool operator ==(FixedTriangle left, FixedTriangle right)

Parameters

left FixedTriangle
right FixedTriangle

Returns

bool

operator !=(FixedTriangle, FixedTriangle)

Determines whether two triangles have different ordered vertices.

public static bool operator !=(FixedTriangle left, FixedTriangle right)

Parameters

left FixedTriangle
right FixedTriangle

Returns

bool