Gazebo Math

API Reference

8.1.0
Sphere< Precision > Class Template Reference

A representation of a sphere. More...

#include <gz/math/Sphere.hh>

Public Member Functions

 Sphere ()=default
 Default constructor. The default radius is zero.
 
 Sphere (const Precision _radius)
 Construct a sphere with a radius.
 
 Sphere (const Precision _radius, const Material &_mat)
 Construct a sphere with a radius, material.
 
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.
 
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.
 
std::optional< MassMatrix3< Precision > > MassMatrix () const
 Get the mass matrix for this sphere. This function is only meaningful if the sphere's radius and material have been set.
 
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.
 
const MaterialMaterial () const
 Get the material associated with this sphere.
 
bool operator!= (const Sphere &_sphere) const
 Check if this sphere is not equal to the provided sphere. Radius and material properties will be checked.
 
bool operator== (const Sphere &_sphere) const
 Check if this sphere is equal to the provided sphere. Radius and material properties will be checked.
 
Precision Radius () const
 Get the radius in meters.
 
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.
 
void SetMaterial (const Material &_mat)
 Set the material associated with this sphere.
 
void SetRadius (const Precision _radius)
 Set the radius in meters.
 
Precision Volume () const
 Get the volume of the sphere in m^3.
 
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.
 

Detailed Description

template<typename Precision>
class gz::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.

Constructor & Destructor Documentation

◆ Sphere() [1/3]

template<typename Precision >
Sphere ( )
default

Default constructor. The default radius is zero.

◆ Sphere() [2/3]

template<typename Precision >
Sphere ( const Precision  _radius)
explicit

Construct a sphere with a radius.

Parameters
[in]_radiusRadius of the sphere.

◆ Sphere() [3/3]

template<typename Precision >
Sphere ( const Precision  _radius,
const Material _mat 
)

Construct a sphere with a radius, material.

Parameters
[in]_radiusRadius of the sphere.
[in]_matMaterial property for the sphere.

Member Function Documentation

◆ CenterOfVolumeBelow()

template<typename Precision >
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.

Parameters
[in]_planeThe 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()

template<typename Precision >
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]_massMass 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() [1/2]

template<typename Precision >
std::optional< MassMatrix3< Precision > > MassMatrix ( ) const

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

Returns
The computed mass matrix if parameters are valid (radius > 0) and (density > 0). Otherwise std::nullopt is returned.

◆ MassMatrix() [2/2]

template<typename Precision >
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]_massMatThe 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()

template<typename Precision >
const Material & Material ( ) const

Get the material associated with this sphere.

Returns
The material assigned to this sphere

◆ operator!=()

template<typename Precision >
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==()

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

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

◆ Radius()

template<typename Precision >
Precision Radius ( ) const

Get the radius in meters.

Returns
The radius of the sphere in meters.

◆ SetDensityFromMass()

template<typename Precision >
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]_massMass 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.
See also
Precision DensityFromMass(const Precision _mass) const

◆ SetMaterial()

template<typename Precision >
void SetMaterial ( const Material _mat)

Set the material associated with this sphere.

Parameters
[in]_matThe material assigned to this sphere

◆ SetRadius()

template<typename Precision >
void SetRadius ( const Precision  _radius)

Set the radius in meters.

Parameters
[in]_radiusThe radius of the sphere in meters.

◆ Volume()

template<typename Precision >
Precision Volume ( ) const

Get the volume of the sphere in m^3.

Returns
Volume of the sphere in m^3.

◆ VolumeBelow()

template<typename Precision >
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]_planeThe 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: