Liking cljdoc? Tell your friends :D

fastmath.quaternion

Operations for quaternions.

Quaternions extend complex numbers and are widely used in fields like 3D graphics and physics for representing rotations.

In fastmath, quaternions are represented as 4-dimensional vectors ([[Vec4]]) where the components correspond to the scalar part and the three imaginary parts ($i$, $j$, $k$): $q = a + bi + cj + dk$ is (Vec4. a b c d).

The namespace provides functions for creating quaternions, accessing scalar and vector parts, predicates (e.g., real?, zero?, inf?, nan?), and fundamental properties (magnitude, argument, normalization).

A comprehensive set of operations is included:

  • Arithmetic: Addition, subtraction, multiplication, division, negation, square, reciprocal, scaling, conjugation.
  • Transcendental Functions: Extensions of standard complex functions like exponential, logarithm, power, trigonometric, hyperbolic functions, and their inverses.
  • Rotations: Functions for creating rotation quaternions, rotating 3D vectors (rotate), spherical linear interpolation (SLERP), and conversions between quaternions, Euler angles (ZYX body 3-2-1 and z-y'-x''), and rotation matrices.

The implementation correctly handles floating-point special values, including ##Inf and ##NaN.

Operations for quaternions.

Quaternions extend complex numbers and are widely used in fields like 3D graphics and physics for representing rotations.

In `fastmath`, quaternions are represented as 4-dimensional vectors ([[Vec4]]) where the components correspond to the scalar part and the three imaginary parts ($i$, $j$, $k$): $q = a + bi + cj + dk$ is `(Vec4. a b c d)`.

The namespace provides functions for creating quaternions, accessing scalar and vector parts, predicates (e.g., [[real?]], [[zero?]], [[inf?]], [[nan?]]), and fundamental properties (magnitude, argument, normalization).

A comprehensive set of operations is included:
- **Arithmetic:** Addition, subtraction, multiplication, division, negation, square, reciprocal, scaling, conjugation.
- **Transcendental Functions:** Extensions of standard complex functions like exponential, logarithm, power, trigonometric, hyperbolic functions, and their inverses.
- **Rotations:** Functions for creating rotation quaternions, rotating 3D vectors ([[rotate]]), spherical linear interpolation (SLERP), and conversions between quaternions, Euler angles (ZYX body 3-2-1 and z-y'-x''), and rotation matrices.

The implementation correctly handles floating-point special values, including `##Inf` and `##NaN`.
raw docstring

-Iclj

0-1i+0j+0k

0-1i+0j+0k
sourceraw docstring

-Jclj

0+0i-1j+0k

0+0i-1j+0k
sourceraw docstring

-Kclj

0+0i+0j-1k

0+0i+0j-1k
sourceraw docstring

acosclj

(acos q)

acos(q)

acos(q)
sourceraw docstring

acoshclj

(acosh q)

acosh(q)

acosh(q)
sourceraw docstring

acotclj

(acot q)

acot(q)

acot(q)
sourceraw docstring

acothclj

(acoth q)

acoth(q)

acoth(q)
sourceraw docstring

acscclj

(acsc q)

acsc(q)

acsc(q)
sourceraw docstring

acschclj

(acsch q)

acsch(q)

acsch(q)
sourceraw docstring

addclj

(add q1 q2)

Sum of two quaternions

Sum of two quaternions
sourceraw docstring

addsclj

(adds q1 s)

Adds scalar to a quaternion

Adds scalar to a quaternion
sourceraw docstring

argclj

(arg quaternion)

Argument of quaternion, atan2(|vector(q)|, re(q))

Argument of quaternion, atan2(|vector(q)|, re(q))
sourceraw docstring

asecclj

(asec q)

asec(q)

asec(q)
sourceraw docstring

asechclj

(asech q)

asech(q)

asech(q)
sourceraw docstring

asinclj

(asin q)

asin(q)

asin(q)
sourceraw docstring

asinhclj

(asinh q)

asinh(q)

asinh(q)
sourceraw docstring

atanclj

(atan q)

atan(q)

atan(q)
sourceraw docstring

atanhclj

(atanh q)

atanh(q)

atanh(q)
sourceraw docstring

complex->quaternionclj

(complex->quaternion z)

Create quaternion from complex number

Create quaternion from complex number
sourceraw docstring

conjugateclj

(conjugate quaternion)

Conjugate of the quaternion

Conjugate of the quaternion
sourceraw docstring

cosclj

(cos q)

cos(q)

cos(q)
sourceraw docstring

coshclj

(cosh q)

cosh(q)

cosh(q)
sourceraw docstring

cotclj

(cot q)

cot(q)

cot(q)
sourceraw docstring

cothclj

(coth q)

coth(q)

coth(q)
sourceraw docstring

cscclj

(csc q)

csc(q)

csc(q)
sourceraw docstring

cschclj

(csch q)

csch(q)

csch(q)
sourceraw docstring

delta-eqclj

(delta-eq q1 q2)
(delta-eq q1 q2 accuracy)

Compare quaternions with given accuracy (10e-6 by default)

Compare quaternions with given accuracy (10e-6 by default)
sourceraw docstring

divclj

(div q1 q2)

Division two quaternions

Division two quaternions
sourceraw docstring

ensure-quaternionclj

(ensure-quaternion q)

Convert possible number, complex number to a quaternion

Convert possible number, complex number to a quaternion
sourceraw docstring

expclj

(exp q)

exp(q)

exp(q)
sourceraw docstring

from-anglesclj

(from-angles [x y z])
(from-angles x y z)

Converts Tait–Bryan angles (z-y′-x'' intrinsic rotation sequence) to a quaternion.

The angles [x y z] correspond to rotations around the local (body) x-axis, followed by the intermediate local y'-axis, and finally the local z''-axis.

Parameters:

  • x: Rotation around the x-axis (radians).
  • y: Rotation around the y'-axis (radians).
  • z: Rotation around the z''-axis (radians).

Can accept individual double values or a Vec3 containing [x y z].

Returns A quaternion Vec4 representing the rotation.

Converts Tait–Bryan angles (z-y′-x'' intrinsic rotation sequence) to a quaternion.

The angles `[x y z]` correspond to rotations around the local (body) x-axis, followed by the intermediate local y'-axis, and finally the local z''-axis.

Parameters:

* `x`: Rotation around the x-axis (radians).
* `y`: Rotation around the y'-axis (radians).
* `z`: Rotation around the z''-axis (radians).

Can accept individual double values or a `Vec3` containing `[x y z]`.

Returns A quaternion `Vec4` representing the rotation.
sourceraw docstring

from-eulerclj

(from-euler [roll pitch yaw])
(from-euler roll pitch yaw)

Converts Euler angles (ZYX body 3-2-1 convention) to a quaternion.

The rotation sequence is intrinsic Z-Y'-X'' (yaw, pitch, roll), applied to the body frame. The order of input parameters or vector components is [roll pitch yaw].

Parameters:

  • roll: Rotation around the x-axis (radians), expected range [-pi, pi].
  • pitch: Rotation around the y'-axis (radians), expected range [-pi/2, pi/2].
  • yaw: Rotation around the z''-axis (radians), expected range [-pi, pi].

Can accept individual double values or a Vec3 containing [roll pitch yaw].

Returns A quaternion Vec4 representing the rotation.

Converts Euler angles (ZYX body 3-2-1 convention) to a quaternion.

The rotation sequence is intrinsic Z-Y'-X'' (yaw, pitch, roll), applied to the body frame.
The order of input parameters or vector components is [roll pitch yaw].

Parameters:

* `roll`: Rotation around the x-axis (radians), expected range `[-pi, pi]`.
* `pitch`: Rotation around the y'-axis (radians), expected range `[-pi/2, pi/2]`.
* `yaw`: Rotation around the z''-axis (radians), expected range `[-pi, pi]`.

Can accept individual double values or a `Vec3` containing [roll pitch yaw].

Returns A quaternion `Vec4` representing the rotation.
sourceraw docstring

from-rotation-matrixclj

(from-rotation-matrix m)

Converts a 3x3 rotation matrix to a quaternion.

Takes a [[Mat3x3]] rotation matrix as input. Returns a [[Vec4]] representing the quaternion that represents the same rotation.

The resulting quaternion is a unit quaternion if the input matrix is a valid rotation matrix. The method handles numerical stability and normalization.

Converts a 3x3 rotation matrix to a quaternion.

Takes a [[Mat3x3]] rotation matrix as input.
Returns a [[Vec4]] representing the quaternion that represents the same rotation.

The resulting quaternion is a unit quaternion if the input matrix is a valid rotation matrix. The method handles numerical stability and normalization.
sourceraw docstring

Iclj

0+1i+0j+0k

0+1i+0j+0k
sourceraw docstring

im-iclj

(im-i quaternion)

Return i imaginary part

Return i imaginary part
sourceraw docstring

im-jclj

(im-j quaternion)

Return j imaginary part

Return j imaginary part
sourceraw docstring

im-kclj

(im-k quaternion)

Return k imaginary part

Return k imaginary part
sourceraw docstring

imaginary?clj

(imaginary? quaternion)

Is q is a pure imaginary number?

Is q is a pure imaginary number?
sourceraw docstring

inf?clj

(inf? quaternion)

Is infinitive?

Is infinitive?
sourceraw docstring

invalid?clj

(invalid? z)

Is NaN or Inf?

Is NaN or Inf?
sourceraw docstring

Jclj

0+0i+1j+0k

0+0i+1j+0k
sourceraw docstring

Kclj

0+0i+0j+1k

0+0i+0j+1k
sourceraw docstring

logclj

(log q)

log(q)

log(q)
sourceraw docstring

logbclj

(logb quaternion b)

log with base b

log with base b
sourceraw docstring

multclj

(mult q1 q2)

Multiplication of two quaternions.

Multiplication of two quaternions.
sourceraw docstring

nan?clj

(nan? quaternion)

Is NaN?

Is NaN?
sourceraw docstring

negclj

(neg quaternion)

Negation of the quaternion.

Negation of the quaternion.
sourceraw docstring

normclj

(norm quaternion)

Norm of the quaternion, length of the vector

Norm of the quaternion, length of the vector
sourceraw docstring

normalizeclj

(normalize quaternion)

Normalize quaternion, unit of quaternion.

Normalize quaternion, unit of quaternion.
sourceraw docstring

ONEclj

1+0i+0j+0k

1+0i+0j+0k
sourceraw docstring

powclj

(pow q p)

Quaternion power

Quaternion power
sourceraw docstring

qsgnclj

(qsgn q)
(qsgn re im-i im-j im-k)

Computes the signum of a quaternion.

Returns 0.0 for the zero quaternion ($0+0i+0j+0k$). For any other quaternion, returns the sign of its scalar part.

Computes the signum of a quaternion.

Returns `0.0` for the zero quaternion ($0+0i+0j+0k$). For any other quaternion, returns the sign of its scalar part.
sourceraw docstring

quaternionclj

(quaternion a)
(quaternion scalar [i j k])
(quaternion a b c d)

Create quaternion from individual values or scalar and vector parts, reprezented as Vec4.

Create quaternion from individual values or scalar and vector parts, reprezented as `Vec4`.
sourceraw docstring

reclj

(re quaternion)

Returns scalar part of quaternion

Returns scalar part of quaternion
sourceraw docstring

real?clj

(real? quaternion)

Is q is a real number?

Is q is a real number?
sourceraw docstring

reciprocalclj

(reciprocal quaternion)

Reciprocal of the quaternion

Reciprocal of the quaternion
sourceraw docstring

rotateclj

(rotate in rotq)
(rotate in angle u)

Rotate 3d in vector around axis u, the same as fastmath.vector/axis-rotate.

Rotate 3d `in` vector around axis `u`, the same as `fastmath.vector/axis-rotate`.
sourceraw docstring

rotation-quaternionclj

(rotation-quaternion angle u)

Creates a unit quaternion representing a rotation.

The rotation is defined by an angle (in radians) and a 3D vector u specifying the axis of rotation. The axis vector u is normalized internally to ensure a unit quaternion result.

Parameters:

  • angle: The rotation angle in radians (double).
  • u: The axis of rotation (Vec3). It will be normalized before use.

Returns A unit quaternion (Vec4) representing the rotation.

Creates a unit quaternion representing a rotation.

The rotation is defined by an `angle` (in radians) and a 3D vector `u`
specifying the axis of rotation. The axis vector `u` is normalized
internally to ensure a unit quaternion result.

Parameters:
 
* `angle`: The rotation angle in radians (double).
* `u`: The axis of rotation (Vec3). It will be normalized before use.

Returns A unit quaternion (Vec4) representing the rotation.
sourceraw docstring

scalarclj

(scalar quaternion)

Returns scalar part of quaternion, double

Returns scalar part of quaternion, double
sourceraw docstring

scaleclj

(scale quaternion scale)

Scale the quaternion

Scale the quaternion
sourceraw docstring

secclj

(sec q)

sec(q)

sec(q)
sourceraw docstring

sechclj

(sech q)

sech(q)

sech(q)
sourceraw docstring

sinclj

(sin q)

sin(q)

sin(q)
sourceraw docstring

sinhclj

(sinh q)

sinh(q)

sinh(q)
sourceraw docstring

slerpclj

(slerp q1 q2 t)

Performs Spherical Linear Interpolation (SLERP) between two quaternions.

SLERP interpolates along the shortest arc on the unit sphere, providing smooth interpolation between rotations represented by unit quaternions.

Parameters:

  • q1: The starting quaternion (Vec4).
  • q2: The ending quaternion (Vec4).
  • t: The interpolation parameter (double). Should be in the range [0.0, 1.0].
    • If t=0.0, returns q1.
    • If t=1.0, returns q2.
    • For 0.0 < t < 1.0, returns an interpolated quaternion. The parameter t is internally constrained to [0.0, 1.0].

Note: This function is typically used with unit quaternions for rotation interpolation.

Performs Spherical Linear Interpolation (SLERP) between two quaternions.

SLERP interpolates along the shortest arc on the unit sphere, providing smooth
interpolation between rotations represented by unit quaternions.

Parameters:

* `q1`: The starting quaternion (Vec4).
* `q2`: The ending quaternion (Vec4).
* `t`: The interpolation parameter (double). Should be in the range [0.0, 1.0].
     - If `t=0.0`, returns `q1`.
     - If `t=1.0`, returns `q2`.
     - For `0.0 < t < 1.0`, returns an interpolated quaternion.
     The parameter `t` is internally constrained to [0.0, 1.0].

Note: This function is typically used with unit quaternions for rotation interpolation.
sourceraw docstring

sqclj

(sq quaternion)

Square of the quaternion.

Square of the quaternion.
sourceraw docstring

sqrtclj

(sqrt q)

sqrt(q)

sqrt(q)
sourceraw docstring

subclj

(sub q1 q2)

Difference of two quaternions

Difference of two quaternions
sourceraw docstring

tanclj

(tan q)

tan(q)

tan(q)
sourceraw docstring

tanhclj

(tanh q)

tanh(q)

tanh(q)
sourceraw docstring

to-anglesclj

(to-angles q)

Converts a quaternion q to Tait–Bryan angles using the z-y′-x'' intrinsic rotation sequence. The input quaternion is normalized before calculation. Returns a Vec3 representing the angles [x y z]. These angles correspond to rotations around the local (body) x-axis, followed by the intermediate local y'-axis, and finally the local z''-axis. Output angles are typically in the range [-pi, pi] for x and z, and [-pi/2, pi/2] for y.

Converts a quaternion `q` to Tait–Bryan angles using the z-y′-x'' intrinsic rotation sequence.
The input quaternion is normalized before calculation.
Returns a `Vec3` representing the angles `[x y z]`. These angles correspond to rotations around the local (body) x-axis, followed by the intermediate local y'-axis, and finally the local z''-axis.
Output angles are typically in the range `[-pi, pi]` for x and z, and `[-pi/2, pi/2]` for y.
sourceraw docstring

to-eulerclj

(to-euler q)

Converts a quaternion q to ZYX (body 3-2-1) Euler angles. The input quaternion is normalized before calculation. Returns a Vec3 representing the angles [roll pitch yaw]. Roll is the angle around the x-axis, pitch around the y'-axis, and yaw around the z''-axis. Output angles are typically in [-pi, pi] for roll/yaw and [-pi/2, pi/2] for pitch.

Converts a quaternion `q` to ZYX (body 3-2-1) Euler angles.
The input quaternion is normalized before calculation.
Returns a `Vec3` representing the angles `[roll pitch yaw]`.
Roll is the angle around the x-axis, pitch around the y'-axis, and yaw around the z''-axis.
Output angles are typically in [-pi, pi] for roll/yaw and [-pi/2, pi/2] for pitch.
sourceraw docstring

to-rotation-matrixclj

(to-rotation-matrix q)

Converts a quaternion to a 3x3 rotation matrix.

The input quaternion is normalized internally to ensure a valid rotation matrix. Unit quaternions are used to represent rotations.

Parameters:

  • q: The quaternion (Vec4) to convert.

Returns A 3x3 rotation matrix (Mat3x3).

Converts a quaternion to a 3x3 rotation matrix.

The input quaternion is normalized internally to ensure a valid rotation matrix.
Unit quaternions are used to represent rotations.

Parameters:

* `q`: The quaternion (Vec4) to convert.

Returns A 3x3 rotation matrix (Mat3x3).
sourceraw docstring

valid?clj

(valid? z)

Is valid complex (not NaN or Inf)?

Is valid complex (not NaN or Inf)?
sourceraw docstring

vectorclj

(vector quaternion)

Returns vector part of quaternion, Vec3 type

Returns vector part of quaternion, `Vec3` type
sourceraw docstring

ZEROclj

0+0i+0j+0k

0+0i+0j+0k
sourceraw docstring

zero?clj

(zero? quaternion)

Is zero?

Is zero?
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close