Package Scientific :: Package Geometry :: Module Quaternion :: Class Quaternion
[hide private]
[frames] | no frames]

Class Quaternion



Quaternion (hypercomplex number)

This implementation of quaternions is not complete; only the features needed for representing rotation matrices by quaternions are implemented.

Quaternions support addition, subtraction, and multiplication, as well as multiplication and division by scalars. Division by quaternions is not provided, because quaternion multiplication is not associative. Use multiplication by the inverse instead.

The four components can be extracted by indexing.

Instance Methods [hide private]
  __add__(self, other)
  __div__(self, other)
  __getitem__(self, item)
  __init__(self, *data)
There are two calling patterns:
  __mul__(self, other)
  __rdiv__(self, other)
  __repr__(self)
  __rmul__(self, other)
  __sub__(self, other)
Numeric.array asMatrix(self)
Returns a 4x4 matrix representation
Scientific.Geometry.Transformation.Rotation asRotation(self)
Returns the corresponding rotation matrix
  dot(self, other)
Quaternion inverse(self)
Returns the inverse
float norm(self)
Returns the norm
Quaternion normalized(self)
Returns the quaternion scaled such that its norm is 1

Class Variables [hide private]
  _matrix = array([[[ 1, 0, 0, 0], [ 0, -1, 0, 0], [ 0, 0, -1, 0...
  _rot = array([[[[ 1, 0, 0, 0], [ 0, 1, 0, 0], [ 0, 0, -1, 0...
  is_quaternion = 1

Method Details [hide private]

__add__(self, other)
(Addition operator)

 

__div__(self, other)

 

__getitem__(self, item)
(Indexing operator)

 

__init__(self, *data)
(Constructor)

 

There are two calling patterns:
  • Quaternion(q0, q1, q2, q3) (from four real components)
  • Quaternion(q) (from a sequence containing the four components)

__mul__(self, other)

 

__rdiv__(self, other)

 

__repr__(self)
(Representation operator)

 

__rmul__(self, other)

 

__sub__(self, other)
(Subtraction operator)

 

asMatrix(self)

 
Returns: Numeric.array
a 4x4 matrix representation

asRotation(self)

 
Returns: Scientific.Geometry.Transformation.Rotation
the corresponding rotation matrix
Raises:
  • ValueError - if the quaternion is not normalized

dot(self, other)

 

inverse(self)

 
Returns: Quaternion
the inverse

norm(self)

 
Returns: float
the norm

normalized(self)

 
Returns: Quaternion
the quaternion scaled such that its norm is 1

Class Variable Details [hide private]

_matrix

Value:
array([[[ 1,  0,  0,  0],
        [ 0, -1,  0,  0],
        [ 0,  0, -1,  0],
        [ 0,  0,  0, -1]],
       [[ 0,  1,  0,  0],
        [ 1,  0,  0,  0],
        [ 0,  0,  0, -1],
        [ 0,  0,  1,  0]],
...                                                                    
      

_rot

Value:
array([[[[ 1,  0,  0,  0],
         [ 0,  1,  0,  0],
         [ 0,  0, -1,  0],
         [ 0,  0,  0, -1]],
        [[ 0,  0,  0, -2],
         [ 0,  0,  2,  0],
         [ 0,  0,  0,  0],
         [ 0,  0,  0,  0]],
...                                                                    
      

is_quaternion

Value:
1