template <typename Scalar>
muu::bounding_sphere struct

A bounding sphere.

Template parameters
Scalar The bounding sphere's scalar component type. Must be a floating-point type.

Public types

using constants = muu::constants<bounding_sphere>
Compile-time bounding sphere constants.
using scalar_type = Scalar
The bounding sphere's scalar type.
using vector_type = vector<scalar_type, 3>
The three-dimensional muu::vector with the same scalar_type as the bounding sphere.

Constructors, destructors, conversion operators

bounding_sphere() defaulted noexcept
Default constructor. Values are not initialized.
bounding_sphere(const bounding_sphere&) defaulted constexpr noexcept
Copy constructor.
bounding_sphere(const vector_type& cen, scalar_type rad) constexpr noexcept
Constructs a bounding sphere from center and radius values.
bounding_sphere(scalar_type cen_x, scalar_type cen_y, scalar_type cen_z, scalar_type rad) constexpr noexcept
Constructs a bounding sphere from center and radius values.
bounding_sphere(scalar_type rad) explicit constexpr noexcept
Constructs a bounding sphere at the origin.
template <typename S>
bounding_sphere(const bounding_sphere<S>& bs) explicit constexpr noexcept
Converting constructor.
template <typename T>
bounding_sphere(const T& obj) constexpr noexcept
Constructs a bounding sphere from an implicitly bit-castable type.

Public functions

auto operator=(const bounding_sphere&) -> bounding_sphere& defaulted constexpr noexcept
Copy-assigment operator.

Public variables

vector_type center
The center of the sphere.
scalar_type radius
The radius of the sphere.

Collision detection

static auto contains(const bounding_sphere& bs, const vector_type& point) -> bool constexpr noexcept
Returns true if a bounding sphere contains a point.
static auto contains(const bounding_sphere& bs, const vector_type& start, const vector_type& end) -> bool constexpr noexcept
Returns true if a bounding sphere contains a line segment.
static auto contains(const bounding_sphere& bb, const line_segment<scalar_type>& seg) -> bool constexpr noexcept
Returns true if a bounding sphere contains a line segment.
static auto contains(const bounding_sphere& bs, const vector_type& p0, const vector_type& p1, const vector_type& p2) -> bool constexpr noexcept
Returns true if a bounding sphere contains a triangle.
static auto contains(const bounding_sphere& bs, const triangle<scalar_type>& tri) -> bool constexpr noexcept
Returns true if a bounding sphere contains a triangle.
static auto contains(const bounding_sphere& outer, const bounding_sphere& inner) -> bool constexpr noexcept
Returns true if a bounding sphere contains all the points of another bounding sphere.
static auto contains(const bounding_sphere& outer, const bounding_box<scalar_type>& inner) -> bool constexpr noexcept
Returns true if a bounding sphere contains all the points of an axis-aligned bounding box.
static auto intersects(const bounding_sphere& bs, const vector_type& p0, const vector_type& p1, const vector_type& p2) -> bool constexpr noexcept
Returns true if a bounding sphere intersects a triangle.
static auto intersects(const bounding_sphere& bs, const triangle<scalar_type>& tri) -> bool constexpr noexcept
Returns true if a bounding sphere intersects a triangle.
static auto intersects(const bounding_sphere& bs1, const bounding_sphere& bs2) -> bool constexpr noexcept
Returns true if two bounding spheres intersect.
static auto intersects(const bounding_sphere& bs, const bounding_box<scalar_type>& bb) -> bool constexpr noexcept
Returns true if a bounding sphere intersects a bounding box.
static auto intersects(const bounding_sphere& bs, const oriented_bounding_box<scalar_type>& bb) -> bool constexpr noexcept
Returns true if a bounding sphere intersects an oriented bounding box.
auto collision_tester() const -> muu::collision_tester<bounding_sphere> constexpr noexcept
Creates an #muu::collision_tester for this bounding sphere.
auto contains(const vector_type& point) const -> bool constexpr noexcept
Returns true if the bounding sphere contains a point.
auto contains(const vector_type* begin, const vector_type* end) -> bool constexpr noexcept
Returns true if the bounding sphere contains all the points in an arbitrary collection.
auto contains(const line_segment<scalar_type>& seg) const -> bool constexpr noexcept
Returns true if the bounding sphere contains a line segment.
auto contains(const triangle<scalar_type>& tri) const -> bool constexpr noexcept
Returns true if the bounding sphere contains a triangle.
auto contains(const bounding_sphere& bs) const -> bool constexpr noexcept
Returns true if the bounding sphere contains all the points of another bounding sphere.
auto contains(const bounding_box<scalar_type>& bb) const -> bool constexpr noexcept
Returns true if the bounding sphere contains all the points of an axis-aligned bounding box.
auto intersects(const triangle<scalar_type>& tri) const -> bool constexpr noexcept
Returns true if the bounding sphere intersects a triangle.
auto intersects(const bounding_sphere& bs) const -> bool constexpr noexcept
Returns true if two bounding spheres intersect.
auto intersects(const bounding_box<scalar_type>& bb) const -> bool constexpr noexcept
Returns true if the bounding sphere intersects a bounding box.
auto intersects(const oriented_bounding_box<scalar_type>& bb) const -> bool constexpr noexcept
Returns true if the bounding sphere intersects an oriented bounding box.

Equality (approximate)

static auto approx_empty(const bounding_sphere& bs, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a bounding sphere has approximately zero volume.
template <typename T>
static auto approx_equal(const bounding_sphere& bs1, const bounding_sphere<T>& bs2, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) -> bool constexpr noexcept
Returns true if two bounding spheres are approximately equal.
static auto approx_zero(const bounding_sphere& bs, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if all the scalar components in a bounding sphere are approximately equal to zero.
auto approx_empty(scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if the bounding sphere has approximately zero volume.
template <typename T>
auto approx_equal(const bounding_sphere<T>& bs, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) const -> bool constexpr noexcept
Returns true if the bounding sphere is approximately equal to another.
auto approx_zero(scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if all the scalar components in the bounding sphere are approximately equal to zero.

Equality (exact)

static auto degenerate(const bounding_sphere& bs) -> bool constexpr noexcept
Returns true if a sphere is degenerate (i.e. its radius is less than or equal to zero).
static auto empty(const bounding_sphere& bs) -> bool constexpr noexcept
Returns true if a bounding sphere has exactly zero volume.
static auto infinity_or_nan(const bounding_sphere& bs) -> bool constexpr noexcept
Returns true if any of the scalar components of a bounding sphere are infinity or NaN.
static auto zero(const bounding_sphere& bs) -> bool constexpr noexcept
Returns true if all the scalar components of a bounding sphere are exactly zero.
auto degenerate() const -> bool constexpr noexcept
Returns true if the sphere is degenerate (i.e. its radius is less than or equal to zero).
auto empty() const -> bool constexpr noexcept
Returns true if the bounding sphere has exactly zero volume.
auto infinity_or_nan() const -> bool constexpr noexcept
Returns true if any of the scalar components of the bounding sphere are infinity or NaN.
auto zero() const -> bool constexpr noexcept
Returns true if all the scalar components of the bounding sphere are exactly zero.
template <typename T>
auto operator!=(const bounding_sphere& lhs, const bounding_sphere<T>& rhs) -> bool constexpr noexcept
Returns true if two bounding spheres are not exactly equal.
template <typename T>
auto operator==(const bounding_sphere& lhs, const bounding_sphere<T>& rhs) -> bool constexpr noexcept
Returns true if two bounding spheres are exactly equal.

Geometric properties

auto density(scalar_type mass) const -> scalar_type constexpr noexcept
Calculates the density of this sphere if it had a given mass.
auto diameter() const -> scalar_type constexpr noexcept
Calculates the diameter of the sphere.
auto mass(scalar_type density) const -> scalar_type constexpr noexcept
Calculates the mass of this sphere if it had a given density.
auto volume() const -> scalar_type constexpr noexcept
Calculates the volume of the sphere.

Point queries

auto closest_point(const vector_type& point) const -> vector_type constexpr noexcept
Gets point contained by the bounding sphere closest to another arbitrary point.

Scalar accessors

auto data() -> scalar_type* constexpr noexcept
Returns a pointer to the first scalar component in the bounding sphere.
auto data() const -> constscalar_type* constexpr noexcept
Returns a pointer to the first scalar component in the bounding sphere.

Scaling

static auto scale(const bounding_sphere& bs, scalar_type scale_) -> bounding_sphere constexpr noexcept
Scales a bounding sphere.
auto scale(scalar_type scale_) -> bounding_sphere& constexpr noexcept
Scales the bounding sphere (in-place).

Translation

static auto translate(const bounding_sphere& bs, const vector_type& offset) -> bounding_sphere constexpr noexcept
Translates a bounding sphere.
auto translate(const vector_type& offset) -> bounding_sphere& constexpr noexcept
Translates the bounding sphere (in-place).

Friends

template <typename Char, typename Traits>
auto operator<<(std::basic_ostream<Char, Traits>& os, const bounding_sphere& bs) -> std::basic_ostream<Char, Traits>&
Writes a bounding_sphere out to a text stream.

Function documentation

template <typename Scalar>
muu::bounding_sphere::bounding_sphere(const vector_type& cen, scalar_type rad) constexpr noexcept

Constructs a bounding sphere from center and radius values.

Parameters
cen The center point.
rad The radius.

template <typename Scalar>
muu::bounding_sphere::bounding_sphere(scalar_type cen_x, scalar_type cen_y, scalar_type cen_z, scalar_type rad) constexpr noexcept

Constructs a bounding sphere from center and radius values.

Parameters
cen_x The X component of the center point.
cen_y The Y component of the center point.
cen_z The Z component of the center point.
rad The radius.

template <typename Scalar>
muu::bounding_sphere::bounding_sphere(scalar_type rad) explicit constexpr noexcept

Constructs a bounding sphere at the origin.

Parameters
rad The radius.

template <typename Scalar>
template <typename T>
muu::bounding_sphere::bounding_sphere(const T& obj) constexpr noexcept

Constructs a bounding sphere from an implicitly bit-castable type.

Template parameters
T A bit-castable type.

template <typename Scalar>
static bool muu::bounding_sphere::empty(const bounding_sphere& bs) constexpr noexcept

Returns true if a bounding sphere has exactly zero volume.

template <typename Scalar>
static bool muu::bounding_sphere::zero(const bounding_sphere& bs) constexpr noexcept

Returns true if all the scalar components of a bounding sphere are exactly zero.

template <typename Scalar>
bool muu::bounding_sphere::empty() const constexpr noexcept

Returns true if the bounding sphere has exactly zero volume.

template <typename Scalar>
bool muu::bounding_sphere::zero() const constexpr noexcept

Returns true if all the scalar components of the bounding sphere are exactly zero.

template <typename Scalar>
template <typename T>
bool muu::bounding_sphere::operator!=(const bounding_sphere& lhs, const bounding_sphere<T>& rhs) constexpr noexcept

Returns true if two bounding spheres are not exactly equal.

template <typename Scalar>
template <typename T>
bool muu::bounding_sphere::operator==(const bounding_sphere& lhs, const bounding_sphere<T>& rhs) constexpr noexcept

Returns true if two bounding spheres are exactly equal.

template <typename Scalar>
static bounding_sphere muu::bounding_sphere::scale(const bounding_sphere& bs, scalar_type scale_) constexpr noexcept

Scales a bounding sphere.

Parameters
bs The bounding sphere to scale.
scale_ The amount to scale the sphere radius by.
Returns A copy of the input sphere scaled by the given amount.

template <typename Scalar>
bounding_sphere& muu::bounding_sphere::scale(scalar_type scale_) constexpr noexcept

Scales the bounding sphere (in-place).

Parameters
scale_ The amount to scale the sphere radius by.
Returns A reference to the sphere.

template <typename Scalar>
static bounding_sphere muu::bounding_sphere::translate(const bounding_sphere& bs, const vector_type& offset) constexpr noexcept

Translates a bounding sphere.

Parameters
bs The bounding sphere to translate.
offset An offset to add to the sphere's center position.
Returns A copy of the input sphere translated by the given offset.

template <typename Scalar>
bounding_sphere& muu::bounding_sphere::translate(const vector_type& offset) constexpr noexcept

Translates the bounding sphere (in-place).

Parameters
offset An offset to add to the sphere's center position.
Returns A reference to the sphere.