Quaternion and numpy-quaternion seem to be the top two libraries in the world that handle quaternions in Python, but probably because the person who made the reference page for pyquaternion was the first in Japan, the quaternion calculation in Python is overflowing in the streets. It's just pyquaternion (is there only?).
However, numpy-quaternion seems to have a lower calculation cost. Reference: https://www.theoj.org/joss-papers/joss.00787/10.21105.joss.00787.pdf
Also, comparing the number of stars on github, there are more numpy-quaternions (as of December 13, 2019, numpy-quaternion is 276 and pyquaternion is 138).
I feel that the affinity with numpy is also better than pyquaternion because of the ease of handling batch conversion. Would you like to use it?
github repository: https://github.com/moble/quaternion Documentation: https://quaternion.readthedocs.io/en/latest/ PyPI: https://pypi.org/project/numpy-quaternion/
pip install numpy-quaternion
You can easily enter with.
Also,
import quaternion
You can import the library with.
quat = (w, x, y, z) = \left(\underbrace{\cos\frac{\theta}{2}}_{Real part},\ \underbrace{\lambda_x\sin\frac{\theta}{2},\ \lambda_y\sin\frac{\theta}{2},\ \lambda_z\sin\frac{\theta}{2}}_{Imaginary number(vector)Department}\right)
Less than,
import numpy as np
import quaternion
will do.
quat = np.quaternion(w, x, y, z)
Quaternion is added to the attribute of numpy. For example
print(np.quaternion(1,0,0,0))
# -> quaternion(1, 0, 0, 0)
type(np.quaternion(1,0,0,0))
# -> quaternion.quaternion
It becomes.
q1 = np.quaternion(1, 2, 3, 4)
q2 = np.quaternion(4, 5, 6, 7)
print(q1*q2)
# -> quaternion(-52, 10, 24, 20)
Multiplication is defined. For the time being, other four arithmetic operations are also defined, but do you sometimes use sums ... It is not defined in Eigen of C ++.
Only a part will be taken up. It does not cover things related to spherical functions or linear interpolation. Reference: https://quaternion.readthedocs.io/en/latest/_autosummary/quaternion.html
Member variables | function |
---|---|
w | Elements of the real part |
x | The first element of the imaginary part |
y | The second element of the imaginary part |
z | The third element of the imaginary part |
components | (w,x,y,z)Is numpy.Returned as an array |
imag | Imaginary part(x,y,z)Is numpy.Returned as an array |
vec | Imaginary part(x,y,z)Is numpy.Returned as an array |
real | Real part(w)Is returned |
Member function | function |
---|---|
abs() | Absolute value of quaternion (Euclidean distance) |
absolute() | Absolute value of quaternion |
angle() | rotation angle |
conj() | Returns the complex conjugate of the quaternion |
conjugate() | Returns the complex conjugate of the quaternion |
equal(quat) | Is it equal to the quaternion in the argument content? |
exp | Returns exponential ( |
inverse() | Returns a reverse quaternion |
isfinite() | Are all elements finite |
ininf() | Is there even one inf element? |
innan() | Is there even one nan element? |
log() | Returns quaternion logs |
nonzero() | Are all elements 0 |
norm() | Quaternion Cayley norm (absolute squared route) |
normalized() | Returns a normalized quaternion |
notequal(quat) | Is it not equal to the quaternion in the argument content? |
sqrt() | Quaternion square-root( |
square() | Quaternion squared |
The point is that the methods in this area are not one-dimensional, but can also be used for multidimensional arrays. If the size of the last dimension requires a quaternion, it should be 4, if it is 3D, it should be 3D, and if it is 3x3, the last 2D should be 3x3.
Member function | function |
---|---|
quaternion.as_quat_array(a) | numpy.Convert array to quaternion. The size of the last dimension of a must be 4 |
quaternion.as_float_array(a) | numpy.quaternion numpy.Convert to array. The dimension of the output is one larger than the input. |
quaternion.from_float_array(a) | as_quat_Same as array |
quaternion.as_rotation_matrix(q) | numpy.Convert quaternion to 3x3 rotation matrix. |
quaternion.from_rotation_matrix(rot, nonorthogonal=True) | Numpy a 3x3 rotation matrix.Convert to quaternion |
quaternion.as_rotation_vector(q) | Find the axis of rotation from the quaternion. The magnitude of the last dimension of the output is 3. |
quaternion.from_rotation_vector(rot) | Convert from a size 3 rotation axis to a quaternion. |
quaternion.as_euler_angles(q) | Convert from quaternion to Euler angles. Refer to the document for the conversion order of Euler angles. |
quaternion.from_euler_angles(alpha_beta_gamma, beta=None, gamma=None) | Convert Euler angles to quaternions. Refer to the document for the conversion order of Euler angles. |
quaternion.rotate_vectors(R, v, axis=-1) | R is a quaternion and v is a vector. Rotate the vector according to the quaternion. |
quaternion.allclose(a, b, rtol=8.881784197001252e-16, atol=0.0, equal_nan=False, verbose=False) | Compare two quaternions |
quaternion.integrate_angular_velocity(Omega, t0, t1, R0=None, tolerance=1e-12) | Rotate according to the angular velocity |
https://quaternion.readthedocs.io/en/latest/index.html
By the way, the author of this library seems to have a big Euler angle. Stop if you see someone using it! Say that and walk away from the spot and mess with your mom! Is written
Where is the demand for quaternions in Python? Unity is C #, and I'm talking about using Unity's functions in the first place, and Python is too slow for robots, which is out of the question ...
Recommended Posts