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`. */
106 class Pose : public Point {
110 Pose(double x, double y, double h);
113 /*! Get heading in the interval [-pi, +pi] radians. */
116 /*! Set heading in radians. It's recomputed to [-pi, +pi]. */
119 /*! Set pose (`x`, `y`, and `h`.) */
120 void set_pose(Pose const& p);
122 /*! \brief Rotate self around the point.
124 \param c Rotation center `Point`.
125 \param angl Angle of rotation.
127 void rotate(Point const& c, double const angl);
129 friend std::ostream& operator<<(std::ostream& out, Pose const& p);
132 class PoseRange : public Pose {
137 /*! Get heading's begin in the interval [-pi, +pi] radians. */
140 /*! Set heading's begin in radians. It's recomputed to [-pi, +pi]. */
143 /*! Get heading's end in the interval [-pi, +pi] radians. */
146 /*! Set heading's end in radians. It's recomputed to [-pi, +pi]. */
149 void rotate(Point const& c, double const angl);
151 friend std::ostream& operator<<(std::ostream& out, PoseRange const& p);
154 /*! \brief Store car size.
156 * - Default is https://en.wikipedia.org/wiki/Fiat_Punto
160 double curb_to_curb = 10.820;
161 double width = 1.625;
162 double wheelbase = 2.450;
163 double distance_to_front = 3.105;
164 double length = 3.760;
166 /*! Get curb-to-curb distance. */
169 /*! Set curb-to-curb distance. */
170 void ctc(double ctc);
172 /*! Get wheelbase. */
175 /*! Set wheelbase. */
188 void len(double len);
190 /*! Get distance from rear axle to front. */
193 /*! Set distance from rear axle to front. */
196 /*! Get distance from rear axle to rear. */
199 /*! \brief Get minimum turning radius.
201 * Please, note that the method returns really _minimum turning radius_,
202 * which is the distance from the reare axle center to the center of
203 * left or right rotation given by the kinematics constrants, i.e.
204 * _wheelbase_ and _curb-to-curb_ distance.
206 * Sometimes _minimum turning radius_ is not radius, not minimum, or not
207 * turning. In this method, _minimum turning radius_ is minimum turning
212 /*! \brief Return inner radius.
214 * The inner radius is the distance from minimum turning radius circle
215 * center to the nearest point on the car. In this case, the nearest
216 * points on the car are rear axle endpoints.
218 double iradi() const;
220 /*! \brief Return outer front radius.
222 * The outer front radius is the distance from minimum turning radius
223 * circle center to the farthest point on the front (from the rear axle
224 * view) part of the car.
226 double ofradi() const;
228 /*! \brief Return outer rear radius.
230 * The outer rear radius is the distance from minimum turning radius
231 * circle center to the farthest point on the rear (from the rear axle
232 * view) part of the car.
234 double orradi() const;
236 /*! \brief Return length of perfect parking slot.
238 * The width of the slot is the same as the width of the car.
240 * \see Simon R. Blackburn *The Geometry of Perfect Parking*
241 * \see https://www.ma.rhul.ac.uk/SRBparking
243 double perfect_parking_slot_len() const;
246 /*! Store car motion. */
265 /*! \brief Geometrical computations of a bicycle car.
267 * - `x()` and `y()` methods returns coordinates of rear axle center.
269 class BicycleCar : public Pose, public CarSize, public CarMove {
272 /*! \brief Return `false` if `bc` is not achievable.
274 * When `false` is returned the `bc` may still be drivable, but not
275 * trivially, i.e. by "line segment - circle arc - line segment".
277 * \param p `PoseRange` (resp. `Pose`) to achieve.
279 bool drivable(PoseRange const& p) const;
280 bool drivable(Pose const& p) const;
282 /*! Set maximum steering angle. */
283 void set_max_steer();
285 /*! Get frame's left front x coordinate. */
288 /*! Get frame's left front y coordinate. */
291 /*! Get frame's left rear x coordinate. */
294 /*! Get frame's left rear y coordinate. */
297 /*! Get frame's right rear x coordinate. */
300 /*! Get frame's right rear y coordinate. */
303 /*! Get frame's right front x coordinate. */
306 /*! Get frame's right front y coordinate. */
309 /*! Get rear axle's left x coordinate. */
312 /*! Get rear axle's left y coordinate. */
315 /*! Get rear axle's right x coordinate. */
318 /*! Get rear axle's right y coordinate. */
321 /*! Min. turning radius circle center on left. */
324 /*! Min. turning radius circle center on rigth. */
327 /*! Next car position based on speed `sp` and steer `st`. */
332 #endif /* BCAR_BCAR_H */