Biquaternion

Struct Biquaternion 

Source
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

Source

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());
Source

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());
Source

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);
Source

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());
Source

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));
Source

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));
Source

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.

Source

pub fn to_unit_unchecked(self) -> UnitBiquaternion

Create a UnitBiquaternion by normalizing the given biquaternion.

Trait Implementations§

Source§

impl Add for Biquaternion

Source§

type Output = Biquaternion

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for Biquaternion

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Biquaternion

Source§

fn clone(&self) -> Biquaternion

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Biquaternion

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Biquaternion

Source§

fn default() -> Self

Create a biquaternion with all zeros.

Source§

impl<'de> Deserialize<'de> for Biquaternion

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Biquaternion

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<Complex<f64>> for Biquaternion

Source§

type Output = Biquaternion

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Complex<f64>) -> Self

Performs the / operation. Read more
Source§

impl Div<f64> for Biquaternion

Source§

type Output = Biquaternion

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self

Performs the / operation. Read more
Source§

impl DivAssign<f64> for Biquaternion

Source§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
Source§

impl From<[Complex<f64>; 4]> for Biquaternion

Source§

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<Complex<f64>> for Biquaternion

Source§

type Output = Biquaternion

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Complex<f64>) -> Self

Performs the * operation. Read more
Source§

impl Mul<f64> for Biquaternion

Source§

type Output = Biquaternion

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self

Performs the * operation. Read more
Source§

impl MulAssign<f64> for Biquaternion

Source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
Source§

impl PartialEq for Biquaternion

Source§

fn eq(&self, other: &Biquaternion) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Biquaternion

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub for Biquaternion

Source§

type Output = Biquaternion

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl SubAssign for Biquaternion

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl Copy for Biquaternion

Source§

impl StructuralPartialEq for Biquaternion

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,