3 bool PSPlanner::collide()
5 if(std::get<0>(intersect(
6 this->cc().lfx(), this->cc().lfy(),
7 this->cc().lrx(), this->cc().lry(),
8 this->ps().x1(), this->ps().y1(),
9 this->ps().x2(), this->ps().y2()
12 if(std::get<0>(intersect(
13 this->cc().rfx(), this->cc().rfy(),
14 this->cc().rrx(), this->cc().rry(),
15 this->ps().x1(), this->ps().y1(),
16 this->ps().x2(), this->ps().y2()
19 if(std::get<0>(intersect(
20 this->cc().lfx(), this->cc().lfy(),
21 this->cc().rfx(), this->cc().rfy(),
22 this->ps().x1(), this->ps().y1(),
23 this->ps().x2(), this->ps().y2()
26 if(std::get<0>(intersect(
27 this->cc().lrx(), this->cc().lry(),
28 this->cc().rrx(), this->cc().rry(),
29 this->ps().x1(), this->ps().y1(),
30 this->ps().x2(), this->ps().y2()
33 if(std::get<0>(intersect(
34 this->cc().lfx(), this->cc().lfy(),
35 this->cc().lrx(), this->cc().lry(),
36 this->ps().x2(), this->ps().y2(),
37 this->ps().x3(), this->ps().y3()
40 if(std::get<0>(intersect(
41 this->cc().rfx(), this->cc().rfy(),
42 this->cc().rrx(), this->cc().rry(),
43 this->ps().x2(), this->ps().y2(),
44 this->ps().x3(), this->ps().y3()
47 if(std::get<0>(intersect(
48 this->cc().lfx(), this->cc().lfy(),
49 this->cc().rfx(), this->cc().rfy(),
50 this->ps().x2(), this->ps().y2(),
51 this->ps().x3(), this->ps().y3()
54 if(std::get<0>(intersect(
55 this->cc().lrx(), this->cc().lry(),
56 this->cc().rrx(), this->cc().rry(),
57 this->ps().x2(), this->ps().y2(),
58 this->ps().x3(), this->ps().y3()
61 if(std::get<0>(intersect(
62 this->cc().lfx(), this->cc().lfy(),
63 this->cc().lrx(), this->cc().lry(),
64 this->ps().x3(), this->ps().y3(),
65 this->ps().x4(), this->ps().y4()
68 if(std::get<0>(intersect(
69 this->cc().rfx(), this->cc().rfy(),
70 this->cc().rrx(), this->cc().rry(),
71 this->ps().x3(), this->ps().y3(),
72 this->ps().x4(), this->ps().y4()
75 if(std::get<0>(intersect(
76 this->cc().lfx(), this->cc().lfy(),
77 this->cc().rfx(), this->cc().rfy(),
78 this->ps().x3(), this->ps().y3(),
79 this->ps().x4(), this->ps().y4()
82 if(std::get<0>(intersect(
83 this->cc().lrx(), this->cc().lry(),
84 this->cc().rrx(), this->cc().rry(),
85 this->ps().x3(), this->ps().y3(),
86 this->ps().x4(), this->ps().y4()
92 bool PSPlanner::left()
94 double lfx = this->cc().lfx();
95 double lfy = this->cc().lfy();
96 double rfx = this->cc().rfx();
97 double rfy = this->cc().rfy();
98 double ccx = this->cc().x();
99 double ccy = this->cc().y();
101 (lfx - this->ps().x1()) * (this->ps().y4() - this->ps().y1())
102 - (lfy - this->ps().y1()) * (this->ps().x4() - this->ps().x1())
105 (rfx - this->ps().x1()) * (this->ps().y4() - this->ps().y1())
106 - (rfy - this->ps().y1()) * (this->ps().x4() - this->ps().x1())
109 (ccx - this->ps().x1()) * (this->ps().y4() - this->ps().y1())
110 - (ccy - this->ps().y1()) * (this->ps().x4() - this->ps().x1())
112 return lfs == rfs && lfs != ccs;
120 void PSPlanner::fer()
122 if (this->ps().parallel())
123 return this->fer_parallel();
125 return this->fer_perpendicular();
128 void PSPlanner::fer_parallel()
130 this->cc().st(this->cc().wb() / this->cc().mtr());
131 if (!this->ps().right())
132 this->cc().st(this->cc().st() * -1);
134 while (!this->left()) {
135 while (!this->collide() && !this->left()) {
138 if (this->left() && !this->collide()) {
141 this->cc().sp(this->cc().sp() * -1);
143 this->cc().st(this->cc().st() * -1);
148 void PSPlanner::fer_perpendicular()
152 PSPlanner::PSPlanner()
156 std::tuple<bool, double, double> intersect(
157 double x1, double y1,
158 double x2, double y2,
159 double x3, double y3,
163 double deno = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
165 return std::make_tuple(false, 0, 0);
166 double t = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4);
168 double u = (x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3);
171 if (t < 0 || t > 1 || u < 0 || u > 1)
172 return std::make_tuple(false, 0, 0);
173 return std::make_tuple(true, x1 + t * (x2 - x1), y1 + t * (y2 - y1));