# Unigine::BoundSphere Struct

This structure serves to construct the bounding sphere in single precision coordinates.

Notice
Instances of this structure are deleted automatically when it is necessary.

In case of double precision coordinates, the bounding sphere should be constructed by using the WorldBoundSphere structure. It includes the same functions as the BoundSphere structure, but its functions deal with the double precision coordinates.

Notice
To support both single and double precision builds, you can use the WorldBoundSphere structure only. The engine will automatically substitute it with the BoundSphere if it is required.

## BoundSphere ( ) #

Constructor. Creates an empty bounding sphere.

## BoundSphere ( const vec3 & center, float radius ) #

Constructor. Initialization by the center and radius of the bounding sphere.

### Arguments

• const vec3 & center - The bounding sphere center.

## BoundSphere ( float x, float y, float z, float radius ) #

Constructor. Initialization by the coordinates of the center and radius of the bounding sphere.

### Arguments

• float x - X-coordinate of the center of the bounding sphere.
• float y - Y-coordinate of the center of the bounding sphere.
• float z - Z-coordinate of the center of the bounding sphere.

## BoundSphere ( const vec3 * points, int num_points, bool optimal ) #

Constructor. Initialization by the vector of points.

### Arguments

• const vec3 * points - Vector of points.
• int num_points - Number of points in the vector.
• bool optimal - Flag defining if the optimal sphere should be used. If false, the sphere will be expanded for including all the given points.

## BoundSphere ( const BoundSphere & bs ) #

Initialization by the bounding sphere.

### Arguments

• const BoundSphere & bs - The bounding sphere.

## BoundSphere ( const BoundSphere & bs, const mat4 & transform ) #

Constructor. Initialization by the bounding sphere and setting the given transformation matrix to the new bounding sphere.

### Arguments

• const BoundSphere & bs - The bounding sphere.
• const mat4 & transform - Transformation matrix.

## explicit BoundSphere ( const BoundBox & bb ) #

Constructor. Initialization by the bounding box.

## BoundSphere &operator= ( const BoundSphere & bs ) #

Assignment operator for the bounding sphere.

### Arguments

• const BoundSphere & bs - The bounding sphere.

## voidclear ( ) #

Clears the bounding sphere.

## voidset ( const Math::vec3 & center, float radius ) #

Sets the bounding sphere by its center and radius.

### Arguments

• const Math::vec3 & center - Center of the bounding sphere.

## voidset ( float x_, float y_, float z_, float radius_ ) #

Sets the bounding sphere by the specified coordinates of the center and radius.

### Arguments

• float x_ - X-coordinate of the center of the bounding sphere.
• float y_ - Y-coordinate of the center of the bounding sphere.
• float z_ - Z-coordinate of the center of the bounding sphere.

## voidset ( const Math::vec3 * points, int num_points, bool optimal ) #

Set the bounding sphere by a vector of points.

### Arguments

• const Math::vec3 * points - Vector of points.
• int num_points - Number of points in the vector.
• bool optimal - Flag defining if the optimal sphere should be used. If false, the sphere will be expanded for including all the given points.

## voidset ( const BoundSphere & bs ) #

Sets the bounding sphere.

### Arguments

• const BoundSphere & bs - Bounding sphere.

## voidset ( const BoundSphere & bs, const Math::mat4 & transform ) #

Sets the bounding sphere by a bounding sphere with a transformation matrix taken into account.

### Arguments

• const BoundSphere & bs - Bounding sphere.
• const Math::mat4 & transform - Transformation matrix.

## voidset ( const BoundBox & bb ) #

Sets the bounding sphere by the bounding box.

## voidsetCenter ( const vec3& center ) #

Sets the specified coordinates for the center of the bounding sphere.

### Arguments

• const vec3& center - Coordinates of the center of the bounding sphere.

## voidsetTransform ( const Math::mat4 & transform ) #

Sets the given transformation matrix to bounding sphere.

### Arguments

• const Math::mat4 & transform - Transformation matrix.

## voidsetTransform ( const Math::dmat4 & transform ) #

Sets the given transformation matrix to bounding sphere.

### Arguments

• const Math::dmat4 & transform - Transformation matrix.

## intcompare ( const BoundSphere & bs ) #

Compares the bounding sphere with the given one. The degree of precision is equal to 1.0e-6f.

### Arguments

• const BoundSphere & bs - The bounding sphere to compare with.

### Return value

1 if the radii and the centers of both bounding spheres are equal; otherwise, 0.

## intoperator== ( const BoundSphere & bs ) const#

Compares the bounding sphere with the given one according to the degree of precision equal to 1.0e-6f.

### Arguments

• const BoundSphere & bs - The bounding sphere to compare with.

### Return value

1 if the radii and the centers of both bounding spheres are equal; otherwise, 0.

## intoperator!= ( const BoundSphere & bs ) const#

Bounding spheres not equal comparison operator.

### Arguments

• const BoundSphere & bs - The bounding sphere to compare with.

### Return value

1 if the radii and the centers of both bounding spheres are not equal; otherwise, 0.

## voidexpand ( const Math::vec3 & point ) #

Expands the current bounding sphere to include the given point.

### Arguments

• const Math::vec3 & point - Coordinates of the point.

## voidexpand ( const Math::vec3 * points, int num_points ) #

Expands the current bounding sphere for including all points in the vector.

### Arguments

• const Math::vec3 * points - Vector of points.
• int num_points - Number of points.

## voidexpand ( const BoundSphere & bs ) #

Expands the current bounding sphere to include the given bounding sphere.

### Arguments

• const BoundSphere & bs - Bounding sphere to be included.

## voidexpand ( const BoundBox & bb ) #

Expands the current bounding sphere to include the given bounding box.

### Arguments

• const BoundBox & bb - Bounding box to be included.

## voidexpandRadius ( const Math::vec3 & point ) #

Expands the radius of the bounding sphere.Expands the radius of the bounding sphere.
Source code (C++)
``````float r = length(center - point);
if (center.w < r)

### Arguments

• const Math::vec3 & point - Point coordinates setting the end point of radius.

## voidexpandRadius ( const Math::vec3 * points, int num_points ) #

Expands the radius of the current bounding sphere for including all points in the vector.

### Arguments

• const Math::vec3 * points - Vector of points.
• int num_points - Number of points.

## voidexpandRadius ( const BoundSphere & bs ) #

Expands the radius of the bounding sphere by using the radius of the given bounding sphere.Expands the radius of the bounding sphere by using the radius of the given bounding sphere.
Source code (C++)
``````float r = length(bs.center - center) + bs.radius;
if (center.w < r)

### Arguments

• const BoundSphere & bs - Bounding sphere.

## voidexpandRadius ( const BoundBox & bb ) #

Expands the radius of the bounding sphere by using the max and min points of the given bounding box.Expands the radius of the bounding sphere by using the max and min points of the given bounding box. It uses the expandRadius method.
Source code (C++)
``````const vec3 &min = bb.getMin();
const vec3 &max = bb.getMax();

## boolinside ( const Math::vec3 & point ) const#

Checks if the given point is inside the current bounding sphere.

### Arguments

• const Math::vec3 & point - Point coordinates.

### Return value

true if the given point is inside the bounding sphere; otherwise, false.

## boolinside ( const Math::vec3 & point, float radius ) const#

Checks if the sphere is inside the bounding sphere.

### Arguments

• const Math::vec3 & point - Center of the sphere.

### Return value

true if the sphere is inside the bounding sphere; otherwise, false.

## boolinside ( const Math::vec3 & min, const Math::vec3 & max ) const#

Checks if the box is inside the bounding sphere.

### Arguments

• const Math::vec3 & min - The box minimum coordinates.
• const Math::vec3 & max - The box maximum coordinates.

### Return value

true if the box is inside the bounding sphere; otherwise, false.

## boolinside ( const BoundSphere & bs ) const#

Checks if the specified bounding sphere is inside the bounding sphere.

### Arguments

• const BoundSphere & bs - Bounding sphere.

### Return value

true if the specified bounding sphere is inside the bounding sphere; otherwise, false.

## boolinside ( const BoundBox & bb ) const#

Checks if the bounding box is inside the bounding sphere.

### Return value

true if the bounding box is inside the bounding sphere; otherwise, false.

## boolinsideValid ( const Math::vec3 & point ) const#

Checks if the given point is inside the current bounding sphere.
Notice
The method doesn't check if the bounding sphere is valid (has a positive radius).

### Arguments

• const Math::vec3 & point - Point.

### Return value

true if the given point is inside the bounding sphere; otherwise, false.

## boolinsideValid ( const Math::vec3 & point, float radius ) const#

Checks if the given sphere is inside the current bounding sphere.
Notice
The method doesn't check if the bounding sphere is valid (has a positive radius).

### Arguments

• const Math::vec3 & point - Cente of the sphere.

### Return value

true if the sphere is inside the bounding sphere; otherwise, false.

## boolinsideValid ( const Math::vec3 & min, const Math::vec3 & max ) const#

Checks if the box is inside the bounding sphere.
Notice
The method doesn't check if the bounding sphere is valid (has a positive radius).

### Arguments

• const Math::vec3 & min - The box minimum coordinates.
• const Math::vec3 & max - The box maximum coordinates.

### Return value

true if the box is inside the bounding sphere; otherwise, false.

## boolinsideValid ( const BoundSphere & bs ) const#

Checks if the bounding sphere is inside the bounding sphere.
Notice
The method doesn't check if the bounding sphere is valid (has a positive radius).

### Arguments

• const BoundSphere & bs - The bounding sphere.

### Return value

true if the bounding sphere is inside the bounding sphere; otherwise, false.

## boolinsideValid ( const BoundBox & bb ) const#

Checks if the bounding box is inside the bounding sphere.
Notice
The method doesn't check if the bounding sphere is valid (has a positive radius).

### Return value

true if the bounding box is inside the bounding sphere; otherwise, false.

## boolinsideAll ( const BoundSphere & bs ) const#

Checks if the whole specified bounding sphere is inside the current bounding sphere.

### Arguments

• const BoundSphere & bs - Bounding sphere.

### Return value

true if the whole bounding sphere is inside the bounding sphere; otherwise, false.

## boolinsideAll ( const BoundBox & bb ) const#

Checks if the whole specified bounding box is inside the current bounding sphere.

### Return value

true if the whole bounding box is inside the bounding sphere; otherwise, false.

## boolinsideAllValid ( const BoundSphere & bs ) const#

Checks if the whole given bounding sphere is inside the current bounding sphere.
Notice
The method doesn't check if the bounding sphere is valid (has a positive radius).

### Arguments

• const BoundSphere & bs - Bounding sphere.

### Return value

true if the whole bounding sphere is inside the bounding sphere; otherwise, false.

## boolinsideAllValid ( const BoundBox & bb ) const#

Checks if the whole given bounding box is inside the current bounding sphere.
Notice
The method doesn't check if the bounding sphere is valid (has a positive radius).

### Return value

true if the whole bounding box is inside the bounding sphere; otherwise, false.

## boolrayIntersection ( const Math::vec3 & point, const Math::vec3 & direction ) const#

Checks for an intersection of a ray with the current bounding sphere.

### Arguments

• const Math::vec3 & point - The starting point of the ray.
• const Math::vec3 & direction - The direction vector of the ray.

### Return value

true if an intersection has occurred; otherwise, false.

## boolgetIntersection ( const Math::vec3 & p0, const Math::vec3 & p1 ) const#

Checks for an intersection of a line with the current bounding sphere.

### Arguments

• const Math::vec3 & p0 - The starting point of the line.
• const Math::vec3 & p1 - The ending point of the line.

### Return value

true if an intersection has occurred; otherwise, false.

## boolrayIntersectionValid ( const Math::vec3 & point, const Math::vec3 & direction ) const#

Checks for an intersection of a ray with the current bounding sphere.
Notice
This method doesn't check if the current bounding sphere is valid (has a positive radius).

### Arguments

• const Math::vec3 & point - The starting point of the ray.
• const Math::vec3 & direction - The direction vector of the ray.

### Return value

true if an intersection has occurred; otherwise, false.

## boolgetIntersectionValid ( const Math::vec3 & p0, const Math::vec3 & p1 ) const#

Checks for an intersection of a line with the current bounding sphere.
Notice
This method doesn't check if the current bounding sphere is valid (has a positive radius).

### Arguments

• const Math::vec3 & p0 - The starting point of the line.
• const Math::vec3 & p1 - The ending point of the line.

### Return value

true if an intersection has occurred; otherwise, false.

## floatdistance ( ) const#

Returns the distance from the origin of coordinates to the closest point of the current bounding sphere.

### Return value

Distance from the origin, in units.

## floatdistance ( const Math::vec3 & point ) const#

Returns the distance from the given point to the closest point of the current bounding sphere.

### Arguments

• const Math::vec3 & point - Coordinates of the point.

### Return value

Distance from the point, in units.

## floatdistanceValid ( ) const#

Returns the distance from the origin of coordinates to the closest point of the current bounding sphere.

### Return value

Distance from the origin, in units.

## floatdistanceValid ( const Math::vec3 & point ) const#

Returns the distance from the given point to the closest point of the current bounding sphere.

### Arguments

• const Math::vec3 & point - Point

### Return value

Distance from the point, in units.

## boolisValid ( ) const#

Checks the bounding sphere status.

### Return value

true if the bounding sphere radius has a positive value; otherwise, false.

## boolisCameraVisible ( const vec3& camera, float min_distance, float max_distance ) const#

Returns a value indicating if the bounding sphere is visible fro the camera.

### Arguments

• const vec3& camera - Coordinates of the camera position.
• float min_distance - Minimum visibility distance, in meters.
• float max_distance - Maximum visibility distance, in meters.

### Return value

true if the bounding sphere radius has a positive value; otherwise, false.
Last update: 2022-04-26