10 template <typename T> int sgn(T val) {
11 return (T(0) < val) - (val < T(0));
19 Point(double x, double y);
22 /*! Get horizontal coordinate. */
25 /*! Set horizontal coordinate. */
28 /*! Get vertical coordinate. */
31 /*! Set vertical coordinate. */
34 /*! \brief Return the smallest angle between three points.
36 \see https://math.stackexchange.com/questions/361412/finding-the-angle-between-three-points
38 double min_angle_between(Point const& p1, Point const& p2) const;
40 /*! \brief Return `true` if `this` point is inside of polygon `poly`.
42 * The polygon is given by the vector of `Point`s.
44 * \see https://en.wikipedia.org/wiki/Even%E2%80%93odd_rule
46 * \param poly Polygon to consider.
48 bool inside_of(std::vector<Point> const& poly) const;
58 Line(Point const& fp, Point const& lp);
60 /*! Get first point. */
63 /*! Get last point. */
66 /*! Get intersection point. */
69 /*! Get intersection point. */
72 /*! \brief Return if `this` line intersects with line `li`.
74 * If the method returns `true`, the intersection `Point` is available
77 * \see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
79 * \param li The line to check the intersection with.
81 bool intersects_with(Line const& li);
83 /*! \brief Return intersections of `this` (infinite) line and circle.
85 * If the method returns `true`, the intersection `Point`s are available
86 * in `this->in1()` and `this->in2()`.
88 * \see https://mathworld.wolfram.com/Circle-LineIntersection.html
90 * \param c Circle center.
91 * \param r Circle radius.
93 bool intersects_with(Point const& c, double const r);
95 /*! \brief Return if point `p` is on the right side of the plane.
97 * The plane is given by the line `this`, where `this->fp()` is the base
98 * point and the direction is given by `this->lp() - this->fp()`.
100 * \param p The point to consider.
102 bool is_on_right_side(Point const& p) const;
105 /*! Store coordinates `x`, `y`, and heading `h`. */
112 /*! Get horizontal coordinate. */
115 /*! Set horizontal coordinate. */
118 /*! Get vertical coordinate. */
121 /*! Set vertical coordinate. */
124 /*! Get heading in the interval [-pi, +pi] radians. */
127 /*! Set heading in radians. It's recomputed to [-pi, +pi]. */
130 /*! \brief Rotate self around the point.
132 \param c Rotation center `Point`.
133 \param angl Angle of rotation.
135 void rotate(Point const& c, double const angl);
137 friend std::ostream& operator<<(std::ostream& out, Pose const& p);
140 class PoseRange : public Pose {
145 /*! Get heading's begin in the interval [-pi, +pi] radians. */
148 /*! Set heading's begin in radians. It's recomputed to [-pi, +pi]. */
151 /*! Get heading's end in the interval [-pi, +pi] radians. */
154 /*! Set heading's end in radians. It's recomputed to [-pi, +pi]. */
157 void rotate(Point const& c, double const angl);
159 friend std::ostream& operator<<(std::ostream& out, PoseRange const& p);
162 /*! \brief Store car size.
164 * - Default is https://en.wikipedia.org/wiki/Fiat_Punto
168 double curb_to_curb = 10.820;
169 double width = 1.625;
170 double wheelbase = 2.450;
171 double distance_to_front = 3.105;
172 double length = 3.760;
174 /*! Get curb-to-curb distance. */
177 /*! Set curb-to-curb distance. */
178 void ctc(double ctc);
180 /*! Get wheelbase. */
183 /*! Set wheelbase. */
196 void len(double len);
198 /*! Get distance from rear axle to front. */
201 /*! Set distance from rear axle to front. */
204 /*! Get distance from rear axle to rear. */
207 /*! \brief Get minimum turning radius.
209 * Please, note that the method returns really _minimum turning radius_,
210 * which is the distance from the reare axle center to the center of
211 * left or right rotation given by the kinematics constrants, i.e.
212 * _wheelbase_ and _curb-to-curb_ distance.
214 * Sometimes _minimum turning radius_ is not radius, not minimum, or not
215 * turning. In this method, _minimum turning radius_ is minimum turning
221 /*! Store car motion. */
240 /*! \brief Geometrical computations of a bicycle car.
242 * - `x()` and `y()` methods returns coordinates of rear axle center.
244 class BicycleCar : public Pose, public CarSize, public CarMove {
247 /*! \brief Return `false` if `bc` is not achievable.
249 * When `false` is returned the `bc` may still be drivable, but not
250 * trivially, i.e. by "line segment - circle arc - line segment".
252 * \param p `PoseRange` (resp. `Pose`) to achieve.
254 bool drivable(PoseRange const& p) const;
255 bool drivable(Pose const& p) const;
257 /*! \brief Return inner radius.
259 * The inner radius is the distance from minimum turning radius circle
260 * center to the nearest point on the car. In this case, the nearest
261 * points on the car are rear axle endpoints.
263 double iradi() const;
265 /*! \brief Return outer front radius.
267 * The outer front radius is the distance from minimum turning radius
268 * circle center to the farthest point on the front (from the rear axle
269 * view) part of the car.
271 double ofradi() const;
273 /*! \brief Return outer rear radius.
275 * The outer rear radius is the distance from minimum turning radius
276 * circle center to the farthest point on the rear (from the rear axle
277 * view) part of the car.
279 double orradi() const;
281 /*! \brief Return length of perfect parking slot.
283 * The width of the slot is the same as the width of the car.
285 * \see Simon R. Blackburn *The Geometry of Perfect Parking*
286 * \see https://www.ma.rhul.ac.uk/SRBparking
288 double perfect_parking_slot_len() const;
290 /*! Set maximum steering angle. */
291 void set_max_steer();
293 /*! Get frame's left front x coordinate. */
296 /*! Get frame's left front y coordinate. */
299 /*! Get frame's left rear x coordinate. */
302 /*! Get frame's left rear y coordinate. */
305 /*! Get frame's right rear x coordinate. */
308 /*! Get frame's right rear y coordinate. */
311 /*! Get frame's right front x coordinate. */
314 /*! Get frame's right front y coordinate. */
317 /*! Get rear axle's left x coordinate. */
320 /*! Get rear axle's left y coordinate. */
323 /*! Get rear axle's right x coordinate. */
326 /*! Get rear axle's right y coordinate. */
329 /*! Min. turning radius circle center on left. */
332 /*! Min. turning radius circle center on rigth. */
335 /*! Next car position based on speed `sp` and steer `st`. */
340 #endif /* BCAR_BCAR_H */