Collision Checker
rectangle_aabb.h
Go to the documentation of this file.
1 #ifndef RECTANGLE_AABB_H_
2 #define RECTANGLE_AABB_H_
3 
4 #include <Eigen/Dense>
5 #include <iostream>
6 
7 #include <vector>
8 
10 
11 #include "collision/line_segment.h"
12 
13 namespace collision {
18 class RectangleAABB : public Shape {
19  public:
20  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
21 
22  RectangleAABB(double _rx, double _ry,
23  const Eigen::Vector2d &_center = Eigen::Vector2d(0, 0))
24  : Shape(_center), r_(_rx, _ry) {
25  min_ = center_ - r_;
26  max_ = center_ + r_;
27 
28  segments_.push_back(LineSegment(min_, Eigen::Vector2d(min_.x(), max_.y())));
29 
30  segments_.push_back(LineSegment(Eigen::Vector2d(min_.x(), max_.y()), max_));
31 
32  segments_.push_back(LineSegment(max_, Eigen::Vector2d(max_.x(), min_.y())));
33 
34  segments_.push_back(LineSegment(Eigen::Vector2d(max_.x(), min_.y()), min_));
35  }
36 
37  bool rayTrace(const Eigen::Vector2d &point1, const Eigen::Vector2d &point2,
38  std::vector<LineSegment> &intersect) const override;
39 
41 
42 #if ENABLE_SERIALIZER
43  serialize::ICollisionObjectExport *exportThis(void) const override;
44 #endif
45  RectangleAABB(const RectangleAABB &copy);
46  RectangleAABB *clone() const;
47 
48  void print(std::ostringstream &stream) const;
49 
50  virtual CollisionObjectType getCollisionObjectType() const override {
52  }
53 
54  ShapeType type() const;
55 
56  Eigen::Vector2d r() const;
57  double r(int i) const;
58  double r_x() const;
59  double r_y() const;
60  Eigen::Vector2d min() const;
61  Eigen::Vector2d max() const;
62 
64  void) const override;
66  const std::shared_ptr<fcl::CollisionGeometry<FCL_PRECISION>> &col_geom)
67  const override;
68 
69  void set_center(const Eigen::Vector2d &_center);
70  void set_r(const Eigen::Vector2d &_r);
71  void set_r_x(double _r_x);
72  void set_r_y(double _r_y);
73  void set_all(double r_x, double r_y, double center_x, double center_y);
74 
75  //
76  // @brief Computes the square distance between a point and
77  // the rectangle boundary. From:
78  // C. Ericson, Real-Time Collision Detection, pp. 131, 2004
79  // @param p Point
80  //
81  double squareDisToPoint(const Eigen::Vector2d &p) const;
82 
83  std::vector<LineSegment> segments(void) const { return segments_; };
84 
85  private:
86  // Center-radius representation
87  // ----------- max
88  // | |ry |
89  // | c|____|
90  // | ry |
91  // | |
92  // -----------
93  // min
94  //
95  using Shape::center_;
96  using Shape::radius_;
97 
99  Eigen::Vector2d r_;
100 
102  Eigen::Vector2d min_;
103  Eigen::Vector2d max_;
104 
105  std::vector<LineSegment> segments_;
106 
107  static constexpr ShapeType type_ = TYPE_RECTANGLE_AABB;
108 };
109 
110 } // namespace collision
111 
112 #endif
double radius_
Definition: shape.h:73
void set_r(const Eigen::Vector2d &_r)
double squareDisToPoint(const Eigen::Vector2d &p) const
Eigen::Vector2d r() const
void print(std::ostringstream &stream) const
Print all parameters of the shape.
bool rayTrace(const Eigen::Vector2d &point1, const Eigen::Vector2d &point2, std::vector< LineSegment > &intersect) const override
RectangleAABB * clone() const
fcl::CollisionObject< FCL_PRECISION > * createFCLCollisionObject(const std::shared_ptr< fcl::CollisionGeometry< FCL_PRECISION >> &col_geom) const override
Eigen::Vector2d min() const
fcl::CollisionGeometry< FCL_PRECISION > * createFCLCollisionGeometry(void) const override
void set_r_x(double _r_x)
void set_r_y(double _r_y)
ShapeType type() const
Get shape type.
virtual CollisionObjectType getCollisionObjectType() const override
void set_all(double r_x, double r_y, double center_x, double center_y)
Axis-aligned rectangle.
ShapeType
Definition: shape.h:13
EIGEN_MAKE_ALIGNED_OPERATOR_NEW RectangleAABB(double _rx, double _ry, const Eigen::Vector2d &_center=Eigen::Vector2d(0, 0))
Base prototype for the shape of an obstacle.
Definition: shape.h:25
double center_x() const
Definition: shape.cc:18
std::vector< LineSegment > segments(void) const
double center_y() const
Definition: shape.cc:20
Eigen::Vector2d center_
Definition: shape.h:72
Eigen::Vector2d max() const
void set_center(const Eigen::Vector2d &_center)