Gazebo Math

API Reference

6.15.1
gz/math/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 GZ_MATH_BOX_HH_
18 #define GZ_MATH_BOX_HH_
19 
20 #include <gz/math/config.hh>
21 #include <gz/math/MassMatrix3.hh>
22 #include <gz/math/Material.hh>
23 #include <gz/math/Plane.hh>
24 #include <gz/math/Vector3.hh>
25 
26 #include "gz/math/detail/WellOrderedVector.hh"
27 
28 #include <set>
29 
30 namespace ignition
31 {
32  namespace math
33  {
34  // Inline bracket to help doxygen filtering.
35  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
38  template<typename T>
39  using IntersectionPoints = std::set<Vector3<T>, WellOrderedVectors<T>>;
40 
50  template<typename Precision>
51  class Box
52  {
54  public: Box() = default;
55 
60  public: Box(const Precision _length,
61  const Precision _width,
62  const Precision _height);
63 
69  public: Box(const Precision _length, const Precision _width,
70  const Precision _height,
71  const gz::math::Material &_mat);
72 
80  public: explicit Box(const Vector3<Precision> &_size);
81 
91  public: Box(const Vector3<Precision> &_size,
92  const gz::math::Material &_mat);
93 
95  public: virtual ~Box() = default;
96 
99  public: math::Vector3<Precision> Size() const;
100 
108  public: void SetSize(const math::Vector3<Precision> &_size);
109 
114  public: void SetSize(const Precision _length,
115  const Precision _width,
116  const Precision _height);
117 
121  public: bool operator==(const Box<Precision> &_b) const;
122 
126  public: bool operator!=(const Box<Precision> &_b) const;
127 
130  public: const gz::math::Material &Material() const;
131 
134  public: void SetMaterial(const gz::math::Material &_mat);
135 
138  public: Precision Volume() const;
139 
144  public: Precision VolumeBelow(const Plane<Precision> &_plane) const;
145 
151  public: std::optional<Vector3<Precision>>
152  CenterOfVolumeBelow(const Plane<Precision> &_plane) const;
153 
160  VerticesBelow(const Plane<Precision> &_plane) const;
161 
170  public: Precision DensityFromMass(const Precision _mass) const;
171 
184  public: bool SetDensityFromMass(const Precision _mass);
185 
193  public: bool MassMatrix(MassMatrix3<Precision> &_massMat) const;
194 
200  public: IntersectionPoints<Precision> Intersections(
201  const Plane<Precision> &_plane) const;
202 
205 
207  private: gz::math::Material material;
208  };
209 
212  typedef Box<int> Boxi;
213 
216  typedef Box<double> Boxd;
217 
220  typedef Box<float> Boxf;
221  }
222  }
223 }
224 #include "gz/math/detail/Box.hh"
225 #endif
void SetMaterial(const Material &_mat)
Set the material associated with this box.
virtual ~Box()=default
Destructor.
std::optional< Vector3< Precision > > CenterOfVolumeBelow(const Plane< Precision > &_plane) const
Center of volume below the plane. This is useful when calculating where buoyancy should be applied,...
Definition: gz/math/AdditivelySeparableScalarField3.hh:27
bool MassMatrix(MassMatrix3< Precision > &_massMat) const
Get the mass matrix for this box. This function is only meaningful if the box's size and material hav...
void SetSize(const math::Vector3< Precision > &_size)
Set the size of the box.
const Material & Material() const
Get the material associated with this box.
Box< double > Boxd
Box with double precision.
Definition: gz/math/Box.hh:216
bool operator==(const Box< Precision > &_b) const
Equality test operator.
A plane and related functions.
Definition: gz/math/Plane.hh:38
Contains information about a single material.
Definition: gz/math/Material.hh:65
Box< int > Boxi
Box with integer precision.
Definition: gz/math/Box.hh:212
Box()=default
Default constructor.
math::Vector3< Precision > Size() const
Get the size of the box.
IntersectionPoints< Precision > VerticesBelow(const Plane< Precision > &_plane) const
All the vertices which are on or below the plane.
IntersectionPoints< Precision > Intersections(const Plane< Precision > &_plane) const
Get intersection between a plane and the box's edges. Edges contained on the plane are ignored.
bool operator!=(const Box< Precision > &_b) const
Inequality test operator.
Precision VolumeBelow(const Plane< Precision > &_plane) const
Get the volume of the box below a plane.
bool SetDensityFromMass(const Precision _mass)
Set the density of this box based on a mass value. Density is computed using double DensityFromMass(c...
Precision Volume() const
Get the volume of the box in m^3.
Precision DensityFromMass(const Precision _mass) const
Compute the box's density given a mass value. The box is assumed to be solid with uniform density....
Box< float > Boxf
Box with float precision.
Definition: gz/math/Box.hh:220
A representation of a box. All units are in meters.
Definition: gz/math/Box.hh:51
STL class.
A class for inertial information about a rigid body consisting of the scalar mass and a 3x3 symmetric...
Definition: gz/math/MassMatrix3.hh:45