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;
61 /*! \brief Rotate self around the point.
63 \param c Rotation center `Point`.
64 \param angl Angle of rotation.
66 void rotate(Point const& c, double const angl);
68 friend std::ostream& operator<<(std::ostream& out, Point const& p);
78 Line(Point const& fp, Point const& lp);
80 /*! Get first point. */
83 /*! Get last point. */
86 /*! Get intersection point. */
89 /*! Get intersection point. */
92 /*! \brief Return if `this` line intersects with line `li`.
94 * If the method returns `true`, the intersection `Point` is available
97 * \see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
99 * \param li The line to check the intersection with.
101 bool intersects_with(Line const& li);
103 /*! \brief Return intersections of `this` (infinite) line and circle.
105 * If the method returns `true`, the intersection `Point`s are available
106 * in `this->in1()` and `this->in2()`.
108 * \see https://mathworld.wolfram.com/Circle-LineIntersection.html
110 * \param c Circle center.
111 * \param r Circle radius.
113 bool intersects_with(Point const& c, double const r);
118 /*! Store coordinates `x`, `y`, and heading `h`. */
119 class Pose : public virtual Point {
123 Pose(double x, double y, double h);
126 /*! Get heading in the interval [-pi, +pi] radians. */
129 /*! Set heading in radians. It's recomputed to [-pi, +pi]. */
132 /*! Set pose (`x`, `y`, and `h`.) */
133 void set_pose(Pose const& p);
135 void rotate(Point const& c, double const angl);
137 friend std::ostream& operator<<(std::ostream& out, Pose const& p);
140 class PoseRange : public virtual 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
220 /*! \brief Return inner radius.
222 * The inner radius is the distance from minimum turning radius circle
223 * center to the nearest point on the car. In this case, the nearest
224 * points on the car are rear axle endpoints.
226 double iradi() const;
228 /*! \brief Return outer front radius.
230 * The outer front radius is the distance from minimum turning radius
231 * circle center to the farthest point on the front (from the rear axle
232 * view) part of the car.
234 double ofradi() const;
236 /*! \brief Return outer rear radius.
238 * The outer rear radius is the distance from minimum turning radius
239 * circle center to the farthest point on the rear (from the rear axle
240 * view) part of the car.
242 double orradi() const;
244 /*! \brief Return length of perfect parking slot.
246 * The width of the slot is the same as the width of the car.
248 * \see Simon R. Blackburn *The Geometry of Perfect Parking*
249 * \see https://www.ma.rhul.ac.uk/SRBparking
251 double perfect_parking_slot_len() const;
254 /*! Store car motion. */
273 /*! \brief Geometrical computations of a bicycle car.
275 * - `x()` and `y()` methods returns coordinates of rear axle center.
277 class BicycleCar : public virtual Pose, public virtual CarSize,
278 public virtual CarMove {
281 /*! \brief Return `false` if `bc` is not achievable.
283 * When `false` is returned the `bc` may still be drivable, but not
284 * trivially, i.e. by "line segment - circle arc - line segment".
286 * \param p `PoseRange` (resp. `Pose`) to achieve.
288 bool drivable(PoseRange const& p) const;
289 bool drivable(Pose const& p) const;
291 /*! Set maximum steering angle. */
292 void set_max_steer();
294 /*! Get frame's left front x coordinate. */
297 /*! Get frame's left front y coordinate. */
300 /*! Get frame's left rear x coordinate. */
303 /*! Get frame's left rear y coordinate. */
306 /*! Get frame's right rear x coordinate. */
309 /*! Get frame's right rear y coordinate. */
312 /*! Get frame's right front x coordinate. */
315 /*! Get frame's right front y coordinate. */
318 /*! Get rear axle's left x coordinate. */
321 /*! Get rear axle's left y coordinate. */
324 /*! Get rear axle's right x coordinate. */
327 /*! Get rear axle's right y coordinate. */
330 /*! Min. turning radius circle center on left. */
333 /*! Min. turning radius circle center on rigth. */
336 /*! Next car position based on speed `sp` and steer `st`. */
341 #endif /* BCAR_BCAR_H */