Ignition Math

API Reference

5.1.0
detail/Box.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_BOX_HH_
18 #define IGNITION_MATH_DETAIL_BOX_HH_
19 namespace ignition
20 {
21 namespace math
22 {
24 template<typename T>
25 Box<T>::Box(T _length, T _width, T _height)
26 {
27  this->size.X(_length);
28  this->size.Y(_width);
29  this->size.Z(_height);
30 }
31 
33 template<typename T>
34 Box<T>::Box(T _length, T _width, T _height,
35  const ignition::math::Material &_mat)
36 {
37  this->size.X(_length);
38  this->size.Y(_width);
39  this->size.Z(_height);
40  this->material = _mat;
41 }
42 
44 template<typename T>
45 Box<T>::Box(const Vector3<T> &_size)
46 {
47  this->size = _size;
48 }
49 
51 template<typename T>
52 Box<T>::Box(const Vector3<T> &_size, const ignition::math::Material &_mat)
53 {
54  this->size = _size;
55  this->material = _mat;
56 }
57 
59 template<typename T>
61 {
62  return this->size;
63 }
64 
66 template<typename T>
67 void Box<T>::SetSize(T _length, T _width, T _height)
68 {
69  this->size.X(_length);
70  this->size.Y(_width);
71  this->size.Z(_height);
72 }
73 
75 template<typename T>
76 void Box<T>::SetSize(const math::Vector3<T> &_size)
77 {
78  this->size = _size;
79 }
80 
82 template<typename T>
84 {
85  return this->material;
86 }
87 
89 template<typename T>
91 {
92  this->material = _mat;
93 }
94 
96 template<typename T>
97 bool Box<T>::operator==(const Box<T> &_b) const
98 {
99  return this->size == _b.size && this->material == _b.material;
100 }
101 
103 template<typename T>
104 bool Box<T>::operator!=(const Box<T> &_b) const
105 {
106  return !(*this == _b);
107 }
108 
110 template<typename T>
111 T Box<T>::Volume() const
112 {
113  return this->size.X() * this->size.Y() * this->size.Z();
114 }
115 
117 template<typename T>
118 T Box<T>::DensityFromMass(const T _mass) const
119 {
120  if (this->size.Min() <= 0|| _mass <= 0)
121  return -1.0;
122 
123  return _mass / this->Volume();
124 }
125 
127 template<typename T>
128 bool Box<T>::SetDensityFromMass(const T _mass)
129 {
130  T newDensity = this->DensityFromMass(_mass);
131  if (newDensity > 0)
132  this->material.SetDensity(newDensity);
133  return newDensity > 0;
134 }
135 
137 template<typename T>
138 bool Box<T>::MassMatrix(MassMatrix3<T> &_massMat) const
139 {
140  return _massMat.SetFromBox(this->material, this->size);
141 }
142 }
143 }
144 #endif
void SetSize(const math::Vector3< Precision > &_size)
Set the size of the box.
Precision Volume() const
Get the volume of the box in m^3.
Definition: detail/Box.hh:111
bool operator!=(const Box< Precision > &_b) const
Inequality test operator.
Definition: detail/Box.hh:104
math::Vector3< Precision > Size() const
Get the size of the box.
Definition: detail/Box.hh:60
A class for inertial information about a rigid body consisting of the scalar mass and a 3x3 symmetric...
Definition: MassMatrix3.hh:45
void SetMaterial(const Material &_mat)
Set the material associated with this box.
Definition: detail/Box.hh:90
Contains information about a single material.
Definition: Material.hh:65
bool operator==(const Box< Precision > &_b) const
Equality test operator.
Definition: detail/Box.hh:97
Precision DensityFromMass(const Precision _mass) const
Compute the box&#39;s density given a mass value. The box is assumed to be solid with uniform density...
Definition: detail/Box.hh:118
A representation of a box. All units are in meters.
Definition: Box.hh:42
Box()=default
Default constructor.
The Vector3 class represents the generic vector containing 3 elements. Since it&#39;s commonly used to ke...
Definition: Vector3.hh:40
bool SetFromBox(const Material &_mat, const Vector3< T > &_size, const Quaternion< T > &_rot=Quaternion< T >::Identity)
Set inertial properties based on a Material and equivalent box.
Definition: MassMatrix3.hh:1055
bool SetDensityFromMass(const Precision _mass)
Set the density of this box based on a mass value. Density is computed using double DensityFromMass(c...
Definition: detail/Box.hh:128
Definition: Angle.hh:39
bool MassMatrix(MassMatrix3< Precision > &_massMat) const
Get the mass matrix for this box. This function is only meaningful if the box&#39;s size and material hav...
Definition: detail/Box.hh:138
const Material & Material() const
Get the material associated with this box.
Definition: detail/Box.hh:83