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:
add, sub and mult accept any number of arguments.rotate), interpolation (slerp, nlerp), and conversions between quaternions, Euler angles (ZYX body 3-2-1 and z-y'-x''), axis and angle, and rotation matrices.The transcendental functions are computed with the complex functions of fastmath.complex applied to the scalar part and the magnitude of the vector part, so they share their branch cuts and accuracy. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis (for example the square root of -4 is 2i).
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 (not commutative), division, negation, square, reciprocal, scaling, conjugation, dot product. Functions accept numbers and complex numbers where a quaternion is expected, `add`, `sub` and `mult` accept any number of arguments. - **Transcendental Functions:** Extensions of standard complex functions like exponential, logarithm, power, trigonometric, hyperbolic functions, and their inverses. - **Rotations:** Functions for creating rotation quaternions (from an axis and an angle, from two vectors), rotating 3D vectors ([[rotate]]), interpolation ([[slerp]], [[nlerp]]), and conversions between quaternions, Euler angles (ZYX body 3-2-1 and z-y'-x''), axis and angle, and rotation matrices. The transcendental functions are computed with the complex functions of `fastmath.complex` applied to the scalar part and the magnitude of the vector part, so they share their branch cuts and accuracy. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis (for example the square root of `-4` is `2i`). The implementation correctly handles floating-point special values, including `##Inf` and `##NaN`.
(acos quaternion)Inverse cosine of the quaternion q.
The value is computed with fastmath.complex/acos applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/acos.
Inverse cosine of the quaternion `q`. The value is computed with [[fastmath.complex/acos]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/acos]].
(acosh quaternion)Inverse hyperbolic cosine of the quaternion q.
The value is computed with fastmath.complex/acosh applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/acosh.
Inverse hyperbolic cosine of the quaternion `q`. The value is computed with [[fastmath.complex/acosh]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/acosh]].
(acot quaternion)Inverse cotangent of the quaternion q.
The value is computed with fastmath.complex/acot applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/acot.
Inverse cotangent of the quaternion `q`. The value is computed with [[fastmath.complex/acot]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/acot]].
(acoth quaternion)Inverse hyperbolic cotangent of the quaternion q.
The value is computed with fastmath.complex/acoth applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/acoth.
Inverse hyperbolic cotangent of the quaternion `q`. The value is computed with [[fastmath.complex/acoth]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/acoth]].
(acsc quaternion)Inverse cosecant of the quaternion q.
The value is computed with fastmath.complex/acsc applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/acsc.
Inverse cosecant of the quaternion `q`. The value is computed with [[fastmath.complex/acsc]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/acsc]].
(acsch quaternion)Inverse hyperbolic cosecant of the quaternion q.
The value is computed with fastmath.complex/acsch applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/acsch.
Inverse hyperbolic cosecant of the quaternion `q`. The value is computed with [[fastmath.complex/acsch]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/acsch]].
(add)(add q)(add q1 q2)(add q1 q2 & more)Sum of quaternions.
Arguments can be quaternions, complex numbers or numbers. Without arguments returns 0, with one argument the argument as a quaternion. More than two arguments are added from left to right.
Sum of quaternions. Arguments can be quaternions, complex numbers or numbers. Without arguments returns `0`, with one argument the argument as a quaternion. More than two arguments are added from left to right. See also [[adds]], [[sub]], [[mult]].
(adds q1 s)Adds the real number s to the scalar part of the quaternion q1.
Adds the real number `s` to the scalar part of the quaternion `q1`.
(arg quaternion)Argument of the quaternion, atan2(|vector(q)|, re(q)), in the range [0, pi].
See also norm, to-axis-angle.
Argument of the quaternion, `atan2(|vector(q)|, re(q))`, in the range `[0, pi]`. See also [[norm]], [[to-axis-angle]].
(asec quaternion)Inverse secant of the quaternion q.
The value is computed with fastmath.complex/asec applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/asec.
Inverse secant of the quaternion `q`. The value is computed with [[fastmath.complex/asec]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/asec]].
(asech quaternion)Inverse hyperbolic secant of the quaternion q.
The value is computed with fastmath.complex/asech applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/asech.
Inverse hyperbolic secant of the quaternion `q`. The value is computed with [[fastmath.complex/asech]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/asech]].
(asin quaternion)Inverse sine of the quaternion q.
The value is computed with fastmath.complex/asin applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/asin.
Inverse sine of the quaternion `q`. The value is computed with [[fastmath.complex/asin]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/asin]].
(asinh quaternion)Inverse hyperbolic sine of the quaternion q.
The value is computed with fastmath.complex/asinh applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/asinh.
Inverse hyperbolic sine of the quaternion `q`. The value is computed with [[fastmath.complex/asinh]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/asinh]].
(atan quaternion)Inverse tangent of the quaternion q.
The value is computed with fastmath.complex/atan applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/atan.
Inverse tangent of the quaternion `q`. The value is computed with [[fastmath.complex/atan]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/atan]].
(atanh quaternion)Inverse hyperbolic tangent of the quaternion q.
The value is computed with fastmath.complex/atanh applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/atanh.
Inverse hyperbolic tangent of the quaternion `q`. The value is computed with [[fastmath.complex/atanh]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/atanh]].
(complex->quaternion z)Creates a quaternion from the complex number z (a [[Vec2]]), a+bi becomes a+bi+0j+0k.
Creates a quaternion from the complex number `z` (a [[Vec2]]), `a+bi` becomes `a+bi+0j+0k`.
(conjugate quaternion)Conjugate of the quaternion, a-bi-cj-dk.
Conjugate of the quaternion, `a-bi-cj-dk`.
(cos quaternion)Cosine of the quaternion q.
The value is computed with fastmath.complex/cos applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/cos.
Cosine of the quaternion `q`. The value is computed with [[fastmath.complex/cos]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/cos]].
(cosh quaternion)Hyperbolic cosine of the quaternion q.
The value is computed with fastmath.complex/cosh applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/cosh.
Hyperbolic cosine of the quaternion `q`. The value is computed with [[fastmath.complex/cosh]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/cosh]].
(cot quaternion)Cotangent of the quaternion q.
The value is computed with fastmath.complex/cot applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/cot.
Cotangent of the quaternion `q`. The value is computed with [[fastmath.complex/cot]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/cot]].
(coth quaternion)Hyperbolic cotangent of the quaternion q.
The value is computed with fastmath.complex/coth applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/coth.
Hyperbolic cotangent of the quaternion `q`. The value is computed with [[fastmath.complex/coth]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/coth]].
(csc quaternion)Cosecant of the quaternion q.
The value is computed with fastmath.complex/csc applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/csc.
Cosecant of the quaternion `q`. The value is computed with [[fastmath.complex/csc]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/csc]].
(csch quaternion)Hyperbolic cosecant of the quaternion q.
The value is computed with fastmath.complex/csch applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/csch.
Hyperbolic cosecant of the quaternion `q`. The value is computed with [[fastmath.complex/csch]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/csch]].
(delta-eq q1 q2)(delta-eq q1 q2 abs-tol)(delta-eq q1 q2 abs-tol rel-tol)Checks whether quaternions q1 and q2 are equal within a tolerance. Returns true or false.
The tolerance is applied to the length of the difference, |q1 - q2|, not to each part separately:
(delta-eq q1 q2) - absolute tolerance 1.0e-6,(delta-eq q1 q2 abs-tol) - the quaternions are equal when |q1 - q2| <= abs-tol,(delta-eq q1 q2 abs-tol rel-tol) - the quaternions are equal when |q1 - q2| < max(abs-tol, rel-tol * max(|q1|, |q2|)).A part that is NaN makes the result false. Note that q and -q describe the same rotation but they are not equal. Delegates to fastmath.vector/delta-eq. See also norm.
Checks whether quaternions `q1` and `q2` are equal within a tolerance. Returns `true` or `false`. The tolerance is applied to the length of the difference, `|q1 - q2|`, not to each part separately: * `(delta-eq q1 q2)` - absolute tolerance `1.0e-6`, * `(delta-eq q1 q2 abs-tol)` - the quaternions are equal when `|q1 - q2| <= abs-tol`, * `(delta-eq q1 q2 abs-tol rel-tol)` - the quaternions are equal when `|q1 - q2| < max(abs-tol, rel-tol * max(|q1|, |q2|))`. A part that is `NaN` makes the result `false`. Note that `q` and `-q` describe the same rotation but they are not equal. Delegates to [[fastmath.vector/delta-eq]]. See also [[norm]].
(div q1 q2)Division of quaternions, q1 * q2^-1 (the divisor is applied from the right).
Arguments can be quaternions, complex numbers or numbers. See also mult, reciprocal.
Division of quaternions, `q1 * q2^-1` (the divisor is applied from the right). Arguments can be quaternions, complex numbers or numbers. See also [[mult]], [[reciprocal]].
(dot q1 q2)Dot product of quaternions treated as 4-dimensional vectors, a1*a2 + b1*b2 + c1*c2 + d1*d2.
For unit quaternions it is the cosine of half of the angle between the rotations, the sign shows the shortest arc (see slerp). Arguments can be quaternions, complex numbers or numbers.
Dot product of quaternions treated as 4-dimensional vectors, `a1*a2 + b1*b2 + c1*c2 + d1*d2`. For unit quaternions it is the cosine of half of the angle between the rotations, the sign shows the shortest arc (see [[slerp]]). Arguments can be quaternions, complex numbers or numbers.
(ensure-quaternion q)Converts q to a quaternion ([[Vec4]]). The arithmetic functions of this namespace use it for their arguments.
Accepted values:
Complex, a+bi becomes a+bi+0j+0k (see complex->quaternion)Quaternion[a b c d] (see seq->quaternion)double array of length 4Throws ex-info for any other value, ex-data holds :reason and its details: :sequence-size with :count (a sequence without exactly four elements, also a 3d vector), :non-number with :q (a four element sequence with a non-number element), :array-size with :length (a double array of other length) or :unknown-type with :type (the class of the value).
Converts `q` to a quaternion ([[Vec4]]). The arithmetic functions of this namespace use it for their arguments. Accepted values: - a [[Vec4]], returned as is - a number, becomes a quaternion with the scalar part only - a complex number ([[Vec2]]) or an Apache Commons Math `Complex`, `a+bi` becomes `a+bi+0j+0k` (see [[complex->quaternion]]) - an Apache Commons Math `Quaternion` - a sequence of exactly four numbers `[a b c d]` (see [[seq->quaternion]]) - a `double` array of length 4 Throws `ex-info` for any other value, ex-data holds `:reason` and its details: `:sequence-size` with `:count` (a sequence without exactly four elements, also a 3d vector), `:non-number` with `:q` (a four element sequence with a non-number element), `:array-size` with `:length` (a `double` array of other length) or `:unknown-type` with `:type` (the class of the value).
(exp quaternion)Exponential of the quaternion q.
The value is computed with fastmath.complex/exp applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/exp.
Exponential of the quaternion `q`. The value is computed with [[fastmath.complex/exp]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/exp]].
(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].
The rotation matrix of the result is Rx(x) Ry(y) Rz(z), the same as fastmath.matrix/rotation-matrix-3d. Returns A quaternion Vec4 representing the rotation (a unit quaternion).
See also to-angles, from-euler.
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]`. The rotation matrix of the result is `Rx(x) Ry(y) Rz(z)`, the same as [[fastmath.matrix/rotation-matrix-3d]]. Returns A quaternion `Vec4` representing the rotation (a unit quaternion). See also [[to-angles]], [[from-euler]].
(from-axis-angle angle axis)Creates a unit quaternion representing a rotation by angle (radians) around the axis.
Alias of rotation-quaternion, the arguments have the same order. The axis is normalized, a zero axis throws ex-info. See also to-axis-angle.
Creates a unit quaternion representing a rotation by `angle` (radians) around the `axis`. Alias of [[rotation-quaternion]], the arguments have the same order. The axis is normalized, a zero axis throws `ex-info`. See also [[to-axis-angle]].
(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 (a unit quaternion).
See also to-euler, from-angles.
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 (a unit quaternion). See also [[to-euler]], [[from-angles]].
(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. A rotation corresponds to two quaternions, q and -q; the sign of the result is not defined (the sign of the scalar part is not fixed).
See also to-rotation-matrix.
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. A rotation corresponds to two quaternions, `q` and `-q`; the sign of the result is not defined (the sign of the scalar part is not fixed). See also [[to-rotation-matrix]].
(from-two-vectors u v)Creates a unit quaternion representing the shortest rotation which takes the direction of the vector u to the direction of the vector v.
The lengths of the vectors do not matter (also subnormal ones). For opposite directions the rotation is by pi around some axis perpendicular to u. Throws ex-info when any vector is the zero vector or has an infinite or NaN part (a finite vector is fine also when its length is not representable).
See also rotate, rotation-quaternion.
Creates a unit quaternion representing the shortest rotation which takes the direction of the vector `u` to the direction of the vector `v`. The lengths of the vectors do not matter (also subnormal ones). For opposite directions the rotation is by `pi` around some axis perpendicular to `u`. Throws `ex-info` when any vector is the zero vector or has an infinite or `NaN` part (a finite vector is fine also when its length is not representable). See also [[rotate]], [[rotation-quaternion]].
(im-i quaternion)Returns the i imaginary part as a double.
Returns the `i` imaginary part as a double.
(im-j quaternion)Returns the j imaginary part as a double.
Returns the `j` imaginary part as a double.
(im-k quaternion)Returns the k imaginary part as a double.
Returns the `k` imaginary part as a double.
(imaginary? quaternion)Returns true when the scalar part of the quaternion is zero, a pure imaginary quaternion (the zero quaternion included).
Returns `true` when the scalar part of the quaternion is zero, a pure imaginary quaternion (the zero quaternion included).
(inf? quaternion)Returns true when any part of the quaternion is infinite (also when another part is NaN).
Returns `true` when any part of the quaternion is infinite (also when another part is `NaN`).
(invalid? z)Returns true when the quaternion has an infinite or NaN part. See also valid?.
Returns `true` when the quaternion has an infinite or `NaN` part. See also [[valid?]].
(inverse quaternion)Multiplicative inverse of the quaternion, alias of reciprocal. For a unit quaternion (a rotation) it is the conjugate, the opposite rotation.
Multiplicative inverse of the quaternion, alias of [[reciprocal]]. For a unit quaternion (a rotation) it is the conjugate, the opposite rotation.
(log quaternion)Principal natural logarithm of the quaternion q.
The value is computed with fastmath.complex/log applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/log.
Principal natural logarithm of the quaternion `q`. The value is computed with [[fastmath.complex/log]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/log]].
(logb quaternion b)Logarithm of the quaternion q with the base b, log(q) / log(b).
Both arguments can be quaternions, complex numbers or numbers. See also log.
Logarithm of the quaternion `q` with the base `b`, `log(q) / log(b)`. Both arguments can be quaternions, complex numbers or numbers. See also [[log]].
(mult)(mult q)(mult q1 q2)(mult q1 q2 & more)Product of quaternions (the Hamilton product).
The multiplication is not commutative, i*j = k and j*i = -k. Arguments can be quaternions, complex numbers or numbers. Without arguments returns 1, with one argument the argument as a quaternion. More than two arguments are multiplied from left to right: (mult a b c) is (a*b)*c.
Product of quaternions (the Hamilton product). The multiplication is not commutative, `i*j = k` and `j*i = -k`. Arguments can be quaternions, complex numbers or numbers. Without arguments returns `1`, with one argument the argument as a quaternion. More than two arguments are multiplied from left to right: `(mult a b c)` is `(a*b)*c`. See also [[div]], [[sq]], [[scale]].
(nan? quaternion)Returns true when any part of the quaternion is NaN.
Returns `true` when any part of the quaternion is `NaN`.
(neg quaternion)Negation of the quaternion, -q.
Negation of the quaternion, `-q`.
(nlerp q1 q2 t)Normalized linear interpolation between the unit quaternions q1 and q2.
It follows the shortest arc (when dot(q1, q2) is negative q2 is negated), the result is normalized. It is faster than slerp and the same on the path, the angular velocity is not constant. t is constrained to [0, 1], NaN gives NaN.
Normalized linear interpolation between the unit quaternions `q1` and `q2`. It follows the shortest arc (when `dot(q1, q2)` is negative `q2` is negated), the result is normalized. It is faster than [[slerp]] and the same on the path, the angular velocity is not constant. `t` is constrained to `[0, 1]`, `NaN` gives `NaN`. See also [[slerp]], [[dot]].
(norm quaternion)Norm (magnitude, length) of the quaternion, sqrt(a^2+b^2+c^2+d^2), as a double.
The value is correct over the whole range of doubles. Note that fastmath.complex/norm is the squared magnitude.
See also normalize, fastmath.vector/magsq.
Norm (magnitude, length) of the quaternion, `sqrt(a^2+b^2+c^2+d^2)`, as a double. The value is correct over the whole range of doubles. Note that [[fastmath.complex/norm]] is the squared magnitude. See also [[normalize]], [[fastmath.vector/magsq]].
(normalize quaternion)Normalizes the quaternion to the unit length (a versor). The zero quaternion stays zero.
See also norm.
Normalizes the quaternion to the unit length (a versor). The zero quaternion stays zero. See also [[norm]].
(pow q p)Power of a quaternion, exp(log(q) * p).
Both arguments can be quaternions, complex numbers or numbers. Note that the exponent multiplies log(q) from the right and that the quaternion product is not commutative. The power of the zero quaternion has NaN parts.
Power of a quaternion, `exp(log(q) * p)`. Both arguments can be quaternions, complex numbers or numbers. Note that the exponent multiplies `log(q)` from the right and that the quaternion product is not commutative. The power of the zero quaternion has `NaN` parts. See also [[exp]], [[log]], [[sq]].
(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 (-1.0 or 1.0), not a unit quaternion (see normalize).
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 (`-1.0` or `1.0`), not a unit quaternion (see [[normalize]]).
(quaternion a)(quaternion scalar [i j k])(quaternion a b c d)Creates a quaternion represented as [[Vec4]].
Parameters:
a, b, c, d: the scalar part and the i, j, k parts.scalar and [i j k]: the scalar part and the vector part (any sequence of three numbers, for example Vec3).a: the scalar part only, the vector part is zero.See also complex->quaternion, ensure-quaternion.
Creates a quaternion represented as [[Vec4]]. Parameters: - `a`, `b`, `c`, `d`: the scalar part and the `i`, `j`, `k` parts. - `scalar` and `[i j k]`: the scalar part and the vector part (any sequence of three numbers, for example `Vec3`). - `a`: the scalar part only, the vector part is zero. See also [[complex->quaternion]], [[ensure-quaternion]].
(re quaternion)Returns the scalar (real) part of the quaternion as a double. Alias of scalar.
Returns the scalar (real) part of the quaternion as a double. Alias of [[scalar]].
(real? quaternion)Returns true when the vector part of the quaternion is zero, a real number.
Returns `true` when the vector part of the quaternion is zero, a real number.
(reciprocal quaternion)Reciprocal (multiplicative inverse) of the quaternion, conjugate(q) / |q|^2.
Computed without overflow or underflow in the squared norm. The reciprocal of the zero quaternion has NaN parts, the reciprocal of an infinite quaternion is zero.
Reciprocal (multiplicative inverse) of the quaternion, `conjugate(q) / |q|^2`. Computed without overflow or underflow in the squared norm. The reciprocal of the zero quaternion has `NaN` parts, the reciprocal of an infinite quaternion is zero. See also [[inverse]], [[div]].
(rotate in rotq)(rotate in angle u)Rotates the 3d vector in by the rotation quaternion rotq or around the axis u by the angle (radians), the same as fastmath.vector/axis-rotate.
The rotation quaternion is normalized before use, so a non-unit quaternion represents the same rotation as its unit version (the vector is not scaled). The zero quaternion does not rotate.
Parameters:
in: the vector to rotate, any sequence of three numbers.rotq: the rotation quaternion (see rotation-quaternion, from-euler).angle, u: the angle (radians) and the axis of rotation (Vec3).Returns the rotated vector as Vec3.
Rotates the 3d vector `in` by the rotation quaternion `rotq` or around the axis `u` by the `angle` (radians), the same as `fastmath.vector/axis-rotate`. The rotation quaternion is normalized before use, so a non-unit quaternion represents the same rotation as its unit version (the vector is not scaled). The zero quaternion does not rotate. Parameters: * `in`: the vector to rotate, any sequence of three numbers. * `rotq`: the rotation quaternion (see [[rotation-quaternion]], [[from-euler]]). * `angle`, `u`: the angle (radians) and the axis of rotation (`Vec3`). Returns the rotated vector as `Vec3`.
(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. Throws ex-info when u is the zero vector or has an infinite or NaN part (a finite vector is fine also when its length is not representable).
See also from-axis-angle, to-axis-angle, rotate.
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. Throws `ex-info` when `u` is the zero vector or has an infinite or `NaN` part (a finite vector is fine also when its length is not representable). See also [[from-axis-angle]], [[to-axis-angle]], [[rotate]].
(scalar quaternion)Returns the scalar part of the quaternion as a double. Alias of re.
Returns the scalar part of the quaternion as a double. Alias of [[re]].
(scale quaternion scale)Multiplies the quaternion by the real number scale.
Multiplies the quaternion by the real number `scale`.
(sec quaternion)Secant of the quaternion q.
The value is computed with fastmath.complex/sec applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/sec.
Secant of the quaternion `q`. The value is computed with [[fastmath.complex/sec]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/sec]].
(sech quaternion)Hyperbolic secant of the quaternion q.
The value is computed with fastmath.complex/sech applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/sech.
Hyperbolic secant of the quaternion `q`. The value is computed with [[fastmath.complex/sech]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/sech]].
(seq->quaternion [a b c d])Creates a quaternion ([[Vec4]]) from a sequence [a b c d] (scalar part, then i, j, k parts).
Unchecked: the first four elements are taken, elements beyond them are ignored, a missing or non-number element throws a JVM exception. Use ensure-quaternion for a validated conversion.
Creates a quaternion ([[Vec4]]) from a sequence `[a b c d]` (scalar part, then `i`, `j`, `k` parts). Unchecked: the first four elements are taken, elements beyond them are ignored, a missing or non-number element throws a JVM exception. Use [[ensure-quaternion]] for a validated conversion.
(sin quaternion)Sine of the quaternion q.
The value is computed with fastmath.complex/sin applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/sin.
Sine of the quaternion `q`. The value is computed with [[fastmath.complex/sin]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/sin]].
(sinh quaternion)Hyperbolic sine of the quaternion q.
The value is computed with fastmath.complex/sinh applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/sinh.
Hyperbolic sine of the quaternion `q`. The value is computed with [[fastmath.complex/sinh]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/sinh]].
(slerp q1 q2 t)Performs Spherical Linear Interpolation (SLERP) between two unit quaternions.
SLERP interpolates along the shortest arc on the unit sphere, providing smooth
interpolation between rotations represented by unit quaternions with a constant angular velocity. When dot(q1, q2) is negative q2 is negated (the same rotation) to take the shorter way. For almost parallel quaternions nlerp is used, see below.
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].
t=0.0, returns q1.t=1.0, returns q2.0.0 < t < 1.0, returns an interpolated unit quaternion.
The parameter t is internally constrained to [0.0, 1.0]; NaN gives a quaternion with NaN parts.The quaternions are expected to have the unit length, they are not normalized (the arguments are returned unchanged for t=0 and t=1). Both can be numbers or complex numbers too.
For almost parallel quaternions (dot(q1, q2) > 0.9995, an angle below about 3.6 degrees) the normalized linear interpolation is used: the angular velocity is then not exactly constant, the result differs from the exact slerp by less than 1e-6 (4e-7 measured at dot = 0.99955).
Performs Spherical Linear Interpolation (SLERP) between two unit quaternions.
SLERP interpolates along the shortest arc on the unit sphere, providing smooth
interpolation between rotations represented by unit quaternions with a constant angular velocity. When `dot(q1, q2)` is negative `q2` is negated (the same rotation) to take the shorter way. For almost parallel quaternions [[nlerp]] is used, see below.
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 unit quaternion.
The parameter `t` is internally constrained to [0.0, 1.0]; `NaN` gives a quaternion with `NaN` parts.
The quaternions are expected to have the unit length, they are not normalized (the arguments are returned unchanged for `t=0` and `t=1`). Both can be numbers or complex numbers too.
For almost parallel quaternions (`dot(q1, q2) > 0.9995`, an angle below about 3.6 degrees) the normalized linear interpolation is used: the angular velocity is then not exactly constant, the result differs from the exact slerp by less than 1e-6 (4e-7 measured at `dot = 0.99955`).
See also [[nlerp]], [[dot]].(sqrt quaternion)Principal square root of the quaternion q.
The value is computed with fastmath.complex/sqrt applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/sqrt.
Principal square root of the quaternion `q`. The value is computed with [[fastmath.complex/sqrt]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/sqrt]].
(sub q)(sub q1 q2)(sub q1 q2 & more)Difference of quaternions, q1 - q2 - ....
Arguments can be quaternions, complex numbers or numbers. With one argument returns the negation neg. More than two arguments are subtracted from the first one, from left to right.
Difference of quaternions, `q1 - q2 - ...`. Arguments can be quaternions, complex numbers or numbers. With one argument returns the negation [[neg]]. More than two arguments are subtracted from the first one, from left to right. See also [[add]], [[neg]].
(tan quaternion)Tangent of the quaternion q.
The value is computed with fastmath.complex/tan applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/tan.
Tangent of the quaternion `q`. The value is computed with [[fastmath.complex/tan]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/tan]].
(tanh quaternion)Hyperbolic tangent of the quaternion q.
The value is computed with fastmath.complex/tanh applied to re(q) + |vector(q)| i, the imaginary part of the result is spread over the direction of the vector part of q. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the i axis. Branch cuts and the accuracy are the ones of the complex function.
See also fastmath.complex/tanh.
Hyperbolic tangent of the quaternion `q`. The value is computed with [[fastmath.complex/tanh]] applied to `re(q) + |vector(q)| i`, the imaginary part of the result is spread over the direction of the vector part of `q`. A quaternion with a zero vector part is treated as a complex number with the imaginary part on the `i` axis. Branch cuts and the accuracy are the ones of the complex function. See also [[fastmath.complex/tanh]].
(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 in the range [-pi, pi] for x and z, and [-pi/2, pi/2] for y.
At the gimbal lock (y is +-pi/2, only the sum or the difference of x and z is defined) x is set to zero and z takes the whole rotation, so from-angles of the result represents the same rotation. The lock is detected when cos(y) is below 1.0e-8.
See also from-angles, to-euler.
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 in the range `[-pi, pi]` for x and z, and `[-pi/2, pi/2]` for y. At the gimbal lock (y is `+-pi/2`, only the sum or the difference of x and z is defined) x is set to zero and z takes the whole rotation, so [[from-angles]] of the result represents the same rotation. The lock is detected when `cos(y)` is below `1.0e-8`. See also [[from-angles]], [[to-euler]].
(to-axis-angle quaternion)Converts a quaternion to the axis and the angle of the rotation.
The input quaternion is normalized. Returns a map with the keys:
:axis: the unit axis of rotation (Vec3),:angle: the angle in radians in the range [0, pi].The sign of the quaternion is chosen so that the angle is the shortest one (for -q the result is the same as for q). For a quaternion with a zero vector part (no rotation) the axis is [1 0 0] and the angle is 0.
See also from-axis-angle, arg.
Converts a quaternion to the axis and the angle of the rotation. The input quaternion is normalized. Returns a map with the keys: * `:axis`: the unit axis of rotation (`Vec3`), * `:angle`: the angle in radians in the range `[0, pi]`. The sign of the quaternion is chosen so that the angle is the shortest one (for `-q` the result is the same as for `q`). For a quaternion with a zero vector part (no rotation) the axis is `[1 0 0]` and the angle is `0`. See also [[from-axis-angle]], [[arg]].
(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 in [-pi, pi] for roll/yaw and [-pi/2, pi/2] for pitch.
At the gimbal lock (pitch is +-pi/2, only the sum or the difference of roll and yaw is defined) the roll is set to zero and the yaw takes the whole rotation, so from-euler of the result represents the same rotation. The lock is detected when cos(pitch) is below 1.0e-8.
See also from-euler, to-angles.
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 in [-pi, pi] for roll/yaw and [-pi/2, pi/2] for pitch. At the gimbal lock (pitch is `+-pi/2`, only the sum or the difference of roll and yaw is defined) the roll is set to zero and the yaw takes the whole rotation, so [[from-euler]] of the result represents the same rotation. The lock is detected when `cos(pitch)` is below `1.0e-8`. See also [[from-euler]], [[to-angles]].
(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. Both q and -q give the same matrix.
Parameters:
q: The quaternion (Vec4) to convert.Returns A 3x3 rotation matrix (Mat3x3).
See also from-rotation-matrix.
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. Both `q` and `-q` give the same matrix. Parameters: * `q`: The quaternion (Vec4) to convert. Returns A 3x3 rotation matrix (Mat3x3). See also [[from-rotation-matrix]].
(valid? z)Returns true when all parts of the quaternion are finite numbers. See also invalid?.
Returns `true` when all parts of the quaternion are finite numbers. See also [[invalid?]].
(vector quaternion)Returns the vector part (the i, j, k parts) of the quaternion as [[Vec3]].
Returns the vector part (the `i`, `j`, `k` parts) of the quaternion as [[Vec3]].
(zero? quaternion)Returns true when all parts of the quaternion are zero.
Returns `true` when all parts of the quaternion are zero.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |