From: Jiri Vlasak Date: Wed, 14 Jul 2021 23:12:47 +0000 (+0200) Subject: Move rotate method to point X-Git-Tag: v0.6.0~8 X-Git-Url: https://rtime.felk.cvut.cz/gitweb/hubacji1/bcar.git/commitdiff_plain/21870ef02d534dd5bed7e96016ef249a60438543 Move rotate method to point --- diff --git a/incl/bcar.hh b/incl/bcar.hh index 5a4e466..ee9c303 100644 --- a/incl/bcar.hh +++ b/incl/bcar.hh @@ -58,6 +58,13 @@ public: */ bool on_right_side_of(Line const& li) const; + /*! \brief Rotate self around the point. + + \param c Rotation center `Point`. + \param angl Angle of rotation. + */ + void rotate(Point const& c, double const angl); + friend std::ostream& operator<<(std::ostream& out, Point const& p); }; @@ -125,11 +132,6 @@ public: /*! Set pose (`x`, `y`, and `h`.) */ void set_pose(Pose 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); friend std::ostream& operator<<(std::ostream& out, Pose const& p); diff --git a/src/bcar.cc b/src/bcar.cc index 8aa2b94..230ccbe 100644 --- a/src/bcar.cc +++ b/src/bcar.cc @@ -95,6 +95,19 @@ Point::on_right_side_of(Line const& li) const } } +void +Point::rotate(Point const& c, double const angl) +{ + double px = this->x(); + double py = this->y(); + px -= c.x(); + py -= c.y(); + double nx = px * cos(angl) - py * sin(angl); + double ny = px * sin(angl) + py * cos(angl); + this->x(nx + c.x()); + this->y(ny + c.y()); +} + std::ostream& operator<<(std::ostream& out, Point const& p) { @@ -243,15 +256,8 @@ Pose::set_pose(Pose const& p) void Pose::rotate(Point const& c, double const angl) { - double px = this->x(); - double py = this->y(); - px -= c.x(); - py -= c.y(); - double nx = px * cos(angl) - py * sin(angl); - double ny = px * sin(angl) + py * cos(angl); + Point::rotate(c, angl); this->h(this->h() + angl); - this->x(nx + c.x()); - this->y(ny + c.y()); } std::ostream&