rustgd / cgmath

A linear algebra and mathematics library for computer graphics.
https://docs.rs/cgmath
Apache License 2.0
1.12k stars 155 forks source link

Quaternion (Rotation?) pow/exponent function #555

Open thatcomputerguy0101 opened 1 month ago

thatcomputerguy0101 commented 1 month ago

I'm interested in using a pow/exponent function on the Quaternion type to concisely represent repeated rotations. For quaternions specifically, I found an algorithm for this on the Mathematics StackExchange. However, this concept also applies to other representations of rotations, so it may be more appropriate to add it to the Rotation trait with an implementation for each implementing type. I'd be willing to help implement this functionality for an eventual PR, but wanted feedback on its design before starting.

Example public api:

pub trait Rotation: Sized + Copy + One
//where ...
{
    // Other functions...

    /// Create a new rotation representing `exponent` copies of the original rotation
    fn pow(&self, exponent: <Self::Space as EuclideanSpace>::Scalar) -> Self;

    /// Modifies this rotation to represent `exponent` copies of the original rotation
    fn pow_assign(&mut self, exponent: <Self::Space as EuclideanSpace>::Scalar);
}