]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blobdiff - incl/bcar.hh
Add and use point, pose translate method
[hubacji1/bcar.git] / incl / bcar.hh
index 1ab5b58965e7d29cce30f956cbccf3a136243565..7591d7213682ce162ccee308350c1a27bb31f90a 100644 (file)
@@ -11,13 +11,15 @@ template <typename T> int sgn(T val) {
        return (T(0) < val) - (val < T(0));
 }
 
+class Line;
+
 class Point {
 private:
        double x_ = 0.0;
        double y_ = 0.0;
 public:
-       Point(double x, double y);
        Point();
+       Point(double x, double y);
 
        /*! Get horizontal coordinate. */
        double x() const;
@@ -46,33 +48,67 @@ public:
         * \param poly Polygon to consider.
         */
        bool inside_of(std::vector<Point> const& poly) const;
+
+       /*! \brief Return `true` if on the right side of the plane.
+        *
+        * The plane is given by the line `li`, where `li->b()` is the base
+        * point and the direction is given by `li->e() - li->b()`.
+        *
+        * \param li The plane to consider is given by `li`.
+        */
+       bool on_right_side_of(Line const& li) const;
+
+       /*! \brief Translate self.
+        *
+        * \param p `Point` offset to translate by.
+        */
+       void translate(Point const& p);
+
+       /*! \brief Rotate self around the point.
+
+       \param c Rotation center `Point`.
+       \param angl Angle of rotation.
+       */
+       void rotate(Point const& c, double const angl);
+
+       /*! \brief Compute reflection of `this` around the `Line`.
+        *
+        * \param li The plane to reflect around is given by `li`.
+        */
+       void reflect(Line const& li);
+
+       /*! Return Euclidean distance to `p`. */
+       double edist(Point const& p) const;
+
+       bool operator==(Point const& p);
+       friend std::ostream& operator<<(std::ostream& out, Point const& p);
 };
 
 class Line {
 private:
-       Point first;
-       Point last;
-       Point intersection1;
-       Point intersection2;
+       Point b_;
+       Point e_;
+       Point i1_;
+       Point i2_;
 public:
        Line(Point const& fp, Point const& lp);
 
-       /*! Get first point. */
-       Point fp() const&;
+       /*! Get beginning point. */
+       Point b() const&;
 
-       /*! Get last point. */
-       Point lp() const&;
+       /*! Get end point. */
+       Point e() const&;
 
        /*! Get intersection point. */
-       Point in1() const&;
+       Point i1() const&;
 
        /*! Get intersection point. */
-       Point in2() const&;
+       Point i2() const&;
 
        /*! \brief Return if `this` line intersects with line `li`.
         *
         * If the method returns `true`, the intersection `Point` is available
-        * in `this->in1()`.
+        * in `this->i1()`.
         *
         * \see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
         *
@@ -83,7 +119,7 @@ public:
        /*! \brief Return intersections of `this` (infinite) line and circle.
         *
         * If the method returns `true`, the intersection `Point`s are available
-        * in `this->in1()` and `this->in2()`.
+        * in `this->i1()` and `this->i2()`.
         *
         * \see https://mathworld.wolfram.com/Circle-LineIntersection.html
         *
@@ -92,34 +128,20 @@ public:
         */
        bool intersects_with(Point const& c, double const r);
 
-       /*! \brief Return if point `p` is on the right side of the plane.
-        *
-        * The plane is given by the line `this`, where `this->fp()` is the base
-        * point and the direction is given by `this->lp() - this->fp()`.
-        *
-        * \param p The point to consider.
-        */
-       bool is_on_right_side(Point const& p) const;
+       double len() const;
+
+       double h() const;
+
+       friend std::ostream& operator<<(std::ostream& out, Line const& li);
 };
 
 /*! Store coordinates `x`, `y`, and heading `h`. */
-class Pose {
+class Pose : public virtual Point {
 private:
-       double x_ = 0.0;
-       double y_ = 0.0;
        double h_ = 0.0;
 public:
-       /*! Get horizontal coordinate. */
-       double x() const;
-
-       /*! Set horizontal coordinate. */
-       void x(double x);
-
-       /*! Get vertical coordinate. */
-       double y() const;
-
-       /*! Set vertical coordinate. */
-       void y(double y);
+       using Point::Point;
+       Pose(double x, double y, double h);
 
        /*! Get heading in the interval [-pi, +pi] radians. */
        double h() const;
@@ -127,34 +149,38 @@ public:
        /*! Set heading in radians. It's recomputed to [-pi, +pi]. */
        void h(double h);
 
-       /*! \brief Rotate self around the point.
+       /*! Set pose (`x`, `y`, and `h`.) */
+       void set_pose(Pose const& p);
 
-       \param c Rotation center `Point`.
-       \param angl Angle of rotation.
-       */
        void rotate(Point const& c, double const angl);
 
+       void reflect(Line const& li);
+
+       bool operator==(Pose const& p);
        friend std::ostream& operator<<(std::ostream& out, Pose const& p);
 };
 
-class PoseRange : public Pose {
+class PoseRange : public virtual Pose {
 private:
-       double e_ = 0.0;
-       using Pose::h;
+       Pose bp_;
+       Pose ep_;
+       void set_xyh();
 public:
+       PoseRange(Pose bp, Pose ep);
+       PoseRange(double x, double y, double b, double e);
+
+       Pose bp() const;
+       Pose ep() const;
+
        /*! Get heading's begin in the interval [-pi, +pi] radians. */
        double b() const;
 
-       /*! Set heading's begin in radians. It's recomputed to [-pi, +pi]. */
-       void b(double b);
-
        /*! Get heading's end in the interval [-pi, +pi] radians. */
        double e() const;
 
-       /*! Set heading's end in radians. It's recomputed to [-pi, +pi]. */
-       void e(double e);
-
+       void translate(Point const& p);
        void rotate(Point const& c, double const angl);
+       void reflect(Line const& li);
 
        friend std::ostream& operator<<(std::ostream& out, PoseRange const& p);
 };
@@ -165,11 +191,11 @@ public:
  */
 class CarSize {
 private:
-       double curb_to_curb = 10.820;
-       double width = 1.625;
-       double wheelbase = 2.450;
-       double distance_to_front = 3.105;
-       double length = 3.760;
+       double curb_to_curb_ = 10.820;
+       double width_ = 1.625;
+       double wheelbase_ = 2.450;
+       double distance_to_front_ = 3.105;
+       double length_ = 3.760;
 public:
        /*! Get curb-to-curb distance. */
        double ctc() const;
@@ -207,7 +233,7 @@ public:
        /*! \brief Get minimum turning radius.
         *
         * Please, note that the method returns really _minimum turning radius_,
-        * which is the distance from the reare axle center to the center of
+        * which is the distance from the rear axle center to the center of
         * left or right rotation given by the kinematics constrants, i.e.
         * _wheelbase_ and _curb-to-curb_ distance.
         *
@@ -216,45 +242,6 @@ public:
         * radius.
         */
        double mtr() const;
-};
-
-/*! Store car motion. */
-class CarMove {
-private:
-       double speed = 0.0;
-       double steer = 0.0;
-public:
-       /*! Get speed. */
-       double sp() const;
-
-       /*! Set speed. */
-       void sp(double sp);
-
-       /*! Get steer. */
-       double st() const;
-
-       /*! Set steer. */
-       void st(double st);
-};
-
-/*! \brief Geometrical computations of a bicycle car.
- *
- * - `x()` and `y()` methods returns coordinates of rear axle center.
- */
-class BicycleCar : public Pose, public CarSize, public CarMove {
-private:
-public:
-       /*! \brief Return `false` if `bc` is not achievable.
-        *
-        * When `false` is returned the `bc` may still be drivable, but not
-        * trivially, i.e. by "line segment - circle arc - line segment".
-        *
-        * \param bc The bicycle car to achieve.
-        * \param b The beginning of the heading range.
-        * \param e The end of the heading range.
-        */
-       bool drivable(Pose const& p, double b, double e) const;
-       bool drivable(Pose const& p) const;
 
        /*! \brief Return inner radius.
         *
@@ -288,6 +275,44 @@ public:
         * \see https://www.ma.rhul.ac.uk/SRBparking
         */
        double perfect_parking_slot_len() const;
+};
+
+/*! Store car motion. */
+class CarMove {
+private:
+       double speed_ = 0.0;
+       double steer_ = 0.0;
+public:
+       /*! Get speed. */
+       double sp() const;
+
+       /*! Set speed. */
+       void sp(double sp);
+
+       /*! Get steer. */
+       double st() const;
+
+       /*! Set steer. */
+       void st(double st);
+};
+
+/*! \brief Geometrical computations of a bicycle car.
+ *
+ * - `x()` and `y()` methods returns coordinates of rear axle center.
+ */
+class BicycleCar : public virtual Pose, public virtual CarSize,
+               public virtual CarMove {
+private:
+public:
+       /*! \brief Return `true` if `this` can drive to `p` trivially.
+        *
+        * Trivially means that `this` can drive to `p` by line segment - circle
+        * arc - line segment.
+        *
+        * \param p `PoseRange` (resp. `Pose`) to achieve.
+        */
+       bool drivable(PoseRange const& p) const;
+       bool drivable(Pose const& p) const;
 
        /*! Set maximum steering angle. */
        void set_max_steer();
@@ -316,6 +341,30 @@ public:
        /*! Get frame's right front y coordinate. */
        double rfy() const;
 
+       /*! Get frame's left front point. */
+       Point lf() const;
+
+       /*! Get frame's left rear point. */
+       Point lr() const;
+
+       /*! Get frame's right rear point. */
+       Point rr() const;
+
+       /*! Get frame's right front point. */
+       Point rf() const;
+
+       /*! Get frame's left side. */
+       Line left() const;
+
+       /*! Get frame's rear side. */
+       Line rear() const;
+
+       /*! Get frame's right side. */
+       Line right() const;
+
+       /*! Get frame's front side. */
+       Line front() const;
+
        /*! Get rear axle's left x coordinate. */
        double ralx() const;