Add rotation wrt a point.

This commit is contained in:
Sébastien Crozet 2013-06-06 22:57:07 +00:00
parent 0b8058e88f
commit e9948f55d0

View File

@ -1,3 +1,5 @@
use traits::translation::Translation;
/// Trait of object which represent a rotation, and to wich new rotations can /// Trait of object which represent a rotation, and to wich new rotations can
/// be appended. A rotation is assumed to be an isomitry without translation /// be appended. A rotation is assumed to be an isomitry without translation
/// and without reflexion. /// and without reflexion.
@ -13,3 +15,21 @@ pub trait Rotation<V>
/// In-place version of `rotated`. /// In-place version of `rotated`.
fn rotate(&mut self, &V); fn rotate(&mut self, &V);
} }
/**
* Applies a rotation centered on a specific point.
*
* - `m`: the object to be rotated.
* - `ammount`: the rotation to apply.
* - `point`: the center of rotation.
*/
pub fn rotate_wrt_point<M: Rotation<AV> + Translation<LV>, LV: Neg<LV>, AV>
(m: &M, ammount: &AV, center: &LV) -> M
{
let mut res = m.translated(&-center);
res.rotate(ammount);
res.translate(center);
res
}