Skip to main content

deep_causality_num_complex/complex/quaternion_number/
rotation.rs

1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5use crate::{Quaternion, RealField, Rotation};
6
7impl<T: RealField> Rotation<T> for Quaternion<T> {
8    fn rotate_x(&self, angle: T) -> Self {
9        // Rotor R = cos(t/2) + sin(t/2) * i
10        let half = angle / (T::one() + T::one());
11        let c = half.cos();
12        let s = half.sin();
13
14        let rotor = Quaternion {
15            w: c,
16            x: s,
17            y: T::zero(),
18            z: T::zero(),
19        };
20        // Apply: q' = R * q
21        rotor * *self
22    }
23
24    fn rotate_y(&self, angle: T) -> Self {
25        let half = angle / (T::one() + T::one());
26        let c = half.cos();
27        let s = half.sin();
28        let rotor = Quaternion {
29            w: c,
30            x: T::zero(),
31            y: s,
32            z: T::zero(),
33        };
34        rotor * *self
35    }
36
37    fn rotate_z(&self, angle: T) -> Self {
38        let half = angle / (T::one() + T::one());
39        let c = half.cos();
40        let s = half.sin();
41        let rotor = Quaternion {
42            w: c,
43            x: T::zero(),
44            y: T::zero(),
45            z: s,
46        };
47        rotor * *self
48    }
49
50    fn global_phase(&self, _angle: T) -> Self {
51        // Quaternions don't support global complex phase e^{i theta}
52        // in the standard 4D definition (requires Complex Quaternions).
53        // Returning self is the safe "Real" behavior.
54        *self
55    }
56}