This page has been translated automatically.

# Unigine::BoundSphere Class

 Header: #include

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

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

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

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

## BoundSphere ( ) #

Constructor. Creates an empty bounding sphere.

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

Initialization by the center and radius of the bounding sphere.

### Arguments

• const Math::vec3 & center - The bounding sphere center.
• float radius - The bounding sphere radius.

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

Initialization by the vector of points.

### Arguments

• const Math::vec3 * points - Vector of points.
• int num_points - Number of points in the vector.
• int optimal - Flag defining if the optimal sphere should be used. If 0, 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 Math::mat4 & transform ) #

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

### Arguments

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

## explicit BoundSphere ( const BoundBox & bb ) #

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.
• float radius - Radius of the bounding sphere.

## voidset ( const Math::vec3 * points, int num_points, int 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.
• int optimal - Flag defining if the optimal sphere should be used. If 0, 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.

## 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.
Source code (C++)
``````float r = length(center - point);
if (center.w < r)
radius = 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.
Source code (C++)
``````float r = length(bs.center - center) + bs.radius;
if (center.w < r)
radius = 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. It uses the expandRadius method.
Source code (C++)
``````const vec3 &min = bb.getMin();
const vec3 &max = bb.getMax();
expandRadius(vec3(min.x, min.y, min.z));
expandRadius(vec3(max.x, min.y, min.z));
expandRadius(vec3(min.x, max.y, min.z));
expandRadius(vec3(max.x, max.y, min.z));
expandRadius(vec3(min.x, min.y, max.z));
expandRadius(vec3(max.x, min.y, max.z));
expandRadius(vec3(min.x, max.y, max.z));
expandRadius(vec3(max.x, max.y, max.z));``````

## intinside ( 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

1 if the given point is inside the bounding sphere; otherwise, 0.

## intinside ( 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.
• float radius - Radius of the sphere.

### Return value

1 if the sphere is inside the bounding sphere; otherwise, 0.

## intinside ( 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

1 if the box is inside the bounding sphere; otherwise, 0.

## intinside ( const BoundSphere & bs ) const#

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

### Arguments

• const BoundSphere & bs - Bounding sphere.

### Return value

1 if the specified bounding sphere is inside the bounding sphere; otherwise, 0.

## intinside ( const BoundBox & bb ) const#

Checks if the bounding box is inside the bounding sphere.

### Return value

1 if the bounding box is inside the bounding sphere; otherwise, 0.

## intinsideValid ( 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

1 if the given point is inside the bounding sphere; otherwise, 0.

## intinsideValid ( 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.
• float radius - Radius of the sphere.

### Return value

1 if the sphere is inside the bounding sphere; otherwise, 0.

## intinsideValid ( 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

1 if the box is inside the bounding sphere; otherwise, 0.

## intinsideValid ( 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

1 if the bounding sphere is inside the bounding sphere; otherwise, 0.

## intinsideValid ( 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

1 if the bounding box is inside the bounding sphere; otherwise, 0.

## intinsideAll ( 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

1 if the whole bounding sphere is inside the bounding sphere; otherwise, 0.

## intinsideAll ( const BoundBox & bb ) const#

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

### Return value

1 if the whole bounding box is inside the bounding sphere; otherwise, 0.

## intinsideAllValid ( 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

1 if the whole bounding sphere is inside the bounding sphere; otherwise, 0.

## intinsideAllValid ( 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

1 if the whole bounding box is inside the bounding sphere; otherwise, 0.

## intrayIntersection ( 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

1 if an intersection has occurred; otherwise, 0.

## intgetIntersection ( 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

1 if an intersection has occurred; otherwise, 0.

## intrayIntersectionValid ( 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

1 if an intersection has occurred; otherwise, 0.

## intgetIntersectionValid ( 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

1 if an intersection has occurred; otherwise, 0.

## 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.

## Math::vec3getCenter ( ) const#

Returns the bounding sphere center.

### Return value

Bounding sphere center.

## floatgetRadius ( ) const#

Returns the bounding sphere radius.

### Return value

The bounding sphere radius.

## boolisValid ( ) const#

Checks the bounding sphere status.

### Return value

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