sisl.Quaternion

class sisl.Quaternion

Bases: object

Quaternion object to enable easy rotational quantities.

Parameters:
  • *args – For 1 argument, it is the length 4 vector describing the quaternion. For 2 arguments, it is the angle, and vector.

  • rad – when passing two arguments, for angle and vector, the rad value decides which unit angle is in, for rad=True it is in radians. Otherwise it will be in degrees.

Examples

Construct a quaternion with angle 45°, all 3 are equivalent:

>>> q1 = Quaternion(45, [1, 2, 3], rad=False)
>>> q2 = Quaternion(np.pi/4, [1, 2, 3], rad=True)
>>> q3 = Quaternion([1, 2, 3], 45, rad=False)

If you have the full quaternion complex number, one can also instantiate it directly without having to consider angles:

>>> q = Quaternion([1, 2, 3, 4])

Methods

angle([in_rad])

Return the angle of this quaternion, in requested unit

conj()

Returns the conjugate of the quaternion

copy()

Return a copy of itself

norm()

Returns the norm of this quaternion

rotate(v)

Rotate a vector v by this quaternion

Attributes

degree

Returns the angle associated with this quaternion (in degrees)

radian

Returns the angle associated with this quaternion (in radians)

angle(in_rad=True)[source]

Return the angle of this quaternion, in requested unit

Parameters:

in_rad (bool)

Return type:

float

conj()[source]

Returns the conjugate of the quaternion

Return type:

Quaternion

copy()[source]

Return a copy of itself

Return type:

Quaternion

norm()[source]

Returns the norm of this quaternion

Return type:

float

rotate(v)[source]

Rotate a vector v by this quaternion

This rotation method uses the fast method which can be expressed as:

v=qvq

But using a faster approach (more numerically stable), we can use this relation:

t=2q\crossvv=v+qwt+q\crosst
Return type:

ndarray

property degree: float

Returns the angle associated with this quaternion (in degrees)

property radian: float

Returns the angle associated with this quaternion (in radians)