pub struct Biquaternion {
pub components: [Complex<f64>; 4],
}Expand description
A quaternion with complex coefficients.
Biquaternions are the set of numbers $a + b\mathbf{i} + c\mathbf{j} + d\mathbf{k}$
where $a,b,c,d$ are complex numbers and $\{1,\mathbf{i},\mathbf{j},\mathbf{k}\}$
are the quaternion algebra. Biquaternions can be thought of as a
generalization of quaternions which allow for complex coefficients.
Analogous to quaternions and SO(3), biquaternions furnish a representation
of SO(3,1)
§Construction of Biquaternions
Create a biquaternion from an array of four complex numbers. Note that
components are in the order $[\mathbf{i},\mathbf{j},\mathbf{k},1]$
(i.e., the scalar component is at the end)
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(1.0, 4.0),
Complex::new(2.0, 3.0),
Complex::new(3.0, 2.0),
Complex::new(4.0, 1.0),
]);
assert_eq!(4.0, q.components[0].im);§Operations with Biquaternions.
Similar to Quaternion, biquaternions support vector operations
(addition, multiplication by a scalar, etc.):
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let mut a = Biquaternion::from([
Complex::new(1.0, 0.0),
Complex::new(2.0, 0.0),
Complex::new(3.0, 0.0),
Complex::new(0.0, 1.0),
]);
let mut b = Biquaternion::from([
Complex::new(0.0, 4.0),
Complex::new(0.0, 3.0),
Complex::new(0.0, 2.0),
Complex::new(1.0, 0.0),
]);
b /= 2.0;
let mut c = a + b;
assert_eq!(Complex::new(1.0, 2.0), c.components[0]);Biquaternions also support the following operations:
Hamiltonian conjugate/ biconjugate: Denoted by the method “bar”, the Hamiltonian conjugate multiplies the vector part of the biquaternion by -1.0.
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(-1.0, 0.0),
Complex::new(-1.0, 2.0),
Complex::new(1.0, 0.0),
Complex::new(1.0, 0.0),
]);
let p = Biquaternion::from([
Complex::new(1.0, 0.0),
Complex::new(1.0, -2.0),
Complex::new(-1.0, 0.0),
Complex::new(1.0, 0.0),
]);
assert_eq!(p, q.bar());Complex conjugation: Denoted by method “conj”, takes the complex conjugate of all components of the biquaternion
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(1.0, 8.0),
Complex::new(2.0, 7.0),
Complex::new(3.0, 6.0),
Complex::new(4.0, 5.0),
]);
let p = Biquaternion::from([
Complex::new(1.0, -8.0),
Complex::new(2.0, -7.0),
Complex::new(3.0, -6.0),
Complex::new(4.0, -5.0),
]);
assert_eq!(p, q.conj());Biquaternion Product: The biquaternion product takes two biquaternions and outputs another biquaternion.
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(2.0, 0.0),
Complex::new(0.0, 1.0),
Complex::new(1.0, 0.0),
Complex::new(1.0, 0.0),
]);
let p = Biquaternion::from([
Complex::new(3.0, 0.0),
Complex::new(2.0, 0.0),
Complex::new(1.0, 0.0),
Complex::new(0.0, 1.0),
]);
let c = Biquaternion::from([
Complex::new(1.0, 3.0),
Complex::new(2.0, 0.0),
Complex::new(5.0, -2.0),
Complex::new(-7.0, -1.0),
]);
assert_eq!(c, q.dot(&p));Scalar Product: The scalar product takes two biquaternions and outputs a complex number according to
\frac{1}{2}(a\overline{b} + b\overline{a})use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(2.0, 0.0),
Complex::new(0.0, 1.0),
Complex::new(1.0, 0.0),
Complex::new(1.0, 0.0),
]);
let p = Biquaternion::from([
Complex::new(3.0, 0.0),
Complex::new(2.0, 0.0),
Complex::new(1.0, 0.0),
Complex::new(0.0, 1.0),
]);
assert_eq!(Complex::new(7.0, 3.0), q.scalar_product(&p));Biquaternion Norm: The scalar product furnishes a “norm” for the biquaternion.
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(3.0, 0.0),
Complex::new(0.0, 1.0),
Complex::new(4.0, 0.0),
Complex::new(0.0, 2.0),
]);
assert_eq!(Complex::new(20.0_f64, 0.0).sqrt(), q.norm());Fields§
§components: [Complex<f64>; 4]Components of the biquaternion, in the order [i,j,k,1].
Implementations§
Source§impl Biquaternion
impl Biquaternion
Sourcepub fn bar(&self) -> Self
pub fn bar(&self) -> Self
Compute the Hamiltonian conjugate or biconjugate of a biquaternion.
§Example
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(-1.0, 0.0),
Complex::new(0.0, 1.0),
Complex::new(1.0, 0.0),
Complex::new(1.0, 0.0),
]);
let p = Biquaternion::from([
Complex::new(1.0, 0.0),
Complex::new(0.0, -1.0),
Complex::new(-1.0, 0.0),
Complex::new(1.0, 0.0),
]);
assert_eq!(p, q.bar());Sourcepub fn conj(&self) -> Self
pub fn conj(&self) -> Self
Compute the complex conjugate of a biquaternion.
§Example
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(1.0, 0.0),
Complex::new(0.0, 1.0),
Complex::new(1.0, 0.0),
Complex::new(1.0, 2.0),
]);
let p = Biquaternion::from([
Complex::new(1.0, 0.0),
Complex::new(0.0, -1.0),
Complex::new(1.0, 0.0),
Complex::new(1.0, -2.0),
]);
assert_eq!(p, q.conj());Sourcepub fn norm_squared(&self) -> Complex<f64>
pub fn norm_squared(&self) -> Complex<f64>
Compute the squared norm of a biquaternion.
§Example
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(1.0, 0.0),
Complex::new(0.0, 1.0),
Complex::new(1.0, 0.0),
Complex::new(1.0, 0.0),
]);
assert_eq!(2.0, q.norm_squared().re);Sourcepub fn norm(&self) -> Complex<f64>
pub fn norm(&self) -> Complex<f64>
the norm of a biquaternion
§Example
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(3.0, 0.0),
Complex::new(0.0, 1.0),
Complex::new(4.0, 0.0),
Complex::new(1.0, 0.0),
]);
assert_eq!(Complex::new(5.0, 0.0), q.norm());Sourcepub fn dot(&self, other: &Self) -> Self
pub fn dot(&self, other: &Self) -> Self
Compute the quaternion product of two biquaternions.
§Example
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(2.0, 0.0),
Complex::new(0.0, 1.0),
Complex::new(1.0, 0.0),
Complex::new(1.0, 0.0),
]);
let p = Biquaternion::from([
Complex::new(3.0, 0.0),
Complex::new(2.0, 0.0),
Complex::new(1.0, 0.0),
Complex::new(0.0, 1.0),
]);
let c = Biquaternion::from([
Complex::new(1.0, 3.0),
Complex::new(2.0, 0.0),
Complex::new(5.0, -2.0),
Complex::new(-7.0, -1.0),
]);
assert_eq!(c, q.dot(&p));Sourcepub fn scalar_product(&self, other: &Self) -> Complex<f64>
pub fn scalar_product(&self, other: &Self) -> Complex<f64>
Compute the scalar product of two biquaternions.
§Example
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(2.0, 0.0),
Complex::new(0.0, 1.0),
Complex::new(1.0, 0.0),
Complex::new(1.0, 0.0),
]);
let p = Biquaternion::from([
Complex::new(3.0, 0.0),
Complex::new(2.0, 0.0),
Complex::new(1.0, 0.0),
Complex::new(0.0, 1.0),
]);
assert_eq!(Complex::new(7.0, 3.0), q.scalar_product(&p));Sourcepub fn to_unit(self) -> Result<UnitBiquaternion, Error>
pub fn to_unit(self) -> Result<UnitBiquaternion, Error>
Create a UnitBiquaternion by normalizing the given biquaternion.
§Errors
Error::InvalidBiquaternionMagnitude when self is the 0 quaternion.
Sourcepub fn to_unit_unchecked(self) -> UnitBiquaternion
pub fn to_unit_unchecked(self) -> UnitBiquaternion
Create a UnitBiquaternion by normalizing the given biquaternion.
Trait Implementations§
Source§impl Add for Biquaternion
impl Add for Biquaternion
Source§impl AddAssign for Biquaternion
impl AddAssign for Biquaternion
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl Clone for Biquaternion
impl Clone for Biquaternion
Source§fn clone(&self) -> Biquaternion
fn clone(&self) -> Biquaternion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Biquaternion
impl Debug for Biquaternion
Source§impl Default for Biquaternion
impl Default for Biquaternion
Source§impl<'de> Deserialize<'de> for Biquaternion
impl<'de> Deserialize<'de> for Biquaternion
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Biquaternion
impl Display for Biquaternion
Source§impl Div<f64> for Biquaternion
impl Div<f64> for Biquaternion
Source§impl DivAssign<f64> for Biquaternion
impl DivAssign<f64> for Biquaternion
Source§fn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
/= operation. Read moreSource§impl From<[Complex<f64>; 4]> for Biquaternion
impl From<[Complex<f64>; 4]> for Biquaternion
Source§fn from(value: [Complex<f64>; 4]) -> Self
fn from(value: [Complex<f64>; 4]) -> Self
Construct a Biquaternion from 4 complex values.
§Example
use hoomd_manifold::Biquaternion;
use num::complex::Complex;
let q = Biquaternion::from([
Complex::new(1.0, 0.0),
Complex::new(0.0, 0.1),
Complex::new(1.0, 0.0),
Complex::new(1.0, 1.0),
]);
assert_eq!(
q.components,
[
Complex::new(1.0, 0.0),
Complex::new(0.0, 0.1),
Complex::new(1.0, 0.0),
Complex::new(1.0, 1.0)
]
);Source§impl Mul<f64> for Biquaternion
impl Mul<f64> for Biquaternion
Source§impl MulAssign<f64> for Biquaternion
impl MulAssign<f64> for Biquaternion
Source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
*= operation. Read moreSource§impl PartialEq for Biquaternion
impl PartialEq for Biquaternion
Source§impl Serialize for Biquaternion
impl Serialize for Biquaternion
Source§impl Sub for Biquaternion
impl Sub for Biquaternion
Source§impl SubAssign for Biquaternion
impl SubAssign for Biquaternion
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more