Table of Contents

Struct FixedBoundSphere

Namespace
FixedMathSharp.Geometry
Assembly
FixedMathSharp.dll

Represents a spherical bounding volume with fixed-point precision, optimized for fast, rotationally invariant spatial checks in 3D space.

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

Remarks

The FixedBoundSphere provides a simple yet effective way to represent the spatial extent of objects, especially when rotational invariance is required. Compared to FixedBoundBox, it offers faster intersection checks but is less precise in tightly fitting non-spherical objects.

Use Cases:

  • Ideal for broad-phase collision detection, proximity checks, and culling in physics engines and rendering pipelines.
  • Useful when fast, rotationally invariant checks are needed, such as detecting overlaps or distances between moving objects.
  • Suitable for encapsulating objects with roughly spherical shapes or objects that rotate frequently, where the bounding box may need constant updates.

Constructors

FixedBoundSphere(BoundingSphereState)

Initializes a new instance from serialized or caller-provided state.

[JsonConstructor]
public FixedBoundSphere(FixedBoundSphere.BoundingSphereState state)

Parameters

state FixedBoundSphere.BoundingSphereState

FixedBoundSphere(Vector3d, Fixed64)

Initializes a new instance of the FixedBoundSphere struct with the specified center and radius.

public FixedBoundSphere(Vector3d center, Fixed64 radius)

Parameters

center Vector3d
radius Fixed64

Properties

Center

The center point of the sphere.

[JsonIgnore]
[MemoryPackIgnore]
public Vector3d Center { readonly get; set; }

Property Value

Vector3d

Max

Gets the coordinates of the maximum corner of the bounding box that contains the sphere.

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

Property Value

Vector3d

Remarks

The maximum corner is calculated as the center of the sphere plus the radius in each dimension. This property is useful for spatial queries and bounding volume calculations.

Min

Gets the coordinates of the minimum corner of the bounding box that contains the sphere.

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

Property Value

Vector3d

Remarks

The minimum corner is calculated by subtracting the radius from each component of the sphere's center. This property is useful for spatial queries and bounding box calculations.

Radius

The non-negative radius of the sphere. Assigned values are normalized by absolute value.

[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 Radius { get; set; }

Property Value

Fixed64

State

Gets the current normalized state of the sphere.

[JsonInclude]
[MemoryPackInclude]
public FixedBoundSphere.BoundingSphereState State { get; }

Property Value

FixedBoundSphere.BoundingSphereState

Methods

ClampPoint(Vector3d)

Clamps a point to this sphere, returning the point unchanged when it is already inside the sphere.

public Vector3d ClampPoint(Vector3d point)

Parameters

point Vector3d

Returns

Vector3d

Contains(FixedBoundBox)

Tests a bounding box against this sphere.

public FixedEnclosureType Contains(FixedBoundBox box)

Parameters

box FixedBoundBox

Returns

FixedEnclosureType

Contains(FixedBoundFrustum)

Tests a frustum against this sphere.

public FixedEnclosureType Contains(FixedBoundFrustum frustum)

Parameters

frustum FixedBoundFrustum

Returns

FixedEnclosureType

Contains(FixedBoundSphere)

Tests another sphere against this sphere.

public FixedEnclosureType Contains(FixedBoundSphere sphere)

Parameters

sphere FixedBoundSphere

Returns

FixedEnclosureType

Contains(Vector3d)

Checks if a point is inside the sphere.

public bool Contains(Vector3d point)

Parameters

point Vector3d

The point to check.

Returns

bool

True if the point is inside the sphere, otherwise false.

ContainsStrict(Vector3d)

Returns whether the point lies strictly inside this sphere.

public bool ContainsStrict(Vector3d point)

Parameters

point Vector3d

Returns

bool

Remarks

Boundary points and every point tested against a zero-radius sphere return false.

CreateFromBoundingBox(FixedBoundBox)

Creates a bounding sphere that contains the specified axis-aligned bounding box.

public static FixedBoundSphere CreateFromBoundingBox(FixedBoundBox box)

Parameters

box FixedBoundBox

Returns

FixedBoundSphere

Exceptions

OverflowException

Thrown when this construction requires an unrepresentable radius.

CreateFromFrustum(FixedBoundFrustum)

Creates a bounding sphere that contains the specified frustum.

public static FixedBoundSphere CreateFromFrustum(FixedBoundFrustum frustum)

Parameters

frustum FixedBoundFrustum

Returns

FixedBoundSphere

Exceptions

OverflowException

Thrown when this construction requires an unrepresentable radius.

CreateFromPoints(Vector3d[])

Creates a bounding sphere that contains the specified points.

public static FixedBoundSphere CreateFromPoints(Vector3d[] points)

Parameters

points Vector3d[]

Returns

FixedBoundSphere

Exceptions

OverflowException

Thrown when this construction requires an unrepresentable radius.

CreateFromPoints(IEnumerable<Vector3d>)

Creates a bounding sphere that contains the specified points.

public static FixedBoundSphere CreateFromPoints(IEnumerable<Vector3d> points)

Parameters

points IEnumerable<Vector3d>

Returns

FixedBoundSphere

Exceptions

OverflowException

Thrown when this construction requires an unrepresentable radius.

CreateFromPoints(ReadOnlySpan<Vector3d>)

Creates a bounding sphere that contains the specified points.

public static FixedBoundSphere CreateFromPoints(ReadOnlySpan<Vector3d> points)

Parameters

points ReadOnlySpan<Vector3d>

Returns

FixedBoundSphere

Exceptions

OverflowException

Thrown when this construction requires an unrepresentable radius.

CreateMerged(FixedBoundSphere, FixedBoundSphere)

Creates a deterministic sphere that contains the two specified spheres.

public static FixedBoundSphere CreateMerged(FixedBoundSphere original, FixedBoundSphere additional)

Parameters

original FixedBoundSphere
additional FixedBoundSphere

Returns

FixedBoundSphere

Exceptions

OverflowException

Thrown when this construction cannot produce a containing sphere with a representable radius.

Deconstruct(out Vector3d, out Fixed64)

Deconstructs this sphere into its center and radius.

public void Deconstruct(out Vector3d center, out Fixed64 radius)

Parameters

center Vector3d
radius Fixed64

DistanceToSurface(Vector3d)

Calculates the distance from a point to the surface of the sphere.

public Fixed64 DistanceToSurface(Vector3d point)

Parameters

point Vector3d

The point to calculate the distance from.

Returns

Fixed64

The distance from the point to the surface of the sphere.

Equals(FixedBoundSphere)

public bool Equals(FixedBoundSphere other)

Parameters

other FixedBoundSphere

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

Intersects(FixedBoundBox)

Checks whether a bounding box intersects this sphere, including boundary-only contact.

public bool Intersects(FixedBoundBox box)

Parameters

box FixedBoundBox

Returns

bool

Intersects(FixedBoundFrustum)

Checks whether a frustum intersects this sphere.

public bool Intersects(FixedBoundFrustum frustum)

Parameters

frustum FixedBoundFrustum

Returns

bool

Intersects(FixedBoundSphere)

Checks whether another sphere intersects this sphere, including boundary-only contact.

public bool Intersects(FixedBoundSphere sphere)

Parameters

sphere FixedBoundSphere

Returns

bool

Intersects(FixedPlane)

Classifies this sphere relative to a plane.

public FixedPlaneIntersectionType Intersects(FixedPlane plane)

Parameters

plane FixedPlane

Returns

FixedPlaneIntersectionType

Intersects(FixedRay)

Finds the first forward ray intersection with this sphere.

public Fixed64? Intersects(FixedRay ray)

Parameters

ray FixedRay

Returns

Fixed64?

IntersectsStrict(FixedBoundBox)

Checks whether a bounding box overlaps this sphere with positive volume.

public bool IntersectsStrict(FixedBoundBox box)

Parameters

box FixedBoundBox

Returns

bool

IntersectsStrict(FixedBoundSphere)

Checks whether another sphere overlaps this sphere with positive volume.

public bool IntersectsStrict(FixedBoundSphere sphere)

Parameters

sphere FixedBoundSphere

Returns

bool

ProjectPoint(Vector3d)

Projects a point onto the bounding sphere. If the point is outside the sphere, it returns the closest point on the surface.

public Vector3d ProjectPoint(Vector3d point)

Parameters

point Vector3d

Returns

Vector3d

ToString()

Returns a string that represents the current FixedBoundSphere.

public override string ToString()

Returns

string

ToString(string?, IFormatProvider?)

Returns a string that represents the current FixedBoundSphere.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string
formatProvider IFormatProvider

Returns

string

Transform(Fixed4x4)

Creates a sphere that contains this sphere transformed by the specified matrix.

public FixedBoundSphere Transform(Fixed4x4 matrix)

Parameters

matrix Fixed4x4

Returns

FixedBoundSphere

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Formats this sphere into the provided destination buffer.

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters

destination Span<char>
charsWritten int
format ReadOnlySpan<char>
provider IFormatProvider

Returns

bool

Operators

operator ==(FixedBoundSphere, FixedBoundSphere)

Determines whether two FixedBoundSphere instances are equal.

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

Parameters

left FixedBoundSphere
right FixedBoundSphere

Returns

bool

operator !=(FixedBoundSphere, FixedBoundSphere)

Determines whether two FixedBoundSphere instances are not equal.

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

Parameters

left FixedBoundSphere
right FixedBoundSphere

Returns

bool