servo / euclid

Geometry primitives (basic linear algebra) for Rust
Other
462 stars 103 forks source link

Distinguish between orientation and rotation. #488

Open porky11 opened 2 years ago

porky11 commented 2 years ago

I think, it would be useful to use different representations for orientation (absolute) and rotation (relative).

An orientation is there to rotate vectors and represents the current rotation of an object. A rotation is there to rotate such objects.

Basically orientation should be represented by rotors (GA), which are isomorphic to complex numbers in 2D and to quaternions in 3D. This way you can transform a lot of vectors without the need of recalculating the sine and cosine every time.

Rotation should be represented by bivectors (GA), which are isomorphic to scalars in 2D and to (normal) vectors in 3D. They represent the plane of rotation. The magnitude represents the angle, the direction represents the direction. You can scale them as much as you want. Also multiple rotations along the same plane can always be represented.

A rotation (bivector) can be converted to an orientation (rotor) using sine an cosine:

impl RotationND {
    fn to_orientation(self) -> OrientationND {
        let (imaginary_factor, scalar) = self.magnitude().sin_cos();
        OrientationND {
            scalar,
            imaginary: self.normalized() * imaginary_factor,
        }
    }
}