Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ProwlEngine/Prowl.Vector/llms.txt

Use this file to discover all available pages before exploring further.

Prowl.Vector ships eight bounding volume and shape types, all living in the Prowl.Vector namespace. Six of them — AABB, Sphere, Frustum, Cone, Triangle, and LineSegment — implement IBoundingShape and are therefore compatible with the GJK collision-detection algorithm. Plane and Ray are utility primitives that do not implement the interface but are used extensively by the intersection and ray-cast APIs.

IBoundingShape

namespace Prowl.Vector
{
    public interface IBoundingShape
    {
        Float3 SupportMap(Float3 direction);
        GeometryData GetGeometryData(int resolution = 16);
    }
}
SupportMap(Float3 direction) returns the point on the shape that is farthest in the given direction. The direction does not need to be normalized. This single method is the only requirement for a shape to participate in GJK collision detection — the algorithm calls SupportMap on both shapes to build a simplex in the Minkowski difference space and determine whether the origin is inside it. GetGeometryData(int resolution) generates renderable geometry for the shape as a GeometryData structure containing vertices, edges, and faces. It is used by editor tools and debug visualizers.

AABB

An Axis-Aligned Bounding Box defined by two Float3 corners.

Fields

FieldTypeDescription
MinFloat3The minimum corner. Always ≤ Max after construction.
MaxFloat3The maximum corner.

Constructors

// From two corner points (min/max order is enforced automatically)
new AABB(Float3 min, Float3 max)

// From six individual float components
new AABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)

// From a center point and a size vector (static factory)
AABB.FromCenterAndSize(Float3 center, Float3 size)

Key Properties

PropertyTypeDescription
CenterFloat3(Min + Max) / 2
SizeFloat3Max - Min
ExtentsFloat3Size / 2 (half-size)
VolumefloatSize.X * Size.Y * Size.Z
SurfaceAreafloat2 * (xy + yz + zx)

Key Methods

MethodReturnsDescription
Contains(Float3 point)boolTrue if the point is inside or on the boundary.
Contains(AABB other)boolTrue if other is completely inside this AABB.
Intersects(AABB other)boolTrue if the two AABBs overlap or touch.
Intersects(Sphere sphere)boolTrue if the AABB overlaps the sphere.
Encapsulate(Float3 point)voidExpands the AABB in-place to include a point.
Encapsulate(AABB other)voidExpands the AABB in-place to include another AABB.
Encapsulating(Float3)AABBReturns a new AABB that encapsulates the point.
Expand(float amount)voidExpands all sides outward by amount.
Expand(Float3 expansion)voidExpands each axis independently.
Expanded(float amount)AABBNon-mutating version of Expand.
ClosestPointTo(Float3)Float3Nearest point on the AABB surface to the given point.
GetCorner(int index)Float3One of the 8 corners (index 0–7).
GetCorners()Float3[]All 8 corners.
TransformBy(Float4x4)AABBReturns a new world-space AABB wrapping the transformed corners.
ClippedBy(AABB other)AABBReturns the intersection AABB, or a zero AABB if none.
AABB.FromPoints(Float3[])AABBSmallest AABB containing all given points.
AABB.FromSphere(Sphere)AABBAABB that tightly wraps a sphere.

Example

using Prowl.Vector;

// Build an AABB centered at the origin, 4 units on each side
var box = AABB.FromCenterAndSize(new Float3(0, 0, 0), new Float3(4, 4, 4));

// Grow to include a point outside the box
box.Encapsulate(new Float3(10, 0, 0));

Console.WriteLine(box.Center); // (5, 0, 0)
Console.WriteLine(box.Size);   // (12, 4, 4)

// Test containment
bool inside = box.Contains(new Float3(3, 0, 0)); // true

// AABB vs AABB overlap
var other = new AABB(new Float3(8, -1, -1), new Float3(15, 1, 1));
bool overlaps = box.Intersects(other); // true

Sphere

A sphere defined by a center point and a radius.

Fields

FieldTypeDescription
CenterFloat3World-space center of the sphere.
RadiusfloatRadius; always ≥ 0.

Constructors

new Sphere(Float3 center, float radius)
new Sphere(float x, float y, float z, float radius)

Key Properties

PropertyTypeDescription
DiameterfloatRadius * 2
SurfaceAreafloat4πr²
Volumefloat(4/3)πr³
Circumferencefloat2πr

Key Methods

MethodReturnsDescription
Contains(Float3 point)boolTrue if the point is inside or on the surface.
Contains(Sphere other)boolTrue if other is completely inside this sphere.
Intersects(Sphere other)boolTrue if the two spheres overlap or touch.
Intersects(AABB aabb)boolTrue if the sphere overlaps the AABB.
GetSignedDistanceToPoint(Float3)floatPositive outside, negative inside, zero on surface.
ClosestPointTo(Float3)Float3Nearest point on the sphere surface.
Encapsulate(Float3)voidGrows radius to include the point.
Encapsulate(Sphere)voidGrows radius to include another sphere.
Sphere.FromDiameter(Float3 a, Float3 b)SphereSphere whose diameter is the segment a→b.
Sphere.FromPoints(Float3[])SphereApproximate bounding sphere for a point cloud.

Example

using Prowl.Vector;

var sphere = new Sphere(Float3.Zero, 5.0f);
bool hit = sphere.Contains(new Float3(3, 0, 4)); // true  (dist = 5 = radius)

// Signed distance: negative means inside
float d = sphere.GetSignedDistanceToPoint(new Float3(0, 3, 0)); // -2.0

Frustum

A view frustum defined by six planes: Near, Far, Left, Right, Top, and Bottom.

Fields

FieldTypeDescription
PlanesPlane[]Array of 6 planes (always length 6).
Convenience properties Near, Far, Left, Right, Top, and Bottom index directly into Planes[0..5].

Constructors

// From an array of exactly 6 planes (Near, Far, Left, Right, Top, Bottom)
new Frustum(Plane[] planes)

// From individual planes
new Frustum(Plane near, Plane far, Plane left, Plane right, Plane top, Plane bottom)

Static Factory Methods

MethodDescription
Frustum.FromMatrix(Float4x4 viewProjection)Extracts 6 planes from a combined view-projection matrix using the Gribb/Hartmann method.
Frustum.FromMatrices(Float4x4 view, Float4x4 proj)Convenience overload that multiplies the matrices first.
Frustum.FromCamera(position, forward, up, fovY, aspect, near, far)Constructs a perspective frustum from camera parameters.
Frustum.CreateOrthographic(left, right, bottom, top, near, far)Constructs an orthographic frustum.

Key Methods

MethodReturnsDescription
Contains(Float3 point)boolTrue if the point is inside all 6 planes.
Intersects(Sphere sphere)boolTrue if the sphere is not completely behind any plane.
Intersects(AABB aabb)boolTrue if the AABB is not completely behind any plane.
ClassifyPoint(Float3)intNumber of planes the point is behind (0 = fully inside).
ClassifySphere(Sphere)intPlanes the sphere is completely behind.
ClassifyAABB(AABB)intPlanes the AABB is completely behind.
GetCorners()Float3[]The 8 frustum corners (three-plane intersections).
Transform(Float4x4)FrustumReturns a new frustum transformed by the matrix.
Expand(float amount)voidShifts all planes outward by amount.

Example

using Prowl.Vector;

// Build a frustum from a view-projection matrix
var frustum = Frustum.FromMatrix(viewProjMatrix);

// Frustum culling: skip objects whose bounding sphere is outside
var sphere = new Sphere(objectPosition, objectRadius);
if (!frustum.Intersects(sphere))
    return; // cull

// Point containment check
bool visible = frustum.Contains(lightPosition);

Plane

An infinite plane defined by a unit normal and a signed distance from the origin. The plane equation is dot(Normal, point) = D.

Fields

FieldTypeDescription
NormalFloat3Unit normal vector (normalized on construction).
DfloatSigned distance from the origin along the normal.

Constructors

// From a normal and distance — both are normalized together
new Plane(Float3 normal, float d)

// From three points in counter-clockwise order
new Plane(Float3 point1, Float3 point2, Float3 point3)

// Static factory: from a normal and a point on the plane
Plane.FromNormalAndPoint(Float3 normal, Float3 pointOnPlane)

Key Methods

MethodReturnsDescription
GetSignedDistanceToPoint(Float3)floatPositive if on the normal side, negative if behind.
GetDistanceToPoint(Float3)floatAbsolute distance to the plane.
ClosestPointOnPlane(Float3)Float3Projects a point onto the plane.
GetSide(Float3 point)boolTrue if the point is on the positive (normal) side.
SameSide(Float3 a, Float3 b)boolTrue if both points are on the same side.
Flip()voidReverses the normal and negates D in-place.
Flipped()PlaneReturns a plane facing the opposite direction.
Translate(Float3)voidShifts the plane along the normal.

Example

using Prowl.Vector;

// The XZ ground plane (normal = +Y, passing through the origin)
var ground = Plane.FromNormalAndPoint(Float3.UnitY, Float3.Zero);

// Classify a point
float signedDist = ground.GetSignedDistanceToPoint(new Float3(0, 3, 0)); // +3 (above)
float signedDist2 = ground.GetSignedDistanceToPoint(new Float3(0, -1, 0)); // -1 (below)

// Project a point down onto the ground plane
Float3 projected = ground.ClosestPointOnPlane(new Float3(5, 7, 2));
// projected = (5, 0, 2)

Ray

A ray with an origin and a normalized direction.

Fields

FieldTypeDescription
OriginFloat3The start point of the ray.
DirectionFloat3Unit direction vector (normalized in the constructor).

Constructor

// direction is automatically normalized
new Ray(Float3 origin, Float3 direction)

Key Methods

MethodReturnsDescription
GetPoint(float distance)Float3Origin + Direction * distance
Intersects(Plane, out float distance)boolRay–plane intersection.
Intersects(Triangle, out float dist, out float u, out float v)boolMöller–Trumbore ray–triangle test.
Intersects(AABB, out float tMin, out float tMax)boolSlab-method ray–AABB test.
Intersects(Sphere, out float t0, out float t1)boolRay–sphere test; t0 ≤ t1.
Ray.ScreenPointToRay(screenPos, viewMatrix, projMatrix, width, height)RayUnprojection from 2D screen coordinates (DirectX-style depth).

Example

using Prowl.Vector;

var ray = new Ray(new Float3(0, 10, 0), new Float3(0, -1, 0));

// Hit the ground plane
var ground = Plane.FromNormalAndPoint(Float3.UnitY, Float3.Zero);
if (ray.Intersects(ground, out float dist))
{
    Float3 hitPoint = ray.GetPoint(dist); // (0, 0, 0)
}

// Hit an AABB
var box = new AABB(new Float3(-1, -1, -1), new Float3(1, 1, 1));
if (ray.Intersects(box, out float tMin, out float tMax))
{
    Float3 entry = ray.GetPoint(tMin);
    Float3 exit  = ray.GetPoint(tMax);
}

Cone

A cone defined by an apex point, a base-center point, and a base radius. The cone axis runs from Apex to BaseCenter.

Fields

FieldTypeDescription
ApexFloat3The tip of the cone.
BaseCenterFloat3Center of the base disk.
BaseRadiusfloatRadius of the base disk.

Constructors

new Cone(Float3 apex, Float3 baseCenter, float baseRadius)
new Cone(float apexX, float apexY, float apexZ,
         float baseCenterX, float baseCenterY, float baseCenterZ,
         float baseRadius)

// Static factory: apex + axis direction + height + radius
Cone.FromAxisDirection(Float3 apex, Float3 axisDirection, float height, float baseRadius)

Key Properties

PropertyTypeDescription
HeightfloatDistance from apex to base center.
AxisDirectionFloat3Normalized vector from apex to base center.
Volumefloat(π r² h) / 3
LateralSurfaceAreafloatπ r s where s is the slant height.
TotalSurfaceAreafloatLateral area + base area.

Example

using Prowl.Vector;

// Flashlight cone: apex at camera, pointing forward 5 units, 1.5 unit radius
var cone = Cone.FromAxisDirection(
    apex: new Float3(0, 2, 0),
    axisDirection: new Float3(0, 0, 1),
    height: 5.0f,
    baseRadius: 1.5f
);

bool hit = cone.Contains(new Float3(0, 2, 3)); // true — on axis, inside

Triangle

A triangle defined by three Float3 vertices.

Fields

FieldTypeDescription
V0Float3First vertex.
V1Float3Second vertex.
V2Float3Third vertex.

Constructor

new Triangle(Float3 v0, Float3 v1, Float3 v2)

Key Properties

PropertyTypeDescription
NormalFloat3Cross product (V1−V0) × (V2−V0) — not normalized.
NormalizedNormalFloat3Normalized face normal.
AreafloatLength(Normal) / 2
CentroidFloat3(V0 + V1 + V2) / 3
PerimeterfloatSum of edge lengths.

Key Methods

MethodReturnsDescription
GetBarycentricCoordinates(Float3, out u, out v)voidBarycentric coords of a point. w = 1−u−v.
GetPointFromBarycentric(float u, float v)Float3Point from barycentric coordinates.
ClosestPointTo(Float3)Float3Nearest point on the triangle.
GetPlane()PlaneThe plane containing the triangle.
IntersectsWith(Triangle)boolSAT-based triangle–triangle test.
GetAABB()AABBTight axis-aligned box around the triangle.

Example

using Prowl.Vector;

var tri = new Triangle(
    new Float3(0, 0, 0),
    new Float3(1, 0, 0),
    new Float3(0, 1, 0)
);

Console.WriteLine(tri.Normal);   // (0, 0, 1)  — pointing +Z
Console.WriteLine(tri.Area);     // 0.5

// Closest point on triangle to an arbitrary point
Float3 closest = tri.ClosestPointTo(new Float3(0.5f, 0.5f, 5.0f));
// closest = (0.25, 0.5, 0)

LineSegment

A finite line segment between two Float3 endpoints.

Fields

FieldTypeDescription
StartFloat3Starting endpoint.
EndFloat3Ending endpoint.

Constructors

new LineSegment(Float3 start, Float3 end)
new LineSegment(float startX, float startY, float startZ,
                float endX,   float endY,   float endZ)

// From a Ray with a fixed length
LineSegment.FromRay(Ray ray, float length)

Key Properties

PropertyTypeDescription
CenterFloat3Midpoint: (Start + End) / 2
LengthfloatEuclidean length.
LengthSquaredfloatSquared length (cheaper than Length).
DirectionFloat3End − Start (not normalized).
NormalizedDirectionFloat3Normalized direction vector.

Key Methods

MethodReturnsDescription
GetPoint(float t)Float3Point at parameter t (0 = Start, 1 = End).
GetPointClamped(float t)Float3Same as GetPoint but clamps t to [0, 1].
ClosestPointTo(Float3)Float3Nearest point on the segment.
GetDistanceToPoint(Float3)floatDistance from a point to the segment.
IntersectsPlane(Plane, out Float3 pt)boolSegment–plane intersection point.
GetClosestPoints(LineSegment, out pt1, out pt2, out t1, out t2)voidClosest pair of points between two segments.
Subdivide(int)Float3[]Array of subdivision points including endpoints.

Example

using Prowl.Vector;

var seg = new LineSegment(new Float3(0, 0, 0), new Float3(10, 0, 0));

Console.WriteLine(seg.Center); // (5, 0, 0)
Console.WriteLine(seg.Length); // 10

// Point closest to (5, 3, 0) on the segment
Float3 closest = seg.ClosestPointTo(new Float3(5, 3, 0));
// closest = (5, 0, 0) — projection lands on the segment

// Parametric sampling
Float3 quarter = seg.GetPoint(0.25f); // (2.5, 0, 0)

Build docs developers (and LLMs) love