10 template <typename T> int sgn(T val) {
11 return (T(0) < val) - (val < T(0));
21 Point(double x, double y);
24 /*! Get horizontal coordinate. */
27 /*! Set horizontal coordinate. */
30 /*! Get vertical coordinate. */
33 /*! Set vertical coordinate. */
36 /*! \brief Return the smallest angle between three points.
38 \see https://math.stackexchange.com/questions/361412/finding-the-angle-between-three-points
40 double min_angle_between(Point const& p1, Point const& p2) const;
42 /*! \brief Return `true` if `this` point is inside of polygon `poly`.
44 * The polygon is given by the vector of `Point`s.
46 * \see https://en.wikipedia.org/wiki/Even%E2%80%93odd_rule
48 * \param poly Polygon to consider.
50 bool inside_of(std::vector<Point> const& poly) const;
52 /*! \brief Return `true` if on the right side of the plane.
54 * The plane is given by the line `li`, where `li->fp()` is the base
55 * point and the direction is given by `li->lp() - li->fp()`.
57 * \param li The plane to consider is given by `li`.
59 bool on_right_side_of(Line const& li) const;
69 Line(Point const& fp, Point const& lp);
71 /*! Get first point. */
74 /*! Get last point. */
77 /*! Get intersection point. */
80 /*! Get intersection point. */
83 /*! \brief Return if `this` line intersects with line `li`.
85 * If the method returns `true`, the intersection `Point` is available
88 * \see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
90 * \param li The line to check the intersection with.
92 bool intersects_with(Line const& li);
94 /*! \brief Return intersections of `this` (infinite) line and circle.
96 * If the method returns `true`, the intersection `Point`s are available
97 * in `this->in1()` and `this->in2()`.
99 * \see https://mathworld.wolfram.com/Circle-LineIntersection.html
101 * \param c Circle center.
102 * \param r Circle radius.
104 bool intersects_with(Point const& c, double const r);
109 /*! Store coordinates `x`, `y`, and heading `h`. */
110 class Pose : public Point {
114 Pose(double x, double y, double h);
117 /*! Get heading in the interval [-pi, +pi] radians. */
120 /*! Set heading in radians. It's recomputed to [-pi, +pi]. */
123 /*! Set pose (`x`, `y`, and `h`.) */
124 void set_pose(Pose const& p);
126 /*! \brief Rotate self around the point.
128 \param c Rotation center `Point`.
129 \param angl Angle of rotation.
131 void rotate(Point const& c, double const angl);
133 friend std::ostream& operator<<(std::ostream& out, Pose const& p);
136 class PoseRange : public Pose {
141 /*! Get heading's begin in the interval [-pi, +pi] radians. */
144 /*! Set heading's begin in radians. It's recomputed to [-pi, +pi]. */
147 /*! Get heading's end in the interval [-pi, +pi] radians. */
150 /*! Set heading's end in radians. It's recomputed to [-pi, +pi]. */
153 void rotate(Point const& c, double const angl);
155 friend std::ostream& operator<<(std::ostream& out, PoseRange const& p);
158 /*! \brief Store car size.
160 * - Default is https://en.wikipedia.org/wiki/Fiat_Punto
164 double curb_to_curb = 10.820;
165 double width = 1.625;
166 double wheelbase = 2.450;
167 double distance_to_front = 3.105;
168 double length = 3.760;
170 /*! Get curb-to-curb distance. */
173 /*! Set curb-to-curb distance. */
174 void ctc(double ctc);
176 /*! Get wheelbase. */
179 /*! Set wheelbase. */
192 void len(double len);
194 /*! Get distance from rear axle to front. */
197 /*! Set distance from rear axle to front. */
200 /*! Get distance from rear axle to rear. */
203 /*! \brief Get minimum turning radius.
205 * Please, note that the method returns really _minimum turning radius_,
206 * which is the distance from the reare axle center to the center of
207 * left or right rotation given by the kinematics constrants, i.e.
208 * _wheelbase_ and _curb-to-curb_ distance.
210 * Sometimes _minimum turning radius_ is not radius, not minimum, or not
211 * turning. In this method, _minimum turning radius_ is minimum turning
216 /*! \brief Return inner radius.
218 * The inner radius is the distance from minimum turning radius circle
219 * center to the nearest point on the car. In this case, the nearest
220 * points on the car are rear axle endpoints.
222 double iradi() const;
224 /*! \brief Return outer front radius.
226 * The outer front radius is the distance from minimum turning radius
227 * circle center to the farthest point on the front (from the rear axle
228 * view) part of the car.
230 double ofradi() const;
232 /*! \brief Return outer rear radius.
234 * The outer rear radius is the distance from minimum turning radius
235 * circle center to the farthest point on the rear (from the rear axle
236 * view) part of the car.
238 double orradi() const;
240 /*! \brief Return length of perfect parking slot.
242 * The width of the slot is the same as the width of the car.
244 * \see Simon R. Blackburn *The Geometry of Perfect Parking*
245 * \see https://www.ma.rhul.ac.uk/SRBparking
247 double perfect_parking_slot_len() const;
250 /*! Store car motion. */
269 /*! \brief Geometrical computations of a bicycle car.
271 * - `x()` and `y()` methods returns coordinates of rear axle center.
273 class BicycleCar : public Pose, public CarSize, public CarMove {
276 /*! \brief Return `false` if `bc` is not achievable.
278 * When `false` is returned the `bc` may still be drivable, but not
279 * trivially, i.e. by "line segment - circle arc - line segment".
281 * \param p `PoseRange` (resp. `Pose`) to achieve.
283 bool drivable(PoseRange const& p) const;
284 bool drivable(Pose const& p) const;
286 /*! Set maximum steering angle. */
287 void set_max_steer();
289 /*! Get frame's left front x coordinate. */
292 /*! Get frame's left front y coordinate. */
295 /*! Get frame's left rear x coordinate. */
298 /*! Get frame's left rear y coordinate. */
301 /*! Get frame's right rear x coordinate. */
304 /*! Get frame's right rear y coordinate. */
307 /*! Get frame's right front x coordinate. */
310 /*! Get frame's right front y coordinate. */
313 /*! Get rear axle's left x coordinate. */
316 /*! Get rear axle's left y coordinate. */
319 /*! Get rear axle's right x coordinate. */
322 /*! Get rear axle's right y coordinate. */
325 /*! Min. turning radius circle center on left. */
328 /*! Min. turning radius circle center on rigth. */
331 /*! Next car position based on speed `sp` and steer `st`. */
336 #endif /* BCAR_BCAR_H */