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
FixedBoundSphere(Vector3d, Fixed64)
Initializes a new instance of the FixedBoundSphere struct with the specified center and radius.
public FixedBoundSphere(Vector3d center, Fixed64 radius)
Parameters
Properties
Center
The center point of the sphere.
[JsonIgnore]
[MemoryPackIgnore]
public Vector3d Center { readonly get; set; }
Property Value
Max
Gets the coordinates of the maximum corner of the bounding box that contains the sphere.
[JsonIgnore]
[MemoryPackIgnore]
public Vector3d Max { get; }
Property Value
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
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
State
Gets the current normalized state of the sphere.
[JsonInclude]
[MemoryPackInclude]
public FixedBoundSphere.BoundingSphereState State { get; }
Property Value
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
pointVector3d
Returns
Contains(FixedBoundBox)
Tests a bounding box against this sphere.
public FixedEnclosureType Contains(FixedBoundBox box)
Parameters
boxFixedBoundBox
Returns
Contains(FixedBoundFrustum)
Tests a frustum against this sphere.
public FixedEnclosureType Contains(FixedBoundFrustum frustum)
Parameters
frustumFixedBoundFrustum
Returns
Contains(FixedBoundSphere)
Tests another sphere against this sphere.
public FixedEnclosureType Contains(FixedBoundSphere sphere)
Parameters
sphereFixedBoundSphere
Returns
Contains(Vector3d)
Checks if a point is inside the sphere.
public bool Contains(Vector3d point)
Parameters
pointVector3dThe 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
pointVector3d
Returns
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
boxFixedBoundBox
Returns
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
frustumFixedBoundFrustum
Returns
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
pointsVector3d[]
Returns
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
pointsIEnumerable<Vector3d>
Returns
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
pointsReadOnlySpan<Vector3d>
Returns
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
originalFixedBoundSphereadditionalFixedBoundSphere
Returns
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
DistanceToSurface(Vector3d)
Calculates the distance from a point to the surface of the sphere.
public Fixed64 DistanceToSurface(Vector3d point)
Parameters
pointVector3dThe 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
otherFixedBoundSphere
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
GetHashCode()
public override int GetHashCode()
Returns
Intersects(FixedBoundBox)
Checks whether a bounding box intersects this sphere, including boundary-only contact.
public bool Intersects(FixedBoundBox box)
Parameters
boxFixedBoundBox
Returns
Intersects(FixedBoundFrustum)
Checks whether a frustum intersects this sphere.
public bool Intersects(FixedBoundFrustum frustum)
Parameters
frustumFixedBoundFrustum
Returns
Intersects(FixedBoundSphere)
Checks whether another sphere intersects this sphere, including boundary-only contact.
public bool Intersects(FixedBoundSphere sphere)
Parameters
sphereFixedBoundSphere
Returns
Intersects(FixedPlane)
Classifies this sphere relative to a plane.
public FixedPlaneIntersectionType Intersects(FixedPlane plane)
Parameters
planeFixedPlane
Returns
Intersects(FixedRay)
Finds the first forward ray intersection with this sphere.
public Fixed64? Intersects(FixedRay ray)
Parameters
rayFixedRay
Returns
IntersectsStrict(FixedBoundBox)
Checks whether a bounding box overlaps this sphere with positive volume.
public bool IntersectsStrict(FixedBoundBox box)
Parameters
boxFixedBoundBox
Returns
IntersectsStrict(FixedBoundSphere)
Checks whether another sphere overlaps this sphere with positive volume.
public bool IntersectsStrict(FixedBoundSphere sphere)
Parameters
sphereFixedBoundSphere
Returns
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
pointVector3d
Returns
ToString()
Returns a string that represents the current FixedBoundSphere.
public override string ToString()
Returns
ToString(string?, IFormatProvider?)
Returns a string that represents the current FixedBoundSphere.
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringformatProviderIFormatProvider
Returns
Transform(Fixed4x4)
Creates a sphere that contains this sphere transformed by the specified matrix.
public FixedBoundSphere Transform(Fixed4x4 matrix)
Parameters
matrixFixed4x4
Returns
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
destinationSpan<char>charsWrittenintformatReadOnlySpan<char>providerIFormatProvider
Returns
Operators
operator ==(FixedBoundSphere, FixedBoundSphere)
Determines whether two FixedBoundSphere instances are equal.
public static bool operator ==(FixedBoundSphere left, FixedBoundSphere right)
Parameters
leftFixedBoundSphererightFixedBoundSphere
Returns
operator !=(FixedBoundSphere, FixedBoundSphere)
Determines whether two FixedBoundSphere instances are not equal.
public static bool operator !=(FixedBoundSphere left, FixedBoundSphere right)
Parameters
leftFixedBoundSphererightFixedBoundSphere