#ifndef __JROTATION2D__ #define __JROTATION2D__ #include #include "JGeometry2D/JMatrix2D.hh" #include "JGeometry2D/JAngle2D.hh" /** * \author mdejong */ namespace JGEOMETRY2D {} namespace JPP { using namespace JGEOMETRY2D; } namespace JGEOMETRY2D { /** * Rotation matrix */ class JRotation2D : public JMatrix2D { public: /** * Default constructor (= identity matrix). */ JRotation2D() : JMatrix2D() { setIdentity(); } /** * Constructor. * The rotation is around the origin and anti-clockwise. * * \param dir direction */ JRotation2D(const JAngle2D& dir) : JMatrix2D() { const double cp = cos(dir.getPhi()); const double sp = sin(dir.getPhi()); a00 = cp; a01 = -sp; a10 = sp; a11 = cp; } /** * Get rotation. * * \return rotation */ const JRotation2D& getRotation() const { return static_cast(*this); } /** * Transpose. */ JRotation2D& transpose() { JMatrix2D::transpose(); return *this; } /** * Matrix multiplication. * * \param A matrix * \return this * A */ JRotation2D& mul(const JRotation2D& A) { JMatrix2D::mul(A); return *this; } /** * Rotate. * * \param __x x value * \param __y y value */ void rotate(double& __x, double& __y) const { const double x = a00 * __x + a01 * __y; const double y = a10 * __x + a11 * __y; __x = x; __y = y; } /** * Rotate back. * * \param __x x value * \param __y y value */ void rotate_back(double& __x, double& __y) const { const double x = a00 * __x + a10 * __y; const double y = a01 * __x + a11 * __y; __x = x; __y = y; } }; } #endif