cesium-native  0.41.0
CesiumGeometry::BoundingSphere Class Referencefinal

A bounding sphere with a center and a radius. More...

#include <CesiumGeometry/BoundingSphere.h>

Public Member Functions

constexpr BoundingSphere (const glm::dvec3 &center, double radius) noexcept
 Construct a new instance. More...
 
constexpr const glm::dvec3 & getCenter () const noexcept
 Gets the center of the bounding sphere.
 
constexpr double getRadius () const noexcept
 Gets the radius of the bounding sphere.
 
CullingResult intersectPlane (const Plane &plane) const noexcept
 Determines on which side of a plane this boundings sphere is located. More...
 
double computeDistanceSquaredToPosition (const glm::dvec3 &position) const noexcept
 Computes the distance squared from a position to the closest point on this bounding sphere. Returns 0 if the point is inside the sphere. More...
 
bool contains (const glm::dvec3 &position) const noexcept
 Computes whether the given position is contained within the bounding sphere. More...
 
BoundingSphere transform (const glm::dmat4 &transformation) const noexcept
 Transforms this bounding sphere to another coordinate system using a 4x4 matrix. More...
 

Detailed Description

A bounding sphere with a center and a radius.

Definition at line 16 of file BoundingSphere.h.

Constructor & Destructor Documentation

◆ BoundingSphere()

constexpr CesiumGeometry::BoundingSphere::BoundingSphere ( const glm::dvec3 &  center,
double  radius 
)
inlineconstexprnoexcept

Construct a new instance.

Parameters
centerThe center of the bounding sphere.
radiusThe radius of the bounding sphere.

Definition at line 24 of file BoundingSphere.h.

Member Function Documentation

◆ computeDistanceSquaredToPosition()

double CesiumGeometry::BoundingSphere::computeDistanceSquaredToPosition ( const glm::dvec3 &  position) const
noexcept

Computes the distance squared from a position to the closest point on this bounding sphere. Returns 0 if the point is inside the sphere.

Parameters
positionThe position.
Returns
The distance squared from the position to the closest point on this bounding sphere.
// Sort bounding spheres from back to front
glm::dvec3 cameraPosition = anyOldCameraPosition();
std::vector<BoundingSphere> spheres = anyOldSphereArray();
std::sort(
spheres.begin(),
spheres.end(),
[&cameraPosition](auto& a, auto& b) {
return a.computeDistanceSquaredToPosition(cameraPosition) >
b.computeDistanceSquaredToPosition(cameraPosition);
});

◆ contains()

bool CesiumGeometry::BoundingSphere::contains ( const glm::dvec3 &  position) const
noexcept

Computes whether the given position is contained within the bounding sphere.

Parameters
positionThe position.
Returns
Whether the position is contained within the bounding sphere.

◆ intersectPlane()

CullingResult CesiumGeometry::BoundingSphere::intersectPlane ( const Plane plane) const
noexcept

Determines on which side of a plane this boundings sphere is located.

Parameters
planeThe plane to test against.
Returns
The CullingResult:
  • Inside if the entire sphere is on the side of the plane the normal is pointing.
  • Outside if the entire sphere is on the opposite side.
  • Intersecting if the sphere intersects the plane.

◆ transform()

BoundingSphere CesiumGeometry::BoundingSphere::transform ( const glm::dmat4 &  transformation) const
noexcept

Transforms this bounding sphere to another coordinate system using a 4x4 matrix.

If the transformation has non-uniform scale, the bounding sphere's radius is scaled by the largest scale value among the transformation's axes.

Parameters
transformationThe transformation.
Returns
The bounding sphere in the new coordinate system.

The documentation for this class was generated from the following file: