# Ignition Math

## API Reference

6.10.0
Sphere< Precision > Class Template Reference

A representation of a sphere. More...

#include <ignition/math/Sphere.hh>

## Public Member Functions

Sphere ()=default
Default constructor. The default radius is zero. More...

Construct a sphere with a radius. More...

Sphere (const Precision _radius, const Material &_mat)
Construct a sphere with a radius, material. More...

~Sphere ()=default
Destructor. More...

std::optional< Vector3< Precision > > CenterOfVolumeBelow (const Plane< Precision > &_plane) const
Center of volume below the plane. This is useful for example when calculating where buoyancy should be applied. More...

Precision DensityFromMass (const Precision _mass) const
Compute the sphere's density given a mass value. The sphere is assumed to be solid with uniform density. This function requires the sphere's radius to be set to a value greater than zero. The Material of the sphere is ignored. More...

bool MassMatrix (MassMatrix3d &_massMat) const
Get the mass matrix for this sphere. This function is only meaningful if the sphere's radius and material have been set. More...

const MaterialMaterial () const
Get the material associated with this sphere. More...

bool operator!= (const Sphere &_sphere) const
Check if this sphere is not equal to the provided sphere. Radius and material properties will be checked. More...

bool operator== (const Sphere &_sphere) const
Check if this sphere is equal to the provided sphere. Radius and material properties will be checked. More...

Get the radius in meters. More...

bool SetDensityFromMass (const Precision _mass)
Set the density of this sphere based on a mass value. Density is computed using Precision DensityFromMass(const Precision _mass) const. The sphere is assumed to be solid with uniform density. This function requires the sphere's radius to be set to a value greater than zero. The existing Material density value is overwritten only if the return value from this true. More...

void SetMaterial (const Material &_mat)
Set the material associated with this sphere. More...

Set the radius in meters. More...

Precision Volume () const
Get the volume of the sphere in m^3. More...

Precision VolumeBelow (const Plane< Precision > &_plane) const
Get the volume of sphere below a given plane in m^3. It is assumed that the center of the sphere is on the origin. More...

## Detailed Description

### template<typename Precision> class ignition::math::Sphere< Precision >

A representation of a sphere.

The sphere class supports defining a sphere with a radius and material properties. Radius is in meters. See Material for more on material properties.

## ◆ Sphere() [1/3]

 Sphere ( )
default

Default constructor. The default radius is zero.

## ◆ Sphere() [2/3]

 Sphere ( const Precision _radius )
explicit

Construct a sphere with a radius.

Parameters

## ◆ Sphere() [3/3]

 Sphere ( const Precision _radius, const Material & _mat )

Construct a sphere with a radius, material.

Parameters
 [in] _radius Radius of the sphere. [in] _mat Material property for the sphere.

## ◆ ~Sphere()

 ~Sphere ( )
default

Destructor.

## ◆ CenterOfVolumeBelow()

 std::optional > CenterOfVolumeBelow ( const Plane< Precision > & _plane ) const

Center of volume below the plane. This is useful for example when calculating where buoyancy should be applied.

Parameters
 [in] _plane The plane which slices this sphere, expressed in the sphere's reference frame.
Returns
The center of volume if there is anything under the plane, otherwise return a std::nullopt. Expressed in the sphere's reference frame.

## ◆ DensityFromMass()

 Precision DensityFromMass ( const Precision _mass ) const

Compute the sphere's density given a mass value. The sphere is assumed to be solid with uniform density. This function requires the sphere's radius to be set to a value greater than zero. The Material of the sphere is ignored.

Parameters
 [in] _mass Mass of the sphere, in kg. This value should be greater than zero.
Returns
Density of the sphere in kg/m^3. A negative value is returned if radius or _mass is <= 0.

## ◆ MassMatrix()

 bool MassMatrix ( MassMatrix3d & _massMat ) const

Get the mass matrix for this sphere. This function is only meaningful if the sphere's radius and material have been set.

Parameters
 [out] _massMat The computed mass matrix will be stored here.
Returns
False if computation of the mass matrix failed, which could be due to an invalid radius (<=0) or density (<=0).

## ◆ Material()

 const Material& Material ( ) const

Get the material associated with this sphere.

Returns
The material assigned to this sphere

## ◆ operator!=()

 bool operator!= ( const Sphere< Precision > & _sphere ) const

Check if this sphere is not equal to the provided sphere. Radius and material properties will be checked.

## ◆ operator==()

 bool operator== ( const Sphere< Precision > & _sphere ) const

Check if this sphere is equal to the provided sphere. Radius and material properties will be checked.

Returns
The radius of the sphere in meters.

## ◆ SetDensityFromMass()

 bool SetDensityFromMass ( const Precision _mass )

Set the density of this sphere based on a mass value. Density is computed using Precision DensityFromMass(const Precision _mass) const. The sphere is assumed to be solid with uniform density. This function requires the sphere's radius to be set to a value greater than zero. The existing Material density value is overwritten only if the return value from this true.

Parameters
 [in] _mass Mass of the sphere, in kg. This value should be greater than zero.
Returns
True if the density was set. False is returned if the sphere's radius or the _mass value are <= 0.
Precision DensityFromMass(const Precision _mass) const

## ◆ SetMaterial()

 void SetMaterial ( const Material & _mat )

Set the material associated with this sphere.

Parameters
 [in] _mat The material assigned to this sphere

Parameters

## ◆ Volume()

 Precision Volume ( ) const

Get the volume of the sphere in m^3.

Returns
Volume of the sphere in m^3.

## ◆ VolumeBelow()

 Precision VolumeBelow ( const Plane< Precision > & _plane ) const

Get the volume of sphere below a given plane in m^3. It is assumed that the center of the sphere is on the origin.

Parameters
 [in] _plane The plane which slices this sphere, expressed in the sphere's reference frame.
Returns
Volume below the sphere in m^3.

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