[Positioner] Add Point3D::rotate_2d()

This commit is contained in:
Matteo Cypriani 2012-04-30 09:58:30 +02:00
parent 88a90a7abd
commit 291ef457f5
2 changed files with 20 additions and 0 deletions

View File

@ -97,6 +97,24 @@ double Point3D::angle_2d(const Point3D &b, const Point3D &c) const
}
/**
* #x and #y are updated with the rotated image of the point.
*
* Note that as this functions does a 2D rotation, the c.z is ignored,
* and so is this->x.
*/
void Point3D::rotate_2d(const Point3D &c, float angle)
{
angle = PosUtil::deg2rad(angle) ;
float new_x = cos(angle) * (x-c.x) - sin(angle) * (y-c.y) + c.x ;
float new_y = sin(angle) * (x-c.x) + cos(angle) * (y-c.y) + c.y ;
x = new_x ;
y = new_y ;
}
/* *** Operators *** */

View File

@ -64,6 +64,8 @@ public:
const float radius) const ;
/// Angle BÂC (A being *this) in 2D
double angle_2d(const Point3D &b, const Point3D &c) const ;
/// Rotate #x and #y with a given angle around a center c
void rotate_2d(const Point3D &center, float angle) ;
//@}
/** @name Operators */