Note that all these functions work with single quaternions and quaternion vectors, as well as with arrays containing these.
Functions for working with quaternions. Note that all the functions also work on arrays, and can deal with full quaternions as well as with quaternion vectors.
Convert axis-angles or plain degree into the corresponding quaternion values. Can be used with a plain number or with an axis angle.
Parameters: | inDeg : float or (N,3)
|
---|---|
Returns: | outQuat : float or array (N,3)
|
Notes
More info under http://en.wikipedia.org/wiki/Quaternion
Examples
>>> quat.deg2quat(array([[10,20,30], [20,30,40]]))
array([[ 0.08715574, 0.17364818, 0.25881905],
[ 0.17364818, 0.25881905, 0.34202014]])
>>> quat.deg2quat(10)
0.087155742747658166
Calculate the axis-angle corresponding to a given quaternion.
Parameters: | inQuat: float, or array_like, shape ([3/4],) or (N,[3/4]) :
|
---|---|
Returns: | axAng : corresponding axis angle(s)
|
Notes
More info under http://en.wikipedia.org/wiki/Quaternion
Examples
>>> quat.quat2deg(0.1)
array([ 11.47834095])
>>> quat.quat2deg([0.1, 0.1, 0])
array([ 11.47834095, 11.47834095, 0. ])
>>> quat.quat2deg([cos(0.1), 0, sin(0.1), 0])
array([ 0. , 11.4591559, 0. ])
Calculate the rotation matrix corresponding to the quaternion. If “inQuat” contains more than one quaternion, the matrix is flattened (to facilitate the work with rows of quaternions), and can be restored to matrix form by “reshaping” the resulting rows into a (3,3) shape.
Parameters: | inQuat : array_like, shape ([3,4],) or (N,[3,4])
|
---|---|
Returns: | rotMat : corresponding rotation matrix/matrices (flattened) |
Notes
More info under http://en.wikipedia.org/wiki/Quaternion
Examples
>>> r = quat.quat2rotmat([0, 0, 0.1])
>>> r.shape
(1, 9)
>>> r.reshape((3,3))
array([[ 0.98 , -0.19899749, 0. ],
[ 0.19899749, 0.98 , 0. ],
[ 0. , 0. , 1. ]])
Extract the quaternion vector from a full quaternion.
Parameters: | inQuat : array_like, shape ([3,4],) or (N,[3,4])
|
---|---|
Returns: | vect : array, shape (3,) or (N,3)
|
Notes
More info under http://en.wikipedia.org/wiki/Quaternion
Examples
>>> quat.quat2vect([[cos(0.2), 0, 0, sin(0.2)],[cos(0.1), 0, sin(0.1), 0]])
array([[ 0. , 0. , 0.19866933],
[ 0. , 0.09983342, 0. ]])
Quaternion inversion
Parameters: | q: array_like, shape ([3,4],) or (N,[3/4]) :
|
---|---|
Returns: | qinv : inverse quaternion(s) |
Notes
More info under http://en.wikipedia.org/wiki/Quaternion
Examples
>>> quat.quatinv([0,0,0.1])
array([[-0. , -0. , -0.1]])
>>> quat.quatinv([[cos(0.1),0,0,sin(0.1)],
...: [cos(0.2),0,sin(0.2),0]])
array([[ 0.99500417, -0. , -0. , -0.09983342],
[ 0.98006658, -0. , -0.19866933, -0. ]])
Quaternion multiplication: Calculates the product of two quaternions r = p * q If one of both of the quaterions have only three columns, the scalar component is calculated such that the length of the quaternion is one. The lengths of the quaternions have to match, or one of the two quaternions has to have the length one. If both p and q only have 3 components, the returned quaternion also only has 3 components (i.e. the quaternion vector)
Parameters: | p,q : array_like, shape ([3,4],) or (N,[3,4])
|
---|---|
Returns: | r : quaternion or quaternion vector (if both
|
Notes
More info under http://en.wikipedia.org/wiki/Quaternion
Examples
>>> p = [cos(0.2), 0, 0, sin(0.2)]
>>> q = [[0, 0, 0.1],
>>> [0, 0.1, 0]]
>>> r = quat.quatmult(p,q)
Rotates a vector, according to the given quaternions. Note that a single vector can be rotated into many orientations; or a row of vectors can all be rotated by a single quaternion.
Parameters: | vector : array, shape (3,) or (N,3)
q : array_like, shape ([3,4],) or (N,[3,4])
|
---|---|
Returns: | rotated : array, shape (3,) or (N,3)
|
Notes
More info under http://en.wikipedia.org/wiki/Quaternion
Examples
>>> mymat = eye(3)
>>> myVector = r_[1,0,0]
>>> quats = array([[0,0, sin(0.1)],[0, sin(0.2), 0]])
>>> quat.rotate_vector(myVector, quats)
array([[ 0.98006658, 0.19866933, 0. ],
[ 0.92106099, 0. , -0.38941834]])
>>> quat.rotate_vector(mymat, [0, 0, sin(0.1)])
array([[ 0.98006658, 0.19866933, 0. ],
[-0.19866933, 0.98006658, 0. ],
[ 0. , 0. , 1. ]])
Assumes that R has the shape (3,3), or the matrix elements in columns
Parameters: | rMat : array, shape (3,3) or (N,9)
|
---|---|
Returns: | outQuat : array, shape (4,) or (N,4)
|
Notes
More info under http://en.wikipedia.org/wiki/Quaternion
Examples
>>> rotMat = array([[cos(alpha), -sin(alpha), 0],
>>> [sin(alpha), cos(alpha), 0],
>>> [0, 0, 1]])
>>> quat.rotmat2quat(rotMat)
array([[ 0.99500417, 0. , 0. , 0.09983342]])
Utility function, which turns a quaternion vector into a unit quaternion.
Parameters: | inData : array_like, shape (3,) or (N,3)
|
---|---|
Returns: | quats : array, shape (4,) or (N,4)
|
Notes
More info under http://en.wikipedia.org/wiki/Quaternion
Examples
>>> quats = array([[0,0, sin(0.1)],[0, sin(0.2), 0]])
>>> quat.vect2quat(quats)
array([[ 0.99500417, 0. , 0. , 0.09983342],
[ 0.98006658, 0. , 0.19866933, 0. ]])
Take an angular velocity (in deg/s), and convert it into the corresponding orientation quaternion.
Parameters: | vel : array, shape (3,) or (N,3)
q0 : array (3,)
rate : float
CStype: string :
|
---|---|
Returns: | quats : array, shape (N,4)
|
Notes
Take care that you choose a high enough sampling rate!
Examples
>>> v0 = [0., 0., 100.]
>>> vel = tile(v0, (1000,1))
>>> rate = 100
>>> out = quat.vel2quat(vel, [0., 0., 0.], rate, 'sf')
>>> out[-1:]
array([[-0.76040597, 0. , 0. , 0.64944805]])