ddg.math.quaternion module

Quaternion arithmetic module. In this module quaternions are represented by numpy arrays with 4 entries.

ddg.math.quaternion.point_to_quaternion(x)[source]

Converts a point in \(\mathbf{R}^3\) to an imaginary quaternion by adding a zero as the first coordinate.

Parameters:
xnp.ndarray of shape (n, 3) or (3,)

the input array representing points in \(\mathbf{R}^3\). Either a single point as 1D array of shape (3,) or an array of points with shape (n, 3)

Returns:
np.ndarray

the array of resulting imaginary quaternions for each point of the input array

ddg.math.quaternion.multiply(x, y)[source]

Multiplication of quaternions. Notice if we write a quaternion in a vectorize manner we have

\[\begin{split}x &= [q_1, q_2, q_3, q_4] \\ y &= [p_1, p_2, p_3, p_4] \\ \Im(x) &:= [q_2, q_3, q_4] \\ \Im(y) &:= [p_2, p_3, p_4] \\ \Re(xy) &= q_{1}p_1 - \langle \Im(x), \Im(y) \rangle \\ \Im(xy) &= \Im(x) \times \Im(y) + q_{1}\Im(y) + p_{1}\Im(x)\end{split}\]

If one of the inputs is a 2D array of several quaternions and the other is a 2D array of a single quaternion, the output is the multiplication of each element of the first array with the second array

Parameters:
xnp.ndarray
ynp.ndarray
Returns:
np.ndarray
ddg.math.quaternion.inverse(X)[source]

Calculates the inverse of a quaternion. We have:

\[\begin{split}x &= [q_1, q_2, q_3, q_4] \\ \bar{x} &= [q_1, -q_2, -q_3, -q_4] \\ ||x||^{2} &= q_{1}^2 + q_{2}^2 + q_{3}^2 + q_{4}^2 \\ x^{-1} &= \frac{\bar{x}}{||x||^2}\end{split}\]
Parameters:
Xnp.ndarray

the input array of quaternions

Returns:
np.ndarray

an array of inversed values for each element of the input

ddg.math.quaternion.cr(X1, X2, X3, X4)[source]

The cross ratio of four quaternions. For each four quaternions, the cross ratio is calculated by the formula:

\[cr(x_1, x_2, x_3, x_4) = \frac{(x_1-x_2)(x_3-x_4)}{(x_2-x_3)(x_4-x_1)}.\]
Parameters:
X1np.ndarray

First quaternion or array of quaternions

X2np.ndarray

Second quaternion or array of quaternions

X3np.ndarray

Third quaternion or array of quaternions

X4np.ndarray

Fourth quaternion or array of quaternions

Returns:
np.ndarray

cross ratio of the input quaternions If four 2D arrays of quaternions are given as input, the resulting array is the 2D array of cross ratios of corresponding quaternions.

ddg.math.quaternion.imag(X)[source]

Finds the imaginary part of the quaternion.

Parameters:
Xnp.ndarray

the input array of quaternions

Returns:
np.ndarray

Imaginary parts of an array of quaternions.