Ignition Math

API Reference

5.1.0
detail/Sphere.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_MATH_DETAIL_SPHERE_HH_
18 #define IGNITION_MATH_DETAIL_SPHERE_HH_
19 
20 #include "ignition/math/Sphere.hh"
21 
22 namespace ignition
23 {
24 namespace math
25 {
27 template<typename T>
28 Sphere<T>::Sphere(const T _radius)
29 {
30  this->radius = _radius;
31 }
32 
34 template<typename T>
35 Sphere<T>::Sphere(const T _radius, const ignition::math::Material &_mat)
36 {
37  this->radius = _radius;
38  this->material = _mat;
39 }
40 
42 template<typename T>
44 {
45  return this->radius;
46 }
47 
49 template<typename T>
50 void Sphere<T>::SetRadius(const T _radius)
51 {
52  this->radius = _radius;
53 }
54 
56 template<typename T>
58 {
59  return this->material;
60 }
61 
63 template<typename T>
65 {
66  this->material = _mat;
67 }
68 
70 template<typename T>
71 bool Sphere<T>::operator==(const Sphere &_sphere) const
72 {
73  return equal(this->radius, _sphere.Radius()) &&
74  this->material == _sphere.Material();
75 }
76 
78 template<typename T>
79 bool Sphere<T>::operator!=(const Sphere &_sphere) const
80 {
81  return !(*this == _sphere);
82 }
83 
85 template<typename T>
86 bool Sphere<T>::MassMatrix(MassMatrix3d &_massMat) const
87 {
88  return _massMat.SetFromSphere(this->material, this->radius);
89 }
90 
92 template<typename T>
94 {
95  return (4.0/3.0) * IGN_PI * std::pow(this->radius, 3);
96 }
97 
99 template<typename T>
100 bool Sphere<T>::SetDensityFromMass(const T _mass)
101 {
102  T newDensity = this->DensityFromMass(_mass);
103  if (newDensity > 0)
104  this->material.SetDensity(newDensity);
105  return newDensity > 0;
106 }
107 
109 template<typename T>
110 T Sphere<T>::DensityFromMass(const T _mass) const
111 {
112  if (this->radius <= 0 || _mass <= 0)
113  return -1.0;
114 
115  return _mass / this->Volume();
116 }
117 }
118 }
119 #endif
bool operator==(const Sphere &_sphere) const
Check if this sphere is equal to the provided sphere. Radius and material properties will be checked...
Definition: detail/Sphere.hh:71
A class for inertial information about a rigid body consisting of the scalar mass and a 3x3 symmetric...
Definition: MassMatrix3.hh:45
void SetRadius(const Precision _radius)
Set the radius in meters.
Definition: detail/Sphere.hh:50
bool MassMatrix(MassMatrix3d &_massMat) const
Get the mass matrix for this sphere. This function is only meaningful if the sphere&#39;s radius and mate...
Definition: detail/Sphere.hh:86
void SetMaterial(const Material &_mat)
Set the material associated with this sphere.
Definition: detail/Sphere.hh:64
bool equal(const T &_a, const T &_b, const T &_epsilon=T(1e-6))
check if two values are equal, within a tolerance
Definition: Helpers.hh:552
Sphere()=default
Default constructor. The default radius is zero.
Contains information about a single material.
Definition: Material.hh:65
bool SetFromSphere(const Material &_mat, const T _radius)
Set inertial properties based on a material and equivalent sphere.
Definition: MassMatrix3.hh:1192
A representation of a sphere.
Definition: Sphere.hh:41
Precision Volume() const
Get the volume of the sphere in m^3.
Definition: detail/Sphere.hh:93
Precision Radius() const
Get the radius in meters.
Definition: detail/Sphere.hh:43
Precision DensityFromMass(const Precision _mass) const
Compute the sphere&#39;s density given a mass value. The sphere is assumed to be solid with uniform densi...
Definition: detail/Sphere.hh:110
T pow(T... args)
bool operator!=(const Sphere &_sphere) const
Check if this sphere is not equal to the provided sphere. Radius and material properties will be chec...
Definition: detail/Sphere.hh:79
bool SetDensityFromMass(const Precision _mass)
Set the density of this sphere based on a mass value. Density is computed using Precision DensityFrom...
Definition: detail/Sphere.hh:100
Definition: Angle.hh:39
const Material & Material() const
Get the material associated with this sphere.
Definition: detail/Sphere.hh:57
#define IGN_PI
Define IGN_PI, IGN_PI_2, and IGN_PI_4. This was put here for Windows support.
Definition: Helpers.hh:180