4 bool PSPlanner::collide()
6 if(std::get<0>(intersect(
7 this->cc().lfx(), this->cc().lfy(),
8 this->cc().lrx(), this->cc().lry(),
9 this->ps().x1(), this->ps().y1(),
10 this->ps().x2(), this->ps().y2()
13 if(std::get<0>(intersect(
14 this->cc().rfx(), this->cc().rfy(),
15 this->cc().rrx(), this->cc().rry(),
16 this->ps().x1(), this->ps().y1(),
17 this->ps().x2(), this->ps().y2()
20 if(std::get<0>(intersect(
21 this->cc().lfx(), this->cc().lfy(),
22 this->cc().rfx(), this->cc().rfy(),
23 this->ps().x1(), this->ps().y1(),
24 this->ps().x2(), this->ps().y2()
27 if(std::get<0>(intersect(
28 this->cc().lrx(), this->cc().lry(),
29 this->cc().rrx(), this->cc().rry(),
30 this->ps().x1(), this->ps().y1(),
31 this->ps().x2(), this->ps().y2()
34 if(std::get<0>(intersect(
35 this->cc().lfx(), this->cc().lfy(),
36 this->cc().lrx(), this->cc().lry(),
37 this->ps().x2(), this->ps().y2(),
38 this->ps().x3(), this->ps().y3()
41 if(std::get<0>(intersect(
42 this->cc().rfx(), this->cc().rfy(),
43 this->cc().rrx(), this->cc().rry(),
44 this->ps().x2(), this->ps().y2(),
45 this->ps().x3(), this->ps().y3()
48 if(std::get<0>(intersect(
49 this->cc().lfx(), this->cc().lfy(),
50 this->cc().rfx(), this->cc().rfy(),
51 this->ps().x2(), this->ps().y2(),
52 this->ps().x3(), this->ps().y3()
55 if(std::get<0>(intersect(
56 this->cc().lrx(), this->cc().lry(),
57 this->cc().rrx(), this->cc().rry(),
58 this->ps().x2(), this->ps().y2(),
59 this->ps().x3(), this->ps().y3()
62 if(std::get<0>(intersect(
63 this->cc().lfx(), this->cc().lfy(),
64 this->cc().lrx(), this->cc().lry(),
65 this->ps().x3(), this->ps().y3(),
66 this->ps().x4(), this->ps().y4()
69 if(std::get<0>(intersect(
70 this->cc().rfx(), this->cc().rfy(),
71 this->cc().rrx(), this->cc().rry(),
72 this->ps().x3(), this->ps().y3(),
73 this->ps().x4(), this->ps().y4()
76 if(std::get<0>(intersect(
77 this->cc().lfx(), this->cc().lfy(),
78 this->cc().rfx(), this->cc().rfy(),
79 this->ps().x3(), this->ps().y3(),
80 this->ps().x4(), this->ps().y4()
83 if(std::get<0>(intersect(
84 this->cc().lrx(), this->cc().lry(),
85 this->cc().rrx(), this->cc().rry(),
86 this->ps().x3(), this->ps().y3(),
87 this->ps().x4(), this->ps().y4()
93 bool PSPlanner::left()
95 double lfx = this->cc().lfx();
96 double lfy = this->cc().lfy();
97 double lrx = this->cc().lrx();
98 double lry = this->cc().lry();
99 double rrx = this->cc().rrx();
100 double rry = this->cc().rry();
101 double rfx = this->cc().rfx();
102 double rfy = this->cc().rfy();
104 (lfx - this->ps().x1()) * (this->ps().y4() - this->ps().y1())
105 - (lfy - this->ps().y1()) * (this->ps().x4() - this->ps().x1())
108 (lrx - this->ps().x1()) * (this->ps().y4() - this->ps().y1())
109 - (lry - this->ps().y1()) * (this->ps().x4() - this->ps().x1())
112 (rrx - this->ps().x1()) * (this->ps().y4() - this->ps().y1())
113 - (rry - this->ps().y1()) * (this->ps().x4() - this->ps().x1())
116 (rfx - this->ps().x1()) * (this->ps().y4() - this->ps().y1())
117 - (rfy - this->ps().y1()) * (this->ps().x4() - this->ps().x1())
119 if (this->ps().parallel())
120 return lfs == rfs && (lfs != lrs || lfs != rrs);
121 else if (!this->forward())
122 return lfs == rfs && (lfs != lrs || lfs != rrs);
124 return lrs == rrs && (lrs != lfs || lrs != rfs);
132 void PSPlanner::fer()
134 if (this->ps().parallel())
135 return this->fer_parallel();
137 return this->fer_perpendicular();
140 void PSPlanner::fer_parallel()
142 this->cc().st(this->cc().wb() / this->cc().mtr());
143 if (!this->ps().right())
144 this->cc().st(this->cc().st() * -1);
146 while (!this->left()) {
147 while (!this->collide() && !this->left())
149 if (this->left() && !this->collide()) {
152 this->cc().sp(this->cc().sp() * -1);
154 this->cc().st(this->cc().st() * -1);
159 void PSPlanner::fer_perpendicular()
163 bool PSPlanner::forward()
165 double heading = this->ps().heading();
166 while (heading < 0) heading += 2 * M_PI;
167 if (!this->ps().parallel())
169 double h = this->gc().h();
170 while (h < 0) h += 2 * M_PI;
171 if (-0.00001 < heading - h && heading - h < 0.00001)
177 PSPlanner::PSPlanner()
181 std::tuple<bool, double, double> intersect(
182 double x1, double y1,
183 double x2, double y2,
184 double x3, double y3,
188 double deno = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
190 return std::make_tuple(false, 0, 0);
191 double t = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4);
193 double u = (x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3);
196 if (t < 0 || t > 1 || u < 0 || u > 1)
197 return std::make_tuple(false, 0, 0);
198 return std::make_tuple(true, x1 + t * (x2 - x1), y1 + t * (y2 - y1));