Collision Checker
line_segment.h
Go to the documentation of this file.
1 #ifndef CPP_COLLISION_LINE_SEGMENT_H_
2 #define CPP_COLLISION_LINE_SEGMENT_H_
3 
4 #include <Eigen/Dense>
5 #include <vector>
7 
8 namespace collision
9 
10 {
11 
12 class LineSegment {
13  public:
14  LineSegment(const Eigen::Vector2d &point1, const Eigen::Vector2d &point2) {
15  point1_.x = point1[0];
16  point1_.y = point1[1];
17  point2_.x = point2[0];
18  point2_.y = point2[1];
19  }
21  point1_ = point1;
22  point2_ = point2;
23  }
24  LineSegment(const LineSegment &ls2) {
25  point1_ = ls2.point1_;
26  point2_ = ls2.point2_;
27  }
28  raytrace::Point point1() const { return point1_; }
29 
30  raytrace::Point point2() const { return point2_; }
31 
32  void set_point_1(const raytrace::Point &point1) { point1_ = point1; }
33 
34  void set_point_2(const raytrace::Point &point2) { point2_ = point2; }
35 
36  void swap(void) {
37  raytrace::Point point3 = point2_;
38  point2_ = point1_;
39  point1_ = point3;
40  }
41 
42  bool intersect(LineSegment segment2,
43  std::vector<Eigen::Vector2d> &inters) const {
44  std::vector<raytrace::Point> inters1;
45  bool res =
46  raytrace::doIntersect(this->point1_, this->point2_, segment2.point1_,
47  segment2.point2_, inters1);
48  for (auto &el : inters1) {
49  Eigen::Vector2d v2(el.x, el.y);
50  inters.push_back(v2);
51  }
52 
53  return res;
54  }
55 
56  private:
57  raytrace::Point point1_;
58  raytrace::Point point2_;
59 };
60 
61 } // namespace collision
62 
63 #endif /* CPP_COLLISION_LINE_SEGMENT_H_ */
void set_point_2(const raytrace::Point &point2)
Definition: line_segment.h:34
raytrace::Point point2() const
Definition: line_segment.h:30
LineSegment(const Eigen::Vector2d &point1, const Eigen::Vector2d &point2)
Definition: line_segment.h:14
bool doIntersect(Point p1, Point q1, Point p2, Point q2, std::vector< Point > &inters)
LineSegment(const LineSegment &ls2)
Definition: line_segment.h:24
raytrace::Point point1() const
Definition: line_segment.h:28
void set_point_1(const raytrace::Point &point1)
Definition: line_segment.h:32
LineSegment(raytrace::Point point1, raytrace::Point point2)
Definition: line_segment.h:20
bool intersect(LineSegment segment2, std::vector< Eigen::Vector2d > &inters) const
Definition: line_segment.h:42