quaternion

MoonBit Quaternion Library

quaternion
math
moon add Luna-Flow/quaternion@0.1.3
Download zip
Author
Version
0.1.3
License
Apache-2.0
Last updated
9 months ago
Downloads
28

Dependencies

README

#Quaternion

Luna-Flow library for working with quaternions, which are extensions of complex numbers useful for 3D rotations and orientations. Provides arithmetic operations, normalization, rotation, and other quaternion utilities.

#Reference

#
DoubleConvert

pub trait DoubleConvert {
to_double(Self) -> Double
from_double(Double) -> Self
}

#
Quaternion

type Quaternion[T]
Quaternion struct with real component r and vector components vec
impl Conjugate for Quaternion[T]
impl Add for Quaternion[T]
impl Div for Quaternion[T]
impl Eq for Quaternion[T]
impl Hash for Quaternion[T]
impl Mul for Quaternion[T]
impl Neg for Quaternion[T]
impl Show for Quaternion[T]
impl Sub for Quaternion[T]

#
Quaternion::dot

fn[T : Mul + Add] Quaternion::dot(self : Quaternion[T], other : Quaternion[T]) -> T

Computes the dot product of two quaternions.

#
Quaternion::from_vec

fn[T] Quaternion::from_vec(v : (T, T, T, T)) -> Quaternion[T]

Creates a quaternion from a 4-component vector (scalar, i, j, k).

#
Quaternion::map

fn[T, U] Quaternion::map(self : Quaternion[T], f : (T) -> U) -> Quaternion[U]

Applies a function to each component of the quaternion.

#
Quaternion::pow_by_T

If the exponent is of type Int, please use the pow_by_int function. Computes the power of a quaternion. Like q^(2.5)

#
Quaternion::pow_by_int

If the exponent isn't of type Int, please use the pow_by_T function to calculate. Computes the power of a quaternion. Like q^2

#
Quaternion::scale

fn[T : Mul] Quaternion::scale(self : Quaternion[T], s : T) -> Quaternion[T]

Scales the quaternion by a scalar value.

#
Quaternion::square_len

fn[T : Mul + Add] Quaternion::square_len(self : Quaternion[T]) -> T

Computes the squared length (norm) of the quaternion.

#
Quaternion::to_euler

Converts the quaternion to Euler angles (roll, pitch, yaw) in different Orders, all measured in radians. 'roll' : the rotation angle around the X-axis 'pitch' : the rotation angle around the Y-axis 'yaw' : the rotation angle around the Z-axis 'order' in {"XYZ", "XZY", "YZX", "ZYX"} 'external' is 'true', Result will be External rotation. Otherwise, Result will be Internal rotation

#
Quaternion::to_euler_external_XYZ

Converts the quaternion to Euler angles (roll, pitch, yaw) in external XYZ-Order

#
Quaternion::to_euler_external_XZY

Converts the quaternion to Euler angles (roll, pitch, yaw) in external XZY-Order (active rotation)

#
Quaternion::to_euler_external_YZX

Converts the quaternion to Euler angles (roll, pitch, yaw) in external YZX-Order

#
Quaternion::to_euler_external_ZYX

Converts the quaternion to Euler angles (roll, pitch, yaw) in external ZYX-Order

#
Quaternion::to_euler_internal_XYZ

Converts the quaternion to Euler angles (roll, pitch, yaw) in internal XZY-Order

#
Quaternion::to_euler_internal_XZY

Converts the quaternion to Euler angles (roll, pitch, yaw) in internal XZY-Order

#
Quaternion::to_euler_internal_YZX

Converts the quaternion to Euler angles (roll, pitch, yaw) in internal XZY-Order

#
Quaternion::to_euler_internal_ZYX

Converts the quaternion to Euler angles (roll, pitch, yaw) in internal XZY-Order

#
from_axis_angle

fn[T : DoubleConvert + Mul + Add + Div] from_axis_angle(axis : (T, T, T), angle : T) -> Quaternion[T]

Creates a quaternion from an axis and angle.

#
from_euler

fn[T : DoubleConvert + Mul + Add + Sub] from_euler(roll : T, pitch : T, yaw : T, order? : String) -> Quaternion[T]

Converts the Euler angles to the quaternion (x, ai, bj, ck) In different Orders 'order' in {"XYZ", "YXZ", "ZYX", "YZX", "ZXY"}

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io