8 /*! \brief Bicycle car basic class.
10 This class contains some geometrical computations of bicycle car.
12 \param x Horizontal coordinate of rear axle center.
13 \param y Vertical coordinate of rear axle center.
14 \param h Heading of the car in the interval [-pi,+pi] radians.
15 \param mtr Minimum turning radius.
17 \param w The width of the car.
18 \param l The length of the car.
19 \param he The height of the car.
20 \param sd The safety distance.
21 \param df Distance from rear axle center to the front of the car.
22 \param dr Distance from rear axle center to the back of the car.
23 \param sp Speed of the car.
24 \param st Steering of the car.
32 // kinematic constraints
33 double ctc_ = 10.820; // curb-to-curb
34 // FIXME is not mtr; curb-to-curb is 10.820
48 // kinematic constraints
49 /*! \brief Return `false` if `bc` is not achievable.
51 When `false` is returned the `bc` may still be drivable,
52 because only "line segment - circle arc - line segment"
53 paths are considered in ``drivable`` method.
55 \param[in] bc The bicycle car to achieve.
57 bool drivable(const BicycleCar &bc) const;
58 /*! \brief Return inner radius.
60 The inner radius is the distance from minimum turning
61 radius circle center to the nearest point on the car. In
62 this case, the nearest points on the car are rear axle
66 /*! \brief Return outer front radius.
68 The outer front radius is the distance from minimum
69 turning radius circle center to the farthest point on
70 the front (from the rear axle view) part of the car.
72 double ofradi() const;
73 /*! \brief Return outer rear radius.
75 The outer rear radius is the distance from minimum
76 turning radius circle center to the farthest point on
77 the rear (from the rear axle view) part of the car.
79 double orradi() const;
80 /*! \brief Return length of perfect parking slot.
82 The width of the slot is the same as the width of the
85 double perfect_parking_slot_len() const;
86 /*! \brief Set maximum steering angle.
91 double lfx() const; double lfy() const;
92 double lrx() const; double lry() const;
93 double rrx() const; double rry() const;
94 double rfx() const; double rfy() const;
96 double ralx() const; double raly() const;
97 double rarx() const; double rary() const;
99 /*! \brief Min. turning radius circle center on left.
101 Important are coordinates `x` and `y`. The heading `h`
102 is set as the heading of `this->h()`.
104 BicycleCar ccl() const;
105 /*! \brief Min. turning radius circle center on rigth.
107 Important are coordinates `x` and `y`. The heading `h`
108 is set as the heading of `this->h()`.
110 BicycleCar ccr() const;
113 /*! \brief Next car position based on `sp` and `st`.
115 Where `sp` is speed and `st` is steering of the car.
118 /*! \brief Rotate self around the point.
120 \param cx Horizontal coordinate of rotation center.
121 \param cy Vertical coordinate of rotation center.
122 \param angl Angle of rotation.
124 void rotate(double cx, double cy, double angl);
127 double x() const { return this->x_; }
128 void x(double x) { this->x_ = x; }
130 double y() const { return this->y_; }
131 void y(double y) { this->y_ = y; }
133 double h() const { return this->h_; }
143 double ctc() const { return this->ctc_; }
144 void ctc(double ctc) { this->ctc_ = ctc; }
146 double mtr() const { return this->mtr_; }
147 void mtr(double mtr) { this->mtr_ = mtr; }
149 double wb() const { return this->wb_; }
150 void wb(double wb) { this->wb_ = wb; }
152 double w() const { return this->w_; }
153 void w(double w) { this->w_ = w; }
155 double l() const { return this->l_; }
156 void l(double l) { this->l_ = l; }
158 double he() const { return this->he_; }
159 void he(double he) { this->he_ = he; }
161 double sd() const { return this->sd_; }
162 void sd(double sd) { this->sd_ = sd; }
164 double df() const { return this->df_; }
165 void df(double df) { this->df_ = df; }
167 double dr() const { return this->dr_; }
168 void dr(double dr) { this->dr_ = dr; }
170 double sp() const { return this->sp_; }
171 void sp(double sp) { this->sp_ = sp; }
173 double st() const { return this->st_; }
174 void st(double st) { this->st_ = st; }
177 friend std::ostream &operator<<(
182 out << "[" << bc.x();
183 out << "," << bc.y();
184 out << "," << bc.h();
190 /*! \brief Does two polygons collide?
192 Return the tuple `std::tuple<bool, int, int>`, where the first value is
193 `true` when there is an intersection of some segments of the polygons
194 `p1` and `p2` and `false` otherwise. The second and third parameters in
195 the return tuple are indexes of the first collision, where index starts
198 \param p1 The first polygon to check against collision.
199 \param p2 The second polygon to check against collision.
201 std::tuple<bool, unsigned int, unsigned int> collide(
202 std::vector<std::tuple<double, double>> &p1,
203 std::vector<std::tuple<double, double>> &p2
206 /*! \brief Is `x, y` coordinate in polygon `poly`?
208 Return `true` if `x, y` coordinate is inside of polygon `poly`.
210 \see https://en.wikipedia.org/wiki/Even%E2%80%93odd_rule
212 \param x Horizontal coordinate.
213 \param y Vertical coordinate.
214 \param poly The vector of coordinates.
216 bool inside(double x, double y, std::vector<std::tuple<double, double>> &poly);
218 /*! \brief Return intersection of two line segments.
220 The output is tuple `std::tuple<bool, double, double>`, where the first
221 value is true when there is an intersection and false otherwise. The
222 second and third parameters in the return tuple are coordinates of the
225 \see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
227 \param x1 First line segment first `x` coordinate.
228 \param y1 First line segment first `y` coordinate.
229 \param x2 First line segment second `x` coordinate.
230 \param y2 First line segment second `y` coordinate.
231 \param x3 Second line segment first `x` coordinate.
232 \param y3 Second line segment first `y` coordinate.
233 \param x4 Second line segment second `x` coordinate.
234 \param y4 Second line segment second `y` coordinate.
236 std::tuple<bool, double, double> intersect(
237 double x1, double y1,
238 double x2, double y2,
239 double x3, double y3,