Gazebo Math

API Reference

6.17.0
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 
56  template<typename Precision>
57  class Box
58  {
60  public: Box() = default;
61 
66  public: Box(const Precision _length,
67  const Precision _width,
68  const Precision _height);
69 
75  public: Box(const Precision _length, const Precision _width,
76  const Precision _height,
77  const gz::math::Material &_mat);
78 
86  public: explicit Box(const Vector3<Precision> &_size);
87 
97  public: Box(const Vector3<Precision> &_size,
98  const gz::math::Material &_mat);
99 
101  public: virtual ~Box() = default;
102 
106 
114  public: void SetSize(const math::Vector3<Precision> &_size);
115 
120  public: void SetSize(const Precision _length,
121  const Precision _width,
122  const Precision _height);
123 
127  public: bool operator==(const Box<Precision> &_b) const;
128 
132  public: bool operator!=(const Box<Precision> &_b) const;
133 
136  public: const gz::math::Material &Material() const;
137 
140  public: void SetMaterial(const gz::math::Material &_mat);
141 
144  public: Precision Volume() const;
145 
150  public: Precision VolumeBelow(const Plane<Precision> &_plane) const;
151 
157  public: std::optional<Vector3<Precision>>
158  CenterOfVolumeBelow(const Plane<Precision> &_plane) const;
159 
166  VerticesBelow(const Plane<Precision> &_plane) const;
167 
172  public: Vector3<Precision> Centroid() const;
173 
182  public: Precision DensityFromMass(const Precision _mass) const;
183 
196  public: bool SetDensityFromMass(const Precision _mass);
197 
205  public: bool MassMatrix(MassMatrix3<Precision> &_massMat) const;
206 
213  const Plane<Precision> &_plane) const;
214 
217 
219  private: gz::math::Material material;
220  };
221 
224  typedef Box<int> Boxi;
225 
228  typedef Box<double> Boxd;
229 
232  typedef Box<float> Boxf;
233  }
234  }
235 }
236 #include "gz/math/detail/Box.hh"
237 #endif
A representation of a box. All units are in meters.
Definition: gz/math/Box.hh:58
void SetMaterial(const Material &_mat)
Set the material associated with this box.
Box(const Precision _length, const Precision _width, const Precision _height)
Construct a box with specified dimensions.
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,...
bool SetDensityFromMass(const Precision _mass)
Set the density of this box based on a mass value. Density is computed using double DensityFromMass(c...
Box(const Vector3< Precision > &_size, const Material &_mat)
Construct a box with specified dimensions, in vector form and a material.
bool operator!=(const Box< Precision > &_b) const
Inequality test operator.
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....
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.
bool operator==(const Box< Precision > &_b) const
Equality test operator.
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...
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.
void SetSize(const Precision _length, const Precision _width, const Precision _height)
Set the size of the box.
Box(const Vector3< Precision > &_size)
Construct a box with specified dimensions, in vector form.
void SetSize(const math::Vector3< Precision > &_size)
Set the size of the box.
virtual ~Box()=default
Destructor.
Precision VolumeBelow(const Plane< Precision > &_plane) const
Get the volume of the box below a plane.
Box()=default
Default constructor.
Precision Volume() const
Get the volume of the box in m^3.
const Material & Material() const
Get the material associated with this box.
Box(const Precision _length, const Precision _width, const Precision _height, const Material &_mat)
Construct a box with specified dimensions and a material.
Vector3< Precision > Centroid() const
Get the centroid of the box. It coincides with the origin of the reference frame defined in the class...
A class for inertial information about a rigid body consisting of the scalar mass and a 3x3 symmetric...
Definition: gz/math/MassMatrix3.hh:46
A plane and related functions.
Definition: gz/math/Plane.hh:39
Box< float > Boxf
Box with float precision.
Definition: gz/math/Box.hh:232
Box< double > Boxd
Box with double precision.
Definition: gz/math/Box.hh:228
Box< int > Boxi
Box with integer precision.
Definition: gz/math/Box.hh:224
Definition: gz/math/AdditivelySeparableScalarField3.hh:28