1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
use crate::{DivisionAlgebra, Octonion, RealField, Rotation};
impl<T: RealField> Rotation<T> for Octonion<T> {
/// Rotates the Octonion around the $e_1$ axis.
/// $R = \cos(\theta/2) + e_1 \sin(\theta/2)$
fn rotate_x(&self, angle: T) -> Self {
let two = T::one() + T::one();
let half_theta = angle / two;
let c = half_theta.cos();
let s = half_theta.sin();
// Construct Rotor R = cos + e1 * sin
let rotor = Octonion {
s: c,
e1: s,
e2: T::zero(),
e3: T::zero(),
e4: T::zero(),
e5: T::zero(),
e6: T::zero(),
e7: T::zero(),
};
// Apply Rotation: (R * v) * R*
// Note: Octonions are Non-Associative, so grouping matters.
// However, they are Alternative, and this conjugation is stable.
let rotor_conj = rotor.conjugate();
(rotor * *self) * rotor_conj
}
/// Rotates the Octonion around the $e_2$ axis.
/// $R = \cos(\theta/2) + e_2 \sin(\theta/2)$
fn rotate_y(&self, angle: T) -> Self {
let two = T::one() + T::one();
let half_theta = angle / two;
let c = half_theta.cos();
let s = half_theta.sin();
let rotor = Octonion {
s: c,
e1: T::zero(),
e2: s,
e3: T::zero(),
e4: T::zero(),
e5: T::zero(),
e6: T::zero(),
e7: T::zero(),
};
let rotor_conj = rotor.conjugate();
(rotor * *self) * rotor_conj
}
/// Rotates the Octonion around the $e_3$ axis.
/// $R = \cos(\theta/2) + e_3 \sin(\theta/2)$
fn rotate_z(&self, angle: T) -> Self {
let two = T::one() + T::one();
let half_theta = angle / two;
let c = half_theta.cos();
let s = half_theta.sin();
let rotor = Octonion {
s: c,
e1: T::zero(),
e2: T::zero(),
e3: s,
e4: T::zero(),
e5: T::zero(),
e6: T::zero(),
e7: T::zero(),
};
let rotor_conj = rotor.conjugate();
(rotor * *self) * rotor_conj
}
/// Global Phase Shift.
///
/// Octonions are a **Real** algebra. They do not have a central imaginary unit $i$
/// that commutes with everything (unlike Complex numbers).
/// Therefore, a "Global Phase" $e^{i\phi}$ is not well-defined in standard Octonion arithmetic
/// without picking a specific preferred axis (which effectively becomes a rotation).
///
/// To maintain mathematical strictness, this is an Identity operation.
fn global_phase(&self, _angle: T) -> Self {
*self
}
}