Geometry3D
Analytic 3D geometry: intersections, planes, clipping and tetrahedra.
Static CPU operations on supplied coordinates. They neither query game-world objects nor use CollisionLayer/CollisionMask or automatically create meshes/collisions. Use one coordinate system for all inputs; apply local/world transforms yourself. Singleton is a borrowed engine service and must not be disposed.
A ray takes an origin and direction; a segment takes two endpoints. RayIntersectsTriangle and SegmentIntersectsTriangle return a Variant: Vector3 on hit, Nil on miss. Do not use Vector3.Zero as a miss sentinel because the origin can be a valid hit position.
using Variant hit = Geometry3D.RayIntersectsTriangle(
new Vector3(0.25f, 0.25f, 1), new Vector3(0, 0, -1),
Vector3.Zero, new Vector3(1, 0, 0), new Vector3(0, 1, 0));
if (hit.VariantType == Variant.Type.Vector3)
{
Vector3 position = hit.AsVector3();
}SegmentIntersectsSphere/Cylinder/Convex return two Vector3 values: [position, normal], not entry and exit. An empty array means no accepted intersection. These are not universal containment tests: sphere and convex queries starting inside return no exit, while cylinder can return the starting point with a zero normal. Exact sphere tangency is excluded. Triangle segments exclude the starting point with a tolerance but include the endpoint; rays also apply a positive parameter cutoff.
BuildBoxPlanes takes half-extents; BuildCylinderPlanes takes full height. BuildCapsulePlanes uses the central cylindrical-section height, making total axial size height+2*radius. This differs from full-height semantics in some collision resources. Cylinder/capsule builders default to the Z axis. Builders return planes rather than ready Mesh/Shape objects.
GetTriangleBarycentricCoords returns a/b/c weights of the projection onto the triangle plane: positive weights do not establish that the original point lies in that plane. ClipPolygon retains the negative Plane halfspace with boundary tolerance; it does not turn an arbitrary unordered point set into a valid polygon. TetrahedralizeDelaunay returns groups of four indices into the original array rather than triangles or a decomposition of an arbitrary mesh with cavities.
34 Windows headless checks covered simple valid shapes, hits/misses, boundary behavior, result layouts and array/span overloads. Arbitrary topology, extreme-scale accuracy, large-data performance, physics-world queries and rendering were not accepted by this suite.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Properties1
SingletonProperty
public static Geometry3DInstance Singleton { get; }Borrowed Geometry3DInstance behind static API. Do not Free/Dispose it; calculations require no user-created instance.
Methods18
BuildBoxPlanesReckfell.Collections.Array<Plane>
public static Reckfell.Collections.Array<Plane> BuildBoxPlanes(Vector3 extents);Returns six planes of an origin-centered axis-aligned box with outward unit normals. extents are half sizes rather than full dimensions. Interior satisfies normal.Dot(point) ≤ D.
| Name | Type | Default |
|---|---|---|
extents | Vector3 | — |
extentsPositive X/Y/Z half sizes, centered at the origin.
Reckfell.Collections.Array<Plane>Array<Plane> of six outward planes, not a Shape3D.
BuildCapsulePlanesReckfell.Collections.Array<Plane>
public static Reckfell.Collections.Array<Plane> BuildCapsulePlanes(float radius, float height, int sides, int lats, Vector3.Axis axis = Vector3.Axis.Z);Builds a capsule plane approximation: sides*(1+2*lats) planes for valid positive parameters. height is central-section length; axial extremes are ±(height/2+radius). Intermediate latitude normals use normalized interpolation rather than uniform angular steps.
| Name | Type | Default |
|---|---|---|
radius | float | — |
height | float | — |
sides | int | — |
lats | int | — |
axis | Vector3.Axis | Vector3.Axis.Z |
radiusPositive finite radius in the same units as the points.
heightNonnegative capsule middle-section length; total height is height+2*radius.
sidesSide-direction count, use at least 3; not a world-unit tolerance.
latsPositive hemisphere subdivision count controlling plane count.
axisX/Y/Z axis; defaults to Z, not an arbitrary Vector3 direction.
Reckfell.Collections.Array<Plane>Array<Plane> approximation rather than a mesh; pole planes can repeat.
BuildCylinderPlanesReckfell.Collections.Array<Plane>
public static Reckfell.Collections.Array<Plane> BuildCylinderPlanes(float radius, float height, int sides, Vector3.Axis axis = Vector3.Axis.Z);Returns sides lateral planes plus two caps for an approximate origin-centered convex cylinder. height is full height with caps at ±height/2; axis defaults to Z. A plane approximation rather than a smooth CylinderShape3D.
| Name | Type | Default |
|---|---|---|
radius | float | — |
height | float | — |
sides | int | — |
axis | Vector3.Axis | Vector3.Axis.Z |
radiusPositive finite radius in the same units as the points.
heightPositive full height with caps at ±height/2.
sidesSide-direction count, use at least 3; not a world-unit tolerance.
axisX/Y/Z axis; defaults to Z, not an arbitrary Vector3 direction.
Reckfell.Collections.Array<Plane>Array<Plane>: sides lateral planes plus two caps.
ClipPolygon2 overloads
public static Vector3[] ClipPolygon(Vector3[] points, Plane plane);Clips an ordered planar polygon, retaining the negative side and tolerance boundary. Last-to-first edge closes the polygon; repeating the first vertex at the end is unnecessary. Validates neither self-intersection nor planarity and creates no volume cap. Array/span overloads share semantics and leave input unchanged.
| Name | Type | Default |
|---|---|---|
points | Vector3[] | — |
plane | Plane | — |
pointsOrdered planar-polygon vertices without a required closing duplicate; at least 3 for an ordinary region.
planeNormalized Plane; retains normal.Dot(point)-D ≤ tolerance.
Vector3[]New Vector3[] of retained vertices/intersections; empty when fully clipped.
public static Vector3[] ClipPolygon(ReadOnlySpan<Vector3> points, Plane plane);Clips an ordered planar polygon, retaining the negative side and tolerance boundary. Last-to-first edge closes the polygon; repeating the first vertex at the end is unnecessary. Validates neither self-intersection nor planarity and creates no volume cap. Array/span overloads share semantics and leave input unchanged.
| Name | Type | Default |
|---|---|---|
points | ReadOnlySpan<Vector3> | — |
plane | Plane | — |
pointsOrdered planar-polygon vertices without a required closing duplicate; at least 3 for an ordinary region.
planeNormalized Plane; retains normal.Dot(point)-D ≤ tolerance.
Vector3[]New Vector3[] of retained vertices/intersections; empty when fully clipped.
ComputeConvexMeshPointsVector3[]
public static Vector3[] ComputeConvexMeshPoints(Reckfell.Collections.Array<Plane> planes);Finds triple-plane intersections not excluded by remaining normal.Dot(point) ≤ D halfspaces with tolerance. Returns no faces/indices and does not deduplicate all vertices. Requires valid normalized outward planes; this is not a convex hull builder for an arbitrary point cloud.
| Name | Type | Default |
|---|---|---|
planes | Reckfell.Collections.Array<Plane> | — |
planesValid normalized outward Planes of a closed convex region, all in one coordinate system.
Vector3[]Vector3 intersections, possibly empty or duplicated, without face topology.
GetClosestPointToSegmentVector3
public static Vector3 GetClosestPointToSegment(Vector3 point, Vector3 s1, Vector3 s2);Projects point onto the segment and clamps to its endpoints. Returns s1 for a near-zero-length segment. Does not return distance; measure from point to the result.
| Name | Type | Default |
|---|---|---|
point | Vector3 | — |
s1 | Vector3 | — |
s2 | Vector3 | — |
pointProjection point in the same coordinates as s1/s2.
s1Endpoint of the corresponding segment; for Uncapped the endpoints define an infinite line.
s2Endpoint of the corresponding segment; for Uncapped the endpoints define an infinite line.
Vector3Point on the finite segment, including endpoints.
GetClosestPointToSegmentUncappedVector3
public static Vector3 GetClosestPointToSegmentUncapped(Vector3 point, Vector3 s1, Vector3 s2);Projects onto the infinite line through s1/s2 without endpoint clamping. Near-coincident endpoints return s1. Does not find a closest surface point.
| Name | Type | Default |
|---|---|---|
point | Vector3 | — |
s1 | Vector3 | — |
s2 | Vector3 | — |
pointProjection point in the same coordinates as s1/s2.
s1Endpoint of the corresponding segment; for Uncapped the endpoints define an infinite line.
s2Endpoint of the corresponding segment; for Uncapped the endpoints define an infinite line.
Vector3Point on the infinite line, or s1 for degeneracy.
GetClosestPointsBetweenSegmentsVector3[]
public static Vector3[] GetClosestPointsBetweenSegments(Vector3 p1, Vector3 p2, Vector3 q1, Vector3 q2);Returns one closest point per finite segment: first p1–p2, then q1–q2. Neither two intersections nor a scalar distance. Parallel/overlapping spans may admit multiple equally close pairs.
| Name | Type | Default |
|---|---|---|
p1 | Vector3 | — |
p2 | Vector3 | — |
q1 | Vector3 | — |
q2 | Vector3 | — |
p1Endpoint of the corresponding segment; for Uncapped the endpoints define an infinite line.
p2Endpoint of the corresponding segment; for Uncapped the endpoints define an infinite line.
q1Endpoint of the corresponding segment; for Uncapped the endpoints define an infinite line.
q2Endpoint of the corresponding segment; for Uncapped the endpoints define an infinite line.
Vector3[]Two Vector3 values: first-segment point, then second-segment point.
GetTriangleBarycentricCoordsVector3
public static Vector3 GetTriangleBarycentricCoords(Vector3 point, Vector3 a, Vector3 b, Vector3 c);Computes a/b/c weights of the projection of point onto the triangle plane. Neither clamps weights to 0…1 nor checks point-to-plane distance. An exactly zero denominator returns Vector3.Zero; validate degeneracy separately.
| Name | Type | Default |
|---|---|---|
point | Vector3 | — |
a | Vector3 | — |
b | Vector3 | — |
c | Vector3 | — |
pointQuery point; for barycentric use separately check its distance to the triangle plane.
aVertex a of a nondegenerate triangle in the common coordinate system.
bVertex b of a nondegenerate triangle in the common coordinate system.
cVertex c of a nondegenerate triangle in the common coordinate system.
Vector3Vector3 of a/b/c weights; Vector3.Zero also denotes a degenerate triangle.
RayIntersectsTriangleVariant
public static Variant RayIntersectsTriangle(Vector3 from, Vector3 dir, Vector3 a, Vector3 b, Vector3 c);Intersects a forward infinite ray with either triangle side. dir is a direction rather than an endpoint. Parallel checks use tolerance; hits require parameter t > 0.00001. Normalize direction for a meaningful tolerance scale. Returns a Vector3/Nil Variant.
| Name | Type | Default |
|---|---|---|
from | Vector3 | — |
dir | Vector3 | — |
a | Vector3 | — |
b | Vector3 | — |
c | Vector3 | — |
fromRay/segment origin in the common coordinate system.
dirNonzero ray direction rather than a to endpoint; normally normalized.
aVertex a of a nondegenerate triangle in the common coordinate system.
bVertex b of a nondegenerate triangle in the common coordinate system.
cVertex c of a nondegenerate triangle in the common coordinate system.
VariantCaller-owned Variant containing Vector3 or Nil. Dispose after checking its type.
SegmentIntersectsConvex2 overloads
public static Vector3[] SegmentIntersectsConvex(Vector3 from, Vector3 to, Reckfell.Collections.Array planes);Finds segment entry into normalized outward-Plane halfspaces normal.Dot(point) ≤ D. Inside starts/zero-length segments do not yield an exit. Returns [entry position, entry-plane normal] or empty. Untyped-overload elements must still be Plane; its adapter creates Array<Plane>.
| Name | Type | Default |
|---|---|---|
from | Vector3 | — |
to | Vector3 | — |
planes | Reckfell.Collections.Array | — |
fromRay/segment origin in the common coordinate system.
toSegment endpoint rather than a direction.
planesValid normalized outward Planes of a closed convex region, all in one coordinate system.
Vector3[]Empty or [entry position, plane normal]; no exit is returned.
public static Vector3[] SegmentIntersectsConvex(Vector3 from, Vector3 to, Reckfell.Collections.Array<Plane> planes);Finds segment entry into normalized outward-Plane halfspaces normal.Dot(point) ≤ D. Inside starts/zero-length segments do not yield an exit. Returns [entry position, entry-plane normal] or empty. Untyped-overload elements must still be Plane; its adapter creates Array<Plane>.
| Name | Type | Default |
|---|---|---|
from | Vector3 | — |
to | Vector3 | — |
planes | Reckfell.Collections.Array<Plane> | — |
fromRay/segment origin in the common coordinate system.
toSegment endpoint rather than a direction.
planesValid normalized outward Planes of a closed convex region, all in one coordinate system.
Vector3[]Empty or [entry position, plane normal]; no exit is returned.
SegmentIntersectsCylinderVector3[]
public static Vector3[] SegmentIntersectsCylinder(Vector3 from, Vector3 to, float height, float radius);Intersects a finite segment with an origin-centered Z-axis cylinder; height is full height and radius is radial. No axis/position argument: transform endpoints into local space yourself. Inside starts can return from with a zero/non-surface normal; this is not an exit intersection.
| Name | Type | Default |
|---|---|---|
from | Vector3 | — |
to | Vector3 | — |
height | float | — |
radius | float | — |
fromRay/segment origin in the common coordinate system.
toSegment endpoint rather than a direction.
heightPositive full height with caps at ±height/2.
radiusPositive finite radius in the same units as the points.
Vector3[]Empty or [position, normal]; inside starts can have a zero normal.
SegmentIntersectsSphereVector3[]
public static Vector3[] SegmentIntersectsSphere(Vector3 from, Vector3 to, Vector3 spherePosition, float sphereRadius);Finds the forward entry of a segment into a sphere. Excludes exact tangency and near-zero segments. Starting inside places entry behind the origin, so no exit is returned. Success gives [position, outward normal], otherwise empty.
| Name | Type | Default |
|---|---|---|
from | Vector3 | — |
to | Vector3 | — |
spherePosition | Vector3 | — |
sphereRadius | float | — |
fromRay/segment origin in the common coordinate system.
toSegment endpoint rather than a direction.
spherePositionSphere center in the same coordinates as from/to.
sphereRadiusPositive finite radius in the same units as the points.
Vector3[]Empty Vector3[] or exactly [position, normal], not two surface points.
SegmentIntersectsTriangleVariant
public static Variant SegmentIntersectsTriangle(Vector3 from, Vector3 to, Vector3 a, Vector3 b, Vector3 c);Intersects finite from→to with either triangle side. Parameter must exceed CMP_EPSILON and be at most 1: start excluded, endpoint allowed. Returns neither normal, UV nor triangle index; result is a Vector3/Nil Variant.
| Name | Type | Default |
|---|---|---|
from | Vector3 | — |
to | Vector3 | — |
a | Vector3 | — |
b | Vector3 | — |
c | Vector3 | — |
fromRay/segment origin in the common coordinate system.
toSegment endpoint rather than a direction.
aVertex a of a nondegenerate triangle in the common coordinate system.
bVertex b of a nondegenerate triangle in the common coordinate system.
cVertex c of a nondegenerate triangle in the common coordinate system.
VariantVariant containing a Vector3 hit or Nil; caller disposes the Variant.
TetrahedralizeDelaunay2 overloads
public static int[] TetrahedralizeDelaunay(Vector3[] points);Builds Delaunay tetrahedra for a volumetric point cloud, returning original indices in groups of four. Neither triangle faces nor a constrained decomposition of a mesh with holes. Supply finite nondegenerate 3D data; index order/orientation and extreme-scale robustness are not established contracts.
| Name | Type | Default |
|---|---|---|
points | Vector3[] | — |
pointsFinite volumetric Vector3 cloud with at least four nondegenerate points; not mesh indices.
int[]int[] indices into original points; each group of four describes a tetrahedron. Empty output does not establish valid input.
public static int[] TetrahedralizeDelaunay(ReadOnlySpan<Vector3> points);Builds Delaunay tetrahedra for a volumetric point cloud, returning original indices in groups of four. Neither triangle faces nor a constrained decomposition of a mesh with holes. Supply finite nondegenerate 3D data; index order/orientation and extreme-scale robustness are not established contracts.
| Name | Type | Default |
|---|---|---|
points | ReadOnlySpan<Vector3> | — |
pointsFinite volumetric Vector3 cloud with at least four nondegenerate points; not mesh indices.
int[]int[] indices into original points; each group of four describes a tetrahedron. Empty output does not establish valid input.