skrobot.coordinates.quaternion.Quaternion¶
- class skrobot.coordinates.quaternion.Quaternion(w=1.0, x=0.0, y=0.0, z=0.0, q=None)[source]¶
Class for handling Quaternion.
- Parameters:
w (float or numpy.ndarray) –
x (float) –
y (float) –
z (float) –
q (None or numpy.ndarray) – if q is not specified, use w, x, y, z.
Examples
>>> from skrobot.coordinates.quaternion import Quaternion >>> q = Quaternion() >>> q #<Quaternion 0x1283bde48 w: 1.0 x: 0.0 y: 0.0 z: 0.0> >>> q = Quaternion([1, 2, 3, 4]) >>> q #<Quaternion 0x1283cad68 w: 1.0 x: 2.0 y: 3.0 z: 4.0> >>> q = Quaternion(q=[1, 2, 3, 4]) >>> q #<Quaternion 0x1283bd438 w: 1.0 x: 2.0 y: 3.0 z: 4.0> >>> q = Quaternion(1, 2, 3, 4) >>> q #<Quaternion 0x128400198 w: 1.0 x: 2.0 y: 3.0 z: 4.0> >>> q = Quaternion(w=0.0, x=1.0, y=0.0, z=0.0) >>> q #<Quaternion 0x1283cc2e8 w: 0.0 x: 1.0 y: 0.0 z: 0.0>
Methods
- T()[source]¶
Return 4x4 homogeneous transformation matrix.
- Returns:
matrix – homogeneous transformation matrix shape of (4, 4)
- Return type:
Examples
>>> from skrobot.coordinates.quaternion import Quaternion >>> q = Quaternion() >>> q.T() array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]) >>> q.q = [1, 2, 3, 4] >>> q.T() array([[-0.66666667, 0.13333333, 0.73333333, 0. ], [ 0.66666667, -0.33333333, 0.66666667, 0. ], [ 0.33333333, 0.93333333, 0.13333333, 0. ], [ 0. , 0. , 0. , 1. ]])
- copy()[source]¶
Return copy of this Quaternion
- Returns:
Quaternion(q=self.q.copy()) – copy of this quaternion
- Return type:
- normalize()[source]¶
Normalize this quaternion.
Note that this function changes wxyz property.
Examples
>>> from skrobot.coordinates.quaternion import Quaternion >>> q = Quaternion([1, 2, 3, 4]) >>> q.q array([1., 2., 3., 4.]) >>> q.normalize() >>> q.q array([0.18257419, 0.36514837, 0.54772256, 0.73029674])
- __eq__(value, /)¶
Return self==value.
- __ne__(value, /)¶
Return self!=value.
- __lt__(value, /)¶
Return self<value.
- __le__(value, /)¶
Return self<=value.
- __gt__(value, /)¶
Return self>value.
- __ge__(value, /)¶
Return self>=value.
Attributes
- angle¶
Return rotation angle of this quaternion
- Returns:
theta – rotation angle with respect to self.axis
- Return type:
- axis¶
Return axis of this quaternion.
Note that this property return normalized axis.
- Returns:
axis – normalized axis vector
- Return type:
- conjugate¶
Return conjugate of this quaternion
- Returns:
Quaternion – new Quaternion class has this quaternion’s conjugate
- Return type:
Examples
>>> from skrobot.coordinates.quaternion import Quaternion >>> q = Quaternion() >>> q.conjugate #<Quaternion 0x12f2dfb38 w: 1.0 x: -0.0 y: -0.0 z: -0.0> >>> q.q = [0, 1, 0, 0] >>> q.conjugate #<Quaternion 0x12f303c88 w: 0.0 x: -1.0 y: -0.0 z: -0.0>
- inverse¶
Return inverse of this quaternion
- Returns:
q – new Quaternion class has inverse of this quaternion
- Return type:
Examples
>>> from skrobot.coordinates.quaternion import Quaternion >>> q = Quaternion() >>> q #<Quaternion 0x127e6da58 w: 1.0 x: 0.0 y: 0.0 z: 0.0> >>> q.inverse #<Quaternion 0x1281bbda0 w: 1.0 x: -0.0 y: -0.0 z: -0.0> >>> q.q = [0, 1, 0, 0] >>> q.inverse #<Quaternion 0x1282b0cc0 w: 0.0 x: -1.0 y: -0.0 z: -0.0>
- norm¶
Return norm of this quaternion
- Returns:
quaternion_norm(self.q) – norm of this quaternion
- Return type:
Examples
>>> from skrobot.coordinates.quaternion import Quaternion >>> q = Quaternion() >>> q.norm 1.0 >>> q = Quaternion([1, 2, 3, 4]) >>> q.norm 5.477225575051661 >>> q.normalized.norm 0.9999999999999999
- normalized¶
Return Normalized quaternion.
- Returns:
normalized quaternion – return quaternion which is norm == 1.0.
- Return type:
Examples
>>> from skrobot.coordinates.quaternion import Quaternion >>> q = Quaternion([1, 2, 3, 4]) >>> normalized_q = q.normalized >>> normalized_q.q array([0.18257419, 0.36514837, 0.54772256, 0.73029674]) >>> q.q array([1., 2., 3., 4.])
- q¶
Return quaternion
- Returns:
self._q – [w, x, y, z] quaternion
- Return type:
Examples
>>> from skrobot.coordinates.quaternion import Quaternion >>> q = Quaternion() >>> q.q array([1., 0., 0., 0.]) >>> q = Quaternion(w=0.0, x=1.0, y=0.0, z=0.0) >>> q.q array([0., 1., 0., 0.])
- rotation¶
Return rotation matrix.
Note that this property internally normalizes quaternion.
- Returns:
quaternion2matrix(self.q) – 3x3 rotation matrix
- Return type:
Examples
>>> from skrobot.coordinates.quaternion import Quaternion >>> q = Quaternion() >>> q #<Quaternion 0x12f1aa6a0 w: 1.0 x: 0.0 y: 0.0 z: 0.0> >>> q.rotation array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) >>> q.q = [0, 1, 0, 0] >>> q #<Quaternion 0x12f1aa6a0 w: 0.0 x: 1.0 y: 0.0 z: 0.0> >>> q.rotation array([[ 1., 0., 0.], [ 0., -1., 0.], [ 0., 0., -1.]]) >>> q.q = [1, 2, 3, 4] >>> q #<Quaternion 0x12f1aa6a0 w: 1.0 x: 2.0 y: 3.0 z: 4.0> >>> q.rotation array([[-0.66666667, 0.13333333, 0.73333333], [ 0.66666667, -0.33333333, 0.66666667], [ 0.33333333, 0.93333333, 0.13333333]])
- xyz¶
Return xyz vector of this quaternion
- Returns:
quaternion_xyz – xyz elements of this quaternion
- Return type: