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
Fields
A
The first vertex.
[JsonInclude]
[MemoryPackOrder(0)]
public Vector3d A
Field Value
B
The second vertex.
[JsonInclude]
[MemoryPackOrder(1)]
public Vector3d B
Field Value
C
The third vertex.
[JsonInclude]
[MemoryPackOrder(2)]
public Vector3d C
Field Value
EdgeCount
The number of edges in a triangle.
public const int EdgeCount = 3
Field Value
VertexCount
The number of vertices in a triangle.
public const int VertexCount = 3
Field Value
Properties
Area
The non-negative surface area of the triangle.
[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 Area { get; }
Property Value
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
Centroid
The arithmetic center of the three vertices, rounded half to even per component.
[JsonIgnore]
[MemoryPackIgnore]
public Vector3d Centroid { get; }
Property Value
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
Normal
The normalized triangle normal derived from the exact cross product.
[JsonIgnore]
[MemoryPackIgnore]
public Vector3d Normal { get; }
Property Value
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
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
pointVector3d
Returns
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
pointVector3d
Returns
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
pointVector3d
Returns
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
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
pointVector3d
Returns
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
Returns
Equals(FixedTriangle)
public bool Equals(FixedTriangle other)
Parameters
otherFixedTriangle
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
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
triangleOriginVector3dtriangleRotationFixedQuaternionpointFixedPointAnchor
Returns
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
indexint
Returns
GetHashCode()
public override int GetHashCode()
Returns
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
Returns
GetVertex(int)
Gets a vertex by stable index: 0 = A, 1 = B, 2 = C.
public Vector3d GetVertex(int index)
Parameters
indexint
Returns
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
triangleOriginVector3dtriangleRotationFixedQuaternioncapsuleCenterVector3dcapsuleRotationFixedQuaternioncapsuleAxisLengthFixed64capsuleRadiusFixed64fallbackNormalVector3dcontactFixedContactAnchors
Returns
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
centerVector3daxisDirectionVector3daxisLengthFixed64radiusFixed64fallbackNormalVector3dpointOnTriangleVector3dpointOnCapsuleVector3dnormalVector3ddepthFixed64
Returns
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
triangleOriginVector3dtriangleRotationFixedQuaternionslabCenterVector3dcapsuleFrameRotationFixed64localCapsuleAxisDirectionVector2dcapsuleAxisLengthFixed64capsuleRadiusFixed64slabHalfThicknessFixed64contactFixedContactAnchors
Returns
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
triangleOriginVector3dtriangleRotationFixedQuaternionconeCenterVector3dconeRotationFixedQuaternionconeHeightFixed64coneRadiusFixed64supportDirectionVector3dnormalTriangleToConeVector3dcontactFixedContactAnchors
Returns
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
triangleOriginVector3dtriangleRotationFixedQuaternioncylinderCenterVector3dcylinderRotationFixedQuaternioncylinderHeightFixed64cylinderRadiusFixed64supportDirectionVector3dnormalTriangleToCylinderVector3dcontactFixedContactAnchors
Returns
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
triangleOriginVector3dtriangleRotationFixedQuaternionslabCenterVector3dcircleFrameRotationFixed64slabHalfThicknessFixed64circleRadiusFixed64contactFixedContactAnchors
Returns
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
centerVector3daxisDirectionVector3daxisLengthFixed64pointOnTriangleVector3dpointOnAxisVector3d
Returns
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
firstOriginVector3dfirstRotationFixedQuaternionsecondOriginVector3dsecondRotationFixedQuaternionsecondFixedTrianglecontactFixedContactAnchors
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
firstRotationis not normalized.- ArgumentException
secondRotationis 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
Returns
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
triangleOriginVector3dtriangleRotationFixedQuaternioncircleCenterVector2dcircleRadiusFixed64slabCenterYFixed64slabHalfThicknessFixed64triangleContactFixedPointAnchor
Returns
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
triangleOriginVector3dtriangleRotationFixedQuaternioncircleStartVector2dnormalizedDirectionVector2dmaximumDistanceFixed64circleRadiusFixed64slabCenterYFixed64slabHalfThicknessFixed64distanceFixed64triangleContactFixedPointAnchor
Returns
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
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
triangleOriginVector3dtriangleRotationFixedQuaternionsphereCenterVector3dsphereRotationFixedQuaternionsphereRadiusFixed64contactFixedContactAnchors
Returns
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
leftFixedTrianglerightFixedTriangle
Returns
operator !=(FixedTriangle, FixedTriangle)
Determines whether two triangles have different ordered vertices.
public static bool operator !=(FixedTriangle left, FixedTriangle right)
Parameters
leftFixedTrianglerightFixedTriangle