Ignition Math

API Reference

6.9.2
AxisAlignedBox.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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_AXISALIGNEDBOX_HH_
18 #define IGNITION_MATH_AXISALIGNEDBOX_HH_
19 
20 #include <iostream>
21 #include <tuple>
22 #include <ignition/math/config.hh>
23 #include <ignition/math/Helpers.hh>
24 #include <ignition/math/Line3.hh>
27 #include <ignition/math/Vector3.hh>
28 
29 namespace ignition
30 {
31  namespace math
32  {
33  // Inline bracket to help doxygen filtering.
34  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
35  //
36  // Forward declaration of private data
37  class AxisAlignedBoxPrivate;
38 
42  class IGNITION_MATH_VISIBLE AxisAlignedBox
43  {
50  public: AxisAlignedBox();
51 
56  public: AxisAlignedBox(const Vector3d &_vec1, const Vector3d &_vec2);
57 
66  public: AxisAlignedBox(double _vec1X, double _vec1Y, double _vec1Z,
67  double _vec2X, double _vec2Y, double _vec2Z);
68 
71  public: AxisAlignedBox(const AxisAlignedBox &_b);
72 
74  public: virtual ~AxisAlignedBox();
75 
78  public: double XLength() const;
79 
82  public: double YLength() const;
83 
86  public: double ZLength() const;
87 
90  public: math::Vector3d Size() const;
91 
94  public: math::Vector3d Center() const;
95 
98  public: void Merge(const AxisAlignedBox &_box);
99 
104 
108  public: AxisAlignedBox operator+(const AxisAlignedBox &_b) const;
109 
113  public: const AxisAlignedBox &operator+=(const AxisAlignedBox &_b);
114 
118  public: bool operator==(const AxisAlignedBox &_b) const;
119 
123  public: bool operator!=(const AxisAlignedBox &_b) const;
124 
128  public: AxisAlignedBox operator-(const Vector3d &_v);
129 
133  public: AxisAlignedBox operator+(const Vector3d &_v);
134 
139  public: friend std::ostream &operator<<(std::ostream &_out,
141  {
142  _out << "Min[" << _b.Min() << "] Max[" << _b.Max() << "]";
143  return _out;
144  }
145 
148  public: const Vector3d &Min() const;
149 
152  public: const Vector3d &Max() const;
153 
156  public: Vector3d &Min();
157 
160  public: Vector3d &Max();
161 
168  public: bool Intersects(const AxisAlignedBox &_box) const;
169 
173  public: bool Contains(const Vector3d &_p) const;
174 
181  public: bool IntersectCheck(const Vector3d &_origin, const Vector3d &_dir,
182  const double _min, const double _max) const;
183 
200  const Vector3d &_origin, const Vector3d &_dir,
201  const double _min, const double _max) const;
202 
221  const Vector3d &_origin, const Vector3d &_dir,
222  const double _min, const double _max) const;
223 
233  const Line3d &_line) const;
234 
237  public: double Volume() const;
238 
247  public: double DensityFromMass(const double _mass) const;
248 
261  public: bool SetDensityFromMass(const double _mass);
262 
265  public: const ignition::math::Material &Material() const;
266 
269  public: void SetMaterial(const ignition::math::Material &_mat);
270 
278  public: bool MassMatrix(MassMatrix3d &_massMat) const;
279 
286  private: bool ClipLine(const int _d, const Line3d &_line,
287  double &_low, double &_high) const;
288 
290  private: AxisAlignedBoxPrivate *dataPtr;
291  };
292  }
293  }
294 }
295 #endif
Mathematical representation of a box that is aligned along an X,Y,Z axis.
Definition: AxisAlignedBox.hh:43
bool IntersectCheck(const Vector3d &_origin, const Vector3d &_dir, const double _min, const double _max) const
Check if a ray (origin, direction) intersects the box.
AxisAlignedBox operator+(const AxisAlignedBox &_b) const
Addition operator. result = this + _b.
void SetMaterial(const Material &_mat)
Set the material associated with this box.
std::tuple< bool, double > IntersectDist(const Vector3d &_origin, const Vector3d &_dir, const double _min, const double _max) const
Check if a ray (origin, direction) intersects the box.
const AxisAlignedBox & operator+=(const AxisAlignedBox &_b)
Addition set operator. this = this + _b.
math::Vector3d Size() const
Get the size of the box.
AxisAlignedBox operator-(const Vector3d &_v)
Subtract a vector from the min and max values.
AxisAlignedBox()
Default constructor. This constructor will set the box's minimum and maximum corners to the highest (...
void Merge(const AxisAlignedBox &_box)
Merge a box with this box.
bool MassMatrix(MassMatrix3d &_massMat) const
Get the mass matrix for this box. This function is only meaningful if the box's size and material hav...
AxisAlignedBox operator+(const Vector3d &_v)
Add a vector to the min and max values.
math::Vector3d Center() const
Get the box center.
Vector3d & Max()
Get a mutable version of the maximum corner.
double Volume() const
Get the volume of the box in m^3.
double ZLength() const
Get the length along the z dimension.
bool Intersects(const AxisAlignedBox &_box) const
Test box intersection. This test will only work if both box's minimum corner is less than or equal to...
double YLength() const
Get the length along the y dimension.
double XLength() const
Get the length along the x dimension.
std::tuple< bool, double, Vector3d > Intersect(const Vector3d &_origin, const Vector3d &_dir, const double _min, const double _max) const
Check if a ray (origin, direction) intersects the box.
const Vector3d & Max() const
Get the maximum corner.
bool Contains(const Vector3d &_p) const
Check if a point lies inside the box.
bool operator==(const AxisAlignedBox &_b) const
Equality test operator.
bool SetDensityFromMass(const double _mass)
Set the density of this box based on a mass value. Density is computed using double DensityFromMass(c...
std::tuple< bool, double, Vector3d > Intersect(const Line3d &_line) const
Check if a line intersects the box.
AxisAlignedBox(double _vec1X, double _vec1Y, double _vec1Z, double _vec2X, double _vec2Y, double _vec2Z)
Constructor. This constructor will compute the box's minimum and maximum corners based on the argumen...
virtual ~AxisAlignedBox()
Destructor.
AxisAlignedBox & operator=(const AxisAlignedBox &_b)
Assignment operator. Set this box to the parameter.
AxisAlignedBox(const AxisAlignedBox &_b)
Copy Constructor.
Vector3d & Min()
Get a mutable version of the minimum corner.
friend std::ostream & operator<<(std::ostream &_out, const AxisAlignedBox &_b)
Output operator.
Definition: AxisAlignedBox.hh:139
double DensityFromMass(const double _mass) const
Compute the cylinder's density given a mass value. The cylinder is assumed to be solid with uniform d...
bool operator!=(const AxisAlignedBox &_b) const
Inequality test operator.
const Material & Material() const
Get the material associated with this box.
AxisAlignedBox(const Vector3d &_vec1, const Vector3d &_vec2)
Constructor. This constructor will compute the box's minimum and maximum corners based on the two arg...
const Vector3d & Min() const
Get the minimum corner.
A three dimensional line segment. The line is defined by a start and end point.
Definition: Line3.hh:36
A class for inertial information about a rigid body consisting of the scalar mass and a 3x3 symmetric...
Definition: MassMatrix3.hh:46
Contains information about a single material.
Definition: Material.hh:66
The Vector3 class represents the generic vector containing 3 elements. Since it's commonly used to ke...
Definition: Vector3.hh:42
Definition: Angle.hh:43