|
20 | 20 | #include <ignition/math/config.hh>
|
21 | 21 | #include <ignition/math/MassMatrix3.hh>
|
22 | 22 | #include <ignition/math/Material.hh>
|
| 23 | +#include <ignition/math/Plane.hh> |
23 | 24 | #include <ignition/math/Vector3.hh>
|
24 | 25 |
|
| 26 | +#include "ignition/math/detail/WellOrderedVector.hh" |
| 27 | + |
| 28 | +#include <set> |
| 29 | + |
25 | 30 | namespace ignition
|
26 | 31 | {
|
27 | 32 | namespace math
|
28 | 33 | {
|
29 | 34 | // Inline bracket to help doxygen filtering.
|
30 | 35 | inline namespace IGNITION_MATH_VERSION_NAMESPACE {
|
31 |
| - // |
| 36 | + /// \brief This is the type used for deduplicating and returning the set of |
| 37 | + /// intersections. |
| 38 | + template<typename T> |
| 39 | + using IntersectionPoints = std::set<Vector3<T>, WellOrderedVectors<T>>; |
| 40 | + |
32 | 41 | /// \class Box Box.hh ignition/math/Box.hh
|
33 | 42 | /// \brief A representation of a box. All units are in meters.
|
34 | 43 | ///
|
@@ -128,6 +137,28 @@ namespace ignition
|
128 | 137 | /// \return Volume of the box in m^3.
|
129 | 138 | public: Precision Volume() const;
|
130 | 139 |
|
| 140 | + /// \brief Get the volume of the box below a plane. |
| 141 | + /// \param[in] _plane The plane which cuts the box, expressed in the box's |
| 142 | + /// frame. |
| 143 | + /// \return Volume below the plane in m^3. |
| 144 | + public: Precision VolumeBelow(const Plane<Precision> &_plane) const; |
| 145 | + |
| 146 | + /// \brief Center of volume below the plane. This is useful when |
| 147 | + /// calculating where buoyancy should be applied, for example. |
| 148 | + /// \param[in] _plane The plane which cuts the box, expressed in the box's |
| 149 | + /// frame. |
| 150 | + /// \return Center of volume, in box's frame. |
| 151 | + public: std::optional<Vector3<Precision>> |
| 152 | + CenterOfVolumeBelow(const Plane<Precision> &_plane) const; |
| 153 | + |
| 154 | + /// \brief All the vertices which are on or below the plane. |
| 155 | + /// \param[in] _plane The plane which cuts the box, expressed in the box's |
| 156 | + /// frame. |
| 157 | + /// \return Box vertices which are below the plane, expressed in the box's |
| 158 | + /// frame. |
| 159 | + public: IntersectionPoints<Precision> |
| 160 | + VerticesBelow(const Plane<Precision> &_plane) const; |
| 161 | + |
131 | 162 | /// \brief Compute the box's density given a mass value. The
|
132 | 163 | /// box is assumed to be solid with uniform density. This
|
133 | 164 | /// function requires the box's size to be set to
|
@@ -161,6 +192,14 @@ namespace ignition
|
161 | 192 | /// could be due to an invalid size (<=0) or density (<=0).
|
162 | 193 | public: bool MassMatrix(MassMatrix3<Precision> &_massMat) const;
|
163 | 194 |
|
| 195 | + /// \brief Get intersection between a plane and the box's edges. |
| 196 | + /// Edges contained on the plane are ignored. |
| 197 | + /// \param[in] _plane The plane against which we are testing intersection. |
| 198 | + /// \returns A list of points along the edges of the box where the |
| 199 | + /// intersection occurs. |
| 200 | + public: IntersectionPoints<Precision> Intersections( |
| 201 | + const Plane<Precision> &_plane) const; |
| 202 | + |
164 | 203 | /// \brief Size of the box.
|
165 | 204 | private: Vector3<Precision> size = Vector3<Precision>::Zero;
|
166 | 205 |
|
|
0 commit comments