]> rtime.felk.cvut.cz Git - hubacji1/rrts.git/blob - src/rrtext2.cc
Implement ext2 collision procedures
[hubacji1/rrts.git] / src / rrtext2.cc
1 #include "rrtext.h"
2 #define CUTE_C2_IMPLEMENTATION
3 #include "cute_c2.h"
4
5 void RRTExt2::init()
6 {
7         BicycleCar bc;
8         this->c2_bc().count = 4;
9         this->c2_bc().verts[0].x = bc.lfx();
10         this->c2_bc().verts[0].y = bc.lfy();
11         this->c2_bc().verts[1].x = bc.lrx();
12         this->c2_bc().verts[1].y = bc.lry();
13         this->c2_bc().verts[2].x = bc.rrx();
14         this->c2_bc().verts[2].y = bc.rry();
15         this->c2_bc().verts[3].x = bc.rfx();
16         this->c2_bc().verts[3].y = bc.rfy();
17
18         for (auto o: this->obstacles()) {
19                 c2Poly c2tmp;
20                 c2tmp.count = (o.poly().size() < C2_MAX_POLYGON_VERTS)
21                         ? o.poly().size()
22                         : C2_MAX_POLYGON_VERTS
23                 ;
24                 int i = 0;
25                 for (auto c: o.poly()) {
26                         if (i < C2_MAX_POLYGON_VERTS) {
27                                 c2tmp.verts[i].x = std::get<0>(c);
28                                 c2tmp.verts[i].y = std::get<1>(c);
29                         }
30                         i++;
31                 }
32                 this->c2_obstacles().push_back(c2tmp);
33         }
34 }
35
36 void RRTExt2::deinit()
37 {
38 }
39
40 std::tuple<bool, unsigned int, unsigned int>
41 RRTExt2::collide_steered_from(RRTNode &f)
42 {
43         this->c2x_bc().p.x = f.x();
44         this->c2x_bc().p.y = f.y();
45         this->c2x_bc().r.c = cos(f.h());
46         this->c2x_bc().r.s = sin(f.h());
47         for (auto &o: this->c2_obstacles()) {
48                 if (c2PolytoPoly(
49                         &this->c2_bc(), &this->c2x_bc(),
50                         &o, NULL
51                 )) {
52                         return std::make_tuple(true, 0, 0);
53                 }
54         }
55         for (auto &n: this->steered()) {
56                 this->c2x_bc().p.x = n.x();
57                 this->c2x_bc().p.y = n.y();
58                 this->c2x_bc().r.c = cos(n.h());
59                 this->c2x_bc().r.s = sin(n.h());
60                 for (auto &o: this->c2_obstacles()) {
61                         if (c2PolytoPoly(
62                                 &this->c2_bc(), &this->c2x_bc(),
63                                 &o, NULL
64                         )) {
65                                 return std::make_tuple(true, 0, 0);
66                         }
67                 }
68         }
69         return std::make_tuple(false, 0, 0);
70 }
71
72 std::tuple<bool, unsigned int, unsigned int>
73 RRTExt2::collide_two_nodes(RRTNode &f, RRTNode &t)
74 {
75         this->c2x_bc().p.x = f.x();
76         this->c2x_bc().p.y = f.y();
77         this->c2x_bc().r.c = cos(f.h());
78         this->c2x_bc().r.s = sin(f.h());
79         for (auto &o: this->c2_obstacles()) {
80                 if (c2PolytoPoly(
81                         &this->c2_bc(), &this->c2x_bc(),
82                         &o, NULL
83                 )) {
84                         return std::make_tuple(true, 0, 0);
85                 }
86         }
87         this->c2x_bc().p.x = t.x();
88         this->c2x_bc().p.y = t.y();
89         this->c2x_bc().r.c = cos(t.h());
90         this->c2x_bc().r.s = sin(t.h());
91         for (auto &o: this->c2_obstacles()) {
92                 if (c2PolytoPoly(
93                         &this->c2_bc(), &this->c2x_bc(),
94                         &o, NULL
95                 )) {
96                         return std::make_tuple(true, 0, 0);
97                 }
98         }
99         return std::make_tuple(false, 0, 0);
100 }