Liking cljdoc? Tell your friends :D

sicmutils.quaternion

This namespace provides a number of functions and constructors for working with Quaternion instances in Clojure and Clojurescript, and installs Quaternion into the SICMUtils generic arithmetic system.

For other numeric extensions, see sicmutils.ratio, sicmutils.complex and [[sicmutils.numbers]].

This namespace provides a number of functions and constructors for working
with [[Quaternion]] instances in Clojure and Clojurescript, and
installs [[Quaternion]] into the SICMUtils generic arithmetic system.

For other numeric extensions, see [[sicmutils.ratio]], [[sicmutils.complex]]
and [[sicmutils.numbers]].
raw docstring

*angle-axis-tolerance*clj/s

Tolerance setting for ->angle-axis.

Tolerance setting for [[->angle-axis]].
sourceraw docstring

->angle-axisclj/s

(->angle-axis q)

Given a unit quaternion q representing a spatial rotation (sometimes called a 'versor'), returns a pair of

  • theta, the rotation in radians about the rotation axis
  • axis, a 3-element unit vector with elements x, y and z representing an axis of rotation in 3d Euclidean space.

If the unit quaternion q represents NO rotation, the axis is undefined; this manifests as the squared norm of the non-real vector part of q sitting within *angle-axis-tolerance* of 0.

In this case, the conversion is degenerate and ->angle-axis returns the pair [0 [1 0 0]] as a default. (This check only occurs with a quaternion with all numeric elements in the non-real positions.)

Given a unit quaternion `q` [representing a spatial
rotation](https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation) (sometimes
called a 'versor'), returns a pair of

- `theta`, the rotation in radians about the rotation axis
- `axis`, a 3-element unit vector with elements `x`, `y` and `z` representing
  an axis of rotation in 3d Euclidean space.

If the unit quaternion `q` represents NO rotation, the axis is undefined; this
manifests as the squared norm of the non-real vector part of `q` sitting
within [[*angle-axis-tolerance*]] of 0.

In this case, the conversion is degenerate and [[->angle-axis]] returns the
pair [0 [1 0 0]] as a default. (This check only occurs with a quaternion with
all numeric elements in the non-real positions.)
sourceraw docstring

->complex-pairclj/s

(->complex-pair q)

Returns a pair of complex number created respectively from the (r,i) and (j,k) components of the supplied quaternion q.

NOTE that this only works if the coefficients of q are real numbers, due to restrictions on the current complex number implementation.

Returns a pair of complex number created respectively from the `(r,i)`
and `(j,k)` components of the supplied quaternion `q`.

NOTE that this only works if the coefficients of `q` are real numbers, due to
restrictions on the current complex number implementation. 
sourceraw docstring

->vectorclj/s

(->vector q)

Returns a 4-vector of the coefficients of quaternion q.

Works identically to (vec q), but more efficient as we are able to create the new vector in one shot.

Returns a 4-vector of the coefficients of quaternion `q`.

Works identically to `(vec q)`, but more efficient as we are able to create
the new vector in one shot.
sourceraw docstring

addclj/s

(add)
(add q)
(add q1 q2)
(add q1 q2 & more)

Variadic function that returns the sum of all supplied quaternions.

Given 1 argument q, acts as identity. Given no arguments, returns ZERO, the additive identity.

The sum of two or more quaternions is a new quaternion with coefficients equal to the elementwise sum of the coefficients of all supplied quaternions.

Variadic function that returns the sum of all supplied quaternions.

Given 1 argument `q`, acts as identity. Given no arguments, returns [[ZERO]],
the additive identity.

The sum of two or more quaternions is a new quaternion with coefficients equal
to the elementwise sum of the coefficients of all supplied quaternions.
sourceraw docstring

arityclj/s

(arity q)

Given a quaternion q with function coefficients, returns an arity compatible with all function coefficient entries.

NOTE that by default, if any arities are incompatible, the function will return [:at-least 0]. To force strict arity checks, bind sicmutils.function/*strict-arity-checks* to true.

Given a quaternion `q` with function coefficients, returns an arity compatible
with all function coefficient entries.

NOTE that by default, if any arities are incompatible, the function will
return `[:at-least 0]`. To force strict arity checks,
bind [[sicmutils.function/*strict-arity-checks*]] to `true`.
sourceraw docstring

commutatorclj/s

(commutator l r)

Returns the commutator of the supplied quaternions l and r.

The commutator of two quaternions is equal to

(- (* l r) (* r l))
Returns the commutator of the supplied quaternions `l` and `r`.

The commutator of two quaternions is equal to

```clj
(- (* l r) (* r l))
```
sourceraw docstring

complex-1clj/s

(complex-1 q)

Returns the r and i components of the quaternion q as a Complex number instance.

Returns the `r` and `i` components of the quaternion `q` as a `Complex` number
instance.
sourceraw docstring

complex-2clj/s

(complex-2 q)

Returns the j and k components of the quaternion q as a Complex number instance.

Returns the `j` and `k` components of the quaternion `q` as a `Complex` number
instance.
sourceraw docstring

conjugateclj/s

(conjugate q)

Returns the conjugate of the supplied quaternion q.

The conjugate of a quaternion is a new quaternion with real coefficient equal to that of q and each imaginary coefficient negated. (mul q (conjugate q)) will return a real? quaternion.

Returns the conjugate of the supplied quaternion `q`.

The conjugate of a quaternion is a new quaternion with real coefficient equal
to that of `q` and each imaginary coefficient negated. `(mul q (conjugate q))`
will return a [[real?]] quaternion.
sourceraw docstring

cosclj/s

(cos q)

Returns the cosine of the supplied quaternion q.

See the Boost documentation and source for a reference implementation.

Returns the cosine of the supplied quaternion `q`.

See the [Boost
documentation](https://www.boost.org/doc/libs/1_78_0/libs/math/doc/html/math_toolkit/trans.html)
and [source](https://www.boost.org/doc/libs/1_78_0/boost/math/quaternion.hpp)
for a reference implementation.
sourceraw docstring

coshclj/s

(cosh q)

Returns the hyperbolic cosine of the supplied quaternion q.

cosh is defined in terms of the exp function as (e^q + e^{-q}) / 2.

Returns the hyperbolic cosine of the supplied quaternion `q`.

[[cosh]] is defined in terms of the [[exp]] function as `(e^q + e^{-q}) / 2`.
sourceraw docstring

cross-productclj/s

(cross-product l r)

Returns a quaternion representing the (vector) cross product of the two pure sides (retrieved via three-vector) of the supplied quaternions l and r.

NOTE that the suggestion for this function comes from this C++ quaternion library. Strictly, this is not the 'cross product of two quaternions'.

Returns a quaternion representing the (vector) cross product of the two pure
sides (retrieved via [[three-vector]]) of the supplied quaternions `l` and
`r`.

NOTE that the suggestion for this function comes from this [C++ quaternion
library](https://github.com/ferd36/quaternions/blob/master/include/quaternion.h#L1109).
Strictly, this is not the 'cross product of two quaternions'.
sourceraw docstring

cylindricalclj/s

(cylindrical mag angle j k)

Returns a Quaternion q with complex-1 built from the polar coordinates mag and angle, and j and k components equal to the supplied j and k.

Returns a [[Quaternion]] `q` with [[complex-1]] built from the polar
coordinates `mag` and `angle`, and `j` and `k` components equal to the
supplied `j` and `k`.
sourceraw docstring

cylindrosphericalclj/s

(cylindrospherical t r theta phi)

Returns a Quaternion q with real-part equal to t and the three-vector part built from the spherical coordinates r, colat and lon.

Returns a [[Quaternion]] `q` with [[real-part]] equal to `t` and
the [[three-vector]] part built from the spherical coordinates `r`, `colat`
and `lon`.
sourceraw docstring

divclj/s

(div)
(div q)
(div q1 q2)
(div q1 q2 & more)

Variadic function for dividing quaternion arguments.

  • Given no arguments, returns ONE, the multiplicative identity.
  • Given 1 argument q, acts as identity.
  • Given 2 arguments, returns the quotient of quaternions q1 and q2.
  • Given more than 2 arguments, returns the quotient of the first quaternion q1 with the product of all remaining arguments.

The quotient of two quaternions is a new quaternion equal to the product of q1 and the multiplicative inverse of q2

Variadic function for dividing quaternion arguments.

- Given no arguments, returns [[ONE]], the multiplicative identity.
- Given 1 argument `q`, acts as identity.
- Given 2 arguments, returns the quotient of quaternions `q1` and `q2`.
- Given more than 2 arguments, returns the quotient of the first quaternion
  `q1` with the product of all remaining arguments.

The quotient of two quaternions is a new quaternion equal to the product of
`q1` and the multiplicative inverse of `q2`
sourceraw docstring

dot-productclj/s

(dot-product l r)

Returns the quaternion dot product of the supplied quaternions l and r.

The quaternion dot product is the sum of the products of the corresponding coefficients of each quaternion, equal to

$$r_l * r_r + i_l * i_r + j_l * j_r + k_l * k_r$$

Returns the quaternion dot product of the supplied quaternions `l` and `r`.

The quaternion dot product is the sum of the products of the corresponding
coefficients of each quaternion, equal to

$$r_l * r_r + i_l * i_r + j_l * j_r + k_l * k_r$$
sourceraw docstring

eqclj/s

(eq q1 q2)

Returns true if the supplied quaternion q1 is equal to the value q2. The rules for eq are as follows:

  • If q2 is a quaternion, returns true if all coefficients match, false otherwise

  • If q2 is complex, returns true if the real and i coefficients are equal, with j and k coefficients of q1 equal to zero, false otherwise

  • If q2 is sequential with a count of 4, it's interpreted as a vector of quaternion coefficients.

Else, if q1 is a real? quaternion, returns true if the real component of q1 is sicmutils.value/= to q2, false otherwise.

Returns true if the supplied quaternion `q1` is equal to the value `q2`. The
rules for [[eq]] are as follows:

- If `q2` is a quaternion, returns true if all coefficients match, false
  otherwise

- If `q2` is complex, returns true if the real and `i` coefficients are equal,
  with `j` and `k` coefficients of `q1` equal to zero, false otherwise

- If `q2` is sequential with a count of 4, it's interpreted as a vector of
  quaternion coefficients.

Else, if `q1` is a [[real?]] quaternion, returns true if the real component of
`q1` is [[sicmutils.value/=]] to `q2`, false otherwise.
sourceraw docstring

evaluateclj/s

(evaluate q args)

Given a quaternion q with function coefficients and a sequence args of arguments, and returns a new Quaternion generated by replacing each coefficient with the result of applying the (functional) coefficient to args.

Given a quaternion `q` with function coefficients and a sequence `args` of
arguments, and returns a new [[Quaternion]] generated by replacing each
coefficient with the result of applying the (functional) coefficient to
`args`.
sourceraw docstring

expclj/s

(exp q)

Returns the exponential $e^q$ of the supplied quaternion q.

Given a quaternion $q$ with real part $r$ and non-real vector $\vec{v}$, the exponential is computed as

$$ \exp(q) = e^r \left(\cos |\mathbf{v}| \

  • \frac{\mathbf{v}}{|\mathbf{v}|} \sin|\mathbf{v}| \right) $$
Returns the exponential $e^q$ of the supplied quaternion `q`.

Given a quaternion $q$ with real part $r$ and non-real vector $\vec{v}$, the
exponential [is computed
as](https://en.wikipedia.org/wiki/Quaternion#Exponential,_logarithm,_and_power_functions)

$$
\exp(q) = e^r \left(\cos \|\mathbf{v}\| \
+ \frac{\mathbf{v}}{\|\mathbf{v}\|} \sin\|\mathbf{v}\| \right)
$$
sourceraw docstring

exptclj/s

(expt q p)

Returns the result of raising quaternion q to the real, complex or quaternion power p.

Returns the result of raising quaternion `q` to the real, complex or quaternion
power `p`.
sourceraw docstring

from-angle-axisclj/s

(from-angle-axis angle axis)

Returns a Quaternion that represents a rotation of angle radians around a normalized version of the vector described by axis. axis must be a 3-vector with components x, y and z.

Given an axis with numeric entries, from-angle-axis will explicitly normalize axis before calling from-angle-normal-axis. If any entries are non-numerical (ie, symbolic), from-angle-axis will instead log an assumption that the magnitude of axis == 1 and proceed.

NOTE: If you have an already-normalized axis, prefer from-angle-normal-axis.

Returns a [[Quaternion]] that represents a rotation of `angle` radians around a
normalized version of the vector described by `axis`. `axis` must be a
3-vector with components `x`, `y` and `z`.

Given an `axis` with numeric entries, [[from-angle-axis]] will explicitly
normalize `axis` before calling [[from-angle-normal-axis]]. If any entries are
non-numerical (ie, symbolic), [[from-angle-axis]] will instead log an
assumption that the magnitude of `axis` == 1 and proceed.

NOTE: If you have an already-normalized axis,
prefer [[from-angle-normal-axis]].
sourceraw docstring

from-angle-normal-axisclj/s

(from-angle-normal-axis angle [x y z])

Returns a Quaternion that represents a rotation of angle radians around the unit (normalized) vector described by the second argument, a 3-vector with components x, y and z.

The second argument represents an axis of rotation.

NOTE: If you have an UN-normalized axis, prefer from-angle-axis.

Returns a [[Quaternion]] that represents a rotation of `angle` radians around
the unit (normalized) vector described by the second argument, a 3-vector with
components `x`, `y` and `z`.

The second argument represents an axis of rotation.

NOTE: If you have an UN-normalized axis, prefer [[from-angle-axis]].
sourceraw docstring

from-complexclj/s

(from-complex a b)

Given two complex numbers a and b, returns a quaternion instance with

  • r and i components set to the real and imaginary components of a
  • j and k components set to the real and imaginary components of b
Given two complex numbers `a` and `b`, returns a quaternion instance with

- `r` and `i` components set to the real and imaginary components of `a`
- `j` and `k` components set to the real and imaginary components of `b`
sourceraw docstring

get-iclj/s

(get-i q)

Returns the i component of the supplied quaternion q.

Returns the `i` component of the supplied quaternion `q`.
sourceraw docstring

get-jclj/s

(get-j q)

Returns the j component of the supplied quaternion q.

Returns the `j` component of the supplied quaternion `q`.
sourceraw docstring

get-kclj/s

(get-k q)

Returns the k component of the supplied quaternion q.

Returns the `k` component of the supplied quaternion `q`.
sourceraw docstring

get-rclj/s

(get-r q)

Returns the r component of the supplied quaternion q.

Identical to real-part.

Returns the `r` component of the supplied quaternion `q`.

Identical to [[real-part]].
sourceraw docstring

Iclj/s

Unit quaternion with i coefficient equal to 1, all other coefficients equal to 0.

Unit quaternion with `i` coefficient equal to 1, all other
coefficients equal to 0.
sourceraw docstring

invertclj/s

(invert q)

Returns the multiplicative inverse of the supplied quaternion q.

The inverse of a quaternion is a new quaternion that, when multiplied by q, will produce the ONE quaternion (the multiplicative identity).

Returns the multiplicative inverse of the supplied quaternion `q`.

The inverse of a quaternion is a new quaternion that, when [[mul]]tiplied by
`q`, will produce the [[ONE]] quaternion (the multiplicative identity).
sourceraw docstring

Jclj/s

Unit quaternion with j coefficient equal to 1, all other coefficients equal to 0.

Unit quaternion with `j` coefficient equal to 1, all other
coefficients equal to 0.
sourceraw docstring

Kclj/s

Unit quaternion with k coefficient equal to 1, all other coefficients equal to 0.

Unit quaternion with `k` coefficient equal to 1, all other
coefficients equal to 0.
sourceraw docstring

logclj/s

(log q)

Returns the logarithm $\ln q$ of the supplied quaternion q.

Given a quaternion $q$ with real part $r$ and non-real vector $\vec{v}$, the logarithm is computed as

$$ \ln(q) = \ln |q| + \frac{\mathbf{v}}{|\mathbf{v}|}
\arccos \frac{r}{|\q|} $$

Returns the logarithm $\ln q$ of the supplied quaternion `q`.

Given a quaternion $q$ with real part $r$ and non-real vector $\vec{v}$, the
logarithm [is computed
as](https://en.wikipedia.org/wiki/Quaternion#Exponential,_logarithm,_and_power_functions)

$$
\ln(q) = \ln \|q\| + \frac{\mathbf{v}}{\|\mathbf{v}\|} \
\arccos \frac{r}{\|\q\|}
$$
sourceraw docstring

magnitudeclj/s

(magnitude q)

Returns the norm of the supplied quaternion q.

The norm of a quaternion is the square root of the sum of the squares of the quaternion's coefficients.

Returns the norm of the supplied quaternion `q`.

The norm of a quaternion is the square root of the sum of the squares of the
quaternion's coefficients.
sourceraw docstring

magnitude-sqclj/s

(magnitude-sq q)

Returns the square of the magnitude of the supplied quaternion q, equivalent to taking the dot-product of q with itself.

Returns the square of the [[magnitude]] of the supplied quaternion `q`,
equivalent to taking the [[dot-product]] of `q` with itself.
sourceraw docstring

makeclj/s

(make x)
(make r [i j k])
(make r i j k)

Constructor that builds Quaternion instances out of a variety of types. Given:

  • a quaternion x, acts as identity.

  • a sequential x, returns a quaternion with coefficients built from the first four entries.

  • a complex number x, returns a quaternion built from the real and imaginary components of x with j and k components equal to zero.

  • a real number x and 3-vector, returns a quaternion with real coefficient equal to x and imaginary components equal to the elements of the vector

  • 4 distinct arguments r, i, j and k, returns a quaternion with these as the coefficients.

Constructor that builds [[Quaternion]] instances out of a variety of types.
Given:

- a quaternion `x`, acts as identity.

- a sequential `x`, returns a quaternion with coefficients built from the
  first four entries.

- a complex number `x`, returns a quaternion built from the real and imaginary
  components of `x` with `j` and `k` components equal to zero.

- a real number `x` and 3-vector, returns a quaternion with real coefficient
  equal to `x` and imaginary components equal to the elements of the vector

- 4 distinct arguments `r`, `i`, `j` and `k`, returns a quaternion with these
  as the coefficients.
sourceraw docstring

mulclj/s

(mul)
(mul q)
(mul q1 q2)
(mul q1 q2 & more)

Variadic function that returns the product of all supplied quaternions.

Given 1 argument q, acts as identity. Given no arguments, returns ONE, the multiplicative identity.

The product of two or more quaternions is a new quaternion generated by multiplying together each quaternion of the form (r+ai+bj+ck), respecting the quaternion rules:

i^2 == j^2 == k^2 == -1 ijk == -1, ij == k, jk == i, ki == j ji == -k, kj == -i, ik == -j

Variadic function that returns the product of all supplied quaternions.

Given 1 argument `q`, acts as identity. Given no arguments, returns [[ONE]],
the multiplicative identity.

The product of two or more quaternions is a new quaternion generated by
multiplying together each quaternion of the form `(r+ai+bj+ck)`, respecting
the quaternion rules:

i^2 == j^2 == k^2 == -1
ijk == -1,
ij  == k,  jk == i,  ki == j
ji  == -k, kj == -i, ik == -j
sourceraw docstring

multipolarclj/s

(multipolar r1 theta1 r2 theta2)

Returns a Quaternion instance with complex-1 part built from the polar coordinates r1 and theta1 and complex-2 part built from r2 and theta2

Returns a [[Quaternion]] instance with [[complex-1]] part built from the polar
coordinates `r1` and `theta1` and [[complex-2]] part built from `r2` and
`theta2`
sourceraw docstring

negateclj/s

(negate q)

Returns the negation (additive inverse) of the supplied quaternion q.

The additive inverse of a quaternion is a new quaternion that, when added to q, will produce the ZERO quaternion (the additive identity).

Returns the negation (additive inverse) of the supplied quaternion `q`.

The additive inverse of a quaternion is a new quaternion that, when [[add]]ed
to `q`, will produce the [[ZERO]] quaternion (the additive identity).
sourceraw docstring

normalizeclj/s

(normalize q)

Returns a new quaternion generated by dividing each coefficient of the supplied quaternion q by the magnitude of q. (If the magnitude is zero?, returns the zero quaternion q.)

The returned quaternion will have magnitude (approximately) equal to

  1. unit? will return true for a normalized quaternion, though you may need to supply an :epsilon.
Returns a new quaternion generated by dividing each coefficient of the supplied
quaternion `q` by the [[magnitude]] of `q`. (If the [[magnitude]]
is [[zero?]], returns the zero quaternion `q`.)

The returned quaternion will have [[magnitude]] (approximately) equal to
1. [[unit?]] will return true for a [[normalize]]d quaternion, though you may
need to supply an `:epsilon`.
sourceraw docstring

ONEclj/s

The identity quaternion. The real coefficient is equal to 1, and all coefficients are equal to 0.

The identity quaternion. The real coefficient is equal to 1, and
all coefficients are equal to 0.
sourceraw docstring

one?clj/s

(one? q)

Returns true if q is a real? quaternion with a one-like coefficient in the real position, false otherwise.

Returns true if `q` is a [[real?]] quaternion with a one-like coefficient in
the real position, false otherwise.
sourceraw docstring

partial-derivativeclj/s

(partial-derivative q selectors)

Given a quaternion q with function coefficients and a possibly-empty sequence of partial derivative selectors, returns a new Quaternion generated by replacing each (functional) coefficient with its derivative with respect to selectors.

Given a quaternion `q` with function coefficients and a possibly-empty sequence
of partial derivative `selectors`, returns a new [[Quaternion]] generated by
replacing each (functional) coefficient with its derivative with respect to
`selectors`.
sourceraw docstring

pitchclj/s

(pitch angle)

Create a quaternion representing a pitch rotation by the supplied angle (specified in radians).

Create a quaternion representing a pitch rotation by the supplied
`angle` (specified in radians).
sourceraw docstring

pure?clj/s

(pure? q)

Returns true if the quaternion q has a zero real entry, false otherwise.

A 'pure' quaternion is sometimes called an 'imaginary' quaternion.

Returns true if the quaternion `q` has a zero real entry, false otherwise.

A 'pure' quaternion is sometimes called an 'imaginary' quaternion.
sourceraw docstring

q-div-scalarclj/s

(q-div-scalar q s)

Returns a new quaternion generated by dividing each coefficient of the supplied quaternion q by the supplied scalar s.

Returns a new quaternion generated by dividing each coefficient of the supplied
quaternion `q` by the supplied scalar `s`.
sourceraw docstring

Quaternioncljs

source

quaternion?clj/s

(quaternion? q)

Returns true if q is an instance of Quaternion, false otherwise.

Returns `true` if `q` is an instance of [[Quaternion]], false otherwise.
sourceraw docstring

real-partclj/s

(real-part q)

Returns the r component of the supplied quaternion q.

Identical to get-r.

Returns the `r` component of the supplied quaternion `q`.

Identical to [[get-r]].
sourceraw docstring

real?clj/s

(real? q)

Returns true if the quaternion q has zero entries for all non-real fields, false otherwise.

Returns true if the quaternion `q` has zero entries for all non-real fields,
false otherwise.
sourceraw docstring

rollclj/s

(roll angle)

Create a quaternion representing a roll rotation by the supplied angle (specified in radians).

Create a quaternion representing a roll rotation by the supplied
`angle` (specified in radians).
sourceraw docstring

scaleclj/s

(scale q s)

Returns a new quaternion generated by multiplying each coefficient of the supplied quaternion q by the supplied scalar s on the right.

Returns a new quaternion generated by multiplying each coefficient of the
supplied quaternion `q` by the supplied scalar `s` on the right.
sourceraw docstring

scale-lclj/s

(scale-l s q)

Returns a new quaternion generated by multiplying each coefficient of the supplied quaternion q by the supplied scalar s on the left.

Returns a new quaternion generated by multiplying each coefficient of the
supplied quaternion `q` by the supplied scalar `s` on the left.
sourceraw docstring

semipolarclj/s

(semipolar r alpha theta1 theta2)

Returns a Quaternion q with magnitude rho, built such that:

  • the magnitude of q equals rho
  • the magnitude ([[complex-1]] q) equals (* rho (cos alpha))
  • the angle of ([[complex-1]] q) equals theta1
  • The magnitude ([[complex-2]] q) equals (* rho (cos alpha))
  • the angle of ([[complex-2]] q) equals theta12

This strange, possibly unnecessary constructor taken from the Boost quaternion implementation.

Returns a [[Quaternion]] `q` with magnitude `rho`, built such that:

- the magnitude of `q` equals `rho`
- the magnitude `([[complex-1]] q)` equals `(* rho (cos alpha))`
- the angle of `([[complex-1]] q)` equals `theta1`
- The magnitude `([[complex-2]] q)` equals `(* rho (cos alpha))`
- the angle of `([[complex-2]] q)` equals `theta12`

This strange, possibly unnecessary constructor taken from the [Boost
quaternion
implementation](https://www.boost.org/doc/libs/1_78_0/libs/math/doc/html/math_toolkit/create.html).
sourceraw docstring

sinclj/s

(sin q)

Returns the sine of the supplied quaternion q.

See the Boost documentation and source for a reference implementation.

Returns the sine of the supplied quaternion `q`.

See the [Boost
documentation](https://www.boost.org/doc/libs/1_78_0/libs/math/doc/html/math_toolkit/trans.html)
and [source](https://www.boost.org/doc/libs/1_78_0/boost/math/quaternion.hpp)
for a reference implementation.
sourceraw docstring

sinhclj/s

(sinh q)

Returns the hyperbolic sine of the supplied quaternion q.

sinh is defined in terms of the exp function as (e^q - e^{-q}) / 2.

Returns the hyperbolic sine of the supplied quaternion `q`.

[[sinh]] is defined in terms of the [[exp]] function as `(e^q - e^{-q}) / 2`.
sourceraw docstring

sphericalclj/s

(spherical r theta colat lon)

Generates a Quaternion instance, given:

  • a magnitude r
  • a rotation angle theta, with a natural range of -2*pi to 2*pi
  • colat, the colatitude of the (non-real) vectorial part of the quaternion
  • lon, the longitude of the vectorial part of the quaternion
Generates a [[Quaternion]] instance, given:

- a magnitude `r`
- a rotation angle `theta`, with a natural range of `-2*pi` to `2*pi`
- `colat`, the [colatitude](https://mathworld.wolfram.com/Colatitude.html) of
  the (non-real) vectorial part of the quaternion
- `lon`, the longitude of the vectorial part of the quaternion
sourceraw docstring

sqrtclj/s

(sqrt q)

Returns the square root of the supplied quaternion q.

([[sqrt]] q) is identical to, but more efficient than, raising q to the 1/2 power.

Thanks to the Spire library for the correct implementation used here.

Returns the square root of the supplied quaternion `q`.

`([[sqrt]] q)` is identical to, but more efficient than, raising `q` to the
1/2 power.

Thanks to the [Spire
library](https://github.com/typelevel/spire/blob/82f607714f94ba1c70b13fd4751063dfdcd155f5/core/src/main/scala/spire/math/Quaternion.scala#L217)
for the correct implementation used here.
sourceraw docstring

subclj/s

(sub)
(sub q)
(sub q1 q2)
(sub q1 q2 & more)

Variadic function for subtracting quaternion arguments.

  • Given no arguments, returns ZERO, the additive identity.
  • Given 1 argument q, acts as identity.
  • Given 2 arguments, returns the difference of quaternions q1 and q2.
  • Given more than 2 arguments, returns the difference of the first quaternion q1 with the sum of all remaining arguments.

The difference of two quaternions is a new quaternion with coefficients equal to the pairwise difference of the coefficients of q1 and q2.

Variadic function for subtracting quaternion arguments.

- Given no arguments, returns [[ZERO]], the additive identity.
- Given 1 argument `q`, acts as identity.
- Given 2 arguments, returns the difference of quaternions `q1` and `q2`.
- Given more than 2 arguments, returns the difference of the first quaternion
  `q1` with the sum of all remaining arguments.

The difference of two quaternions is a new quaternion with coefficients equal
to the pairwise difference of the coefficients of `q1` and `q2`.
sourceraw docstring

tanclj/s

(tan q)

Returns the tangent of the supplied quaternion q.

tan is defined as (/ (sin q) (cos q)).

Returns the tangent of the supplied quaternion `q`.

[[tan]] is defined as `(/ (sin q) (cos q))`.
sourceraw docstring

tanhclj/s

(tanh q)

Returns the hyperbolic tangent of the supplied quaternion q.

tan is defined as (/ (sinh q) (cosh q)).

Returns the hyperbolic tangent of the supplied quaternion `q`.

[[tan]] is defined as `(/ (sinh q) (cosh q))`.
sourceraw docstring

three-vectorclj/s

(three-vector q)

Returns a 3-vector holding the coefficients of the non-real (imaginary) components of the quaternion q.

Returns a 3-vector holding the coefficients of the non-real (imaginary)
components of the quaternion `q`.
sourceraw docstring

unit?clj/s

(unit? q & {:keys [epsilon]})

Returns true if q is a unit quaternion (ie, a 'versor', a quaternion with magnitude equal to one), false otherwise.

To check if the magnitude of q is /approximately/ equal to one, pass a tolerance via the :epsilon keyword argument.

For more control, use magnitude to compute the magnitude directly.

Returns true if `q` is a unit quaternion (ie, a 'versor', a quaternion
with [[magnitude]] equal to one), false otherwise.

To check if the [[magnitude]] of `q` is /approximately/ equal to one, pass a
tolerance via the `:epsilon` keyword argument.

For more control, use [[magnitude]] to compute the magnitude directly.
sourceraw docstring

yawclj/s

(yaw angle)

Create a quaternion representing a yaw rotation by the supplied angle (specified in radians).

Create a quaternion representing a yaw rotation by the supplied
`angle` (specified in radians).
sourceraw docstring

ZEROclj/s

The zero quaternion. All coefficients are equal to 0.

The zero quaternion. All coefficients are equal to 0.
sourceraw docstring

zero?clj/s

(zero? q)

Returns true if q is a quaternion with zeros in all coefficient positions, false otherwise.

Returns true if `q` is a quaternion with zeros in all coefficient positions,
false otherwise.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close