sisl.Quaternion
- class sisl.Quaternion
Bases:
objectQuaternion 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
angleis in, forrad=Trueit 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
Returns the angle associated with this quaternion (in degrees)
Returns the angle associated with this quaternion (in radians)
- rotate(v)[source]
Rotate a vector v by this quaternion
This rotation method uses the fast method which can be expressed as:
\[\mathbf v' = \mathbf q \mathbf v \mathbf q ^*\]But using a faster approach (more numerically stable), we can use this relation:
\[\begin{split}\mathbf t = 2\mathbf q \cross \mathbf v \\ \mathbf v' = \mathbf v + q_w \mathbf t + \mathbf q \cross \mathbf t\end{split}\]- Return type: