Skip to content

Sphere

A bounding sphere defined by a center point and radius.

Useful for fast intersection tests, frustum culling, and spatial bounds.

Properties

center Vector3

cpp
Vector3 center { Vector3::Zero() }

Center of the sphere in 3D space.

radius float

cpp
float radius { -1.0f }

Radius of the sphere. A negative value indicates an empty sphere.

Functions

ApplyTransform() auto

cpp
auto vglx::Sphere::ApplyTransform(const Matrix4 &transform)
ParameterDescription
transform4x4 matrix to apply to the sphere.

Transforms the sphere by the given matrix. The center is transformed directly, and the radius is scaled by the maximum scale component of the matrix.

ExpandWithPoint() auto

cpp
auto vglx::Sphere::ExpandWithPoint(const Vector3 &p)
ParameterDescription
pPoint to include in the sphere.

Expands the sphere to include a given point. If the sphere is empty, it is initialized with the point. Otherwise, the sphere expands just enough to include the point.

IsEmpty() auto

cpp
auto vglx::Sphere::IsEmpty() const

Checks if the sphere is empty. An empty sphere is defined by a negative radius.

Radius() auto

cpp
auto vglx::Sphere::Radius() const

Returns the current radius of the sphere.

Reset() auto

cpp
auto vglx::Sphere::Reset()

Resets the sphere to an empty state. Sets the center to (0, 0, 0) and the radius to -1.

Sphere() constexpr

cpp
vglx::Sphere::Sphere(const Vector3 center, float radius)
ParameterDescription
centerCenter position.
radiusRadius.

Constructs a Sphere from a center and a radius.

Translate() auto

cpp
auto vglx::Sphere::Translate(const Vector3 &translation)
ParameterDescription
translationVector to translate by.

Translates the sphere by a constant vector.

Union() auto

cpp
auto vglx::Sphere::Union(const Sphere &other)
ParameterDescription
otherThe sphere to merge into this one.

Expands this sphere to fully contain another sphere.

Released under the MIT License.