rotvec_to_quaternion

giant.rotations:

giant.rotations.rotvec_to_quaternion(rot_vec)[source]

This function converts a rotation vector given as a 3 element Sequence into a rotation quaternion of the form discussed in Rotation Representations.

The quaternion is returned as a numpy array and is formed by:

\[\begin{split}\theta = \left\|\mathbf{v}\right\| \\ \hat{\mathbf{x}} = \frac{\hat{\mathbf{x}}}{\theta} \\ \mathbf{q} = \left[\begin{array}{c} \text{sin}(\frac{\theta}{2})\mathbf{x} \\ \text{cos}(\frac{\theta}{2})\end{array}\right]\end{split}\]

This function is also vectorized, meaning that you can specify multiple rotation vectors to be converted to quaternions by specifying each vector as a column. Regardless of whether you are converting 1 or many vectors the first axis must have a length of 3.

This function makes the output have the same number of dimensions as the input. Therefore, if the input is one dimensional, then the output is one dimensional, and if the input is two dimensional then the output will be two dimensional. It also checks for cases when theta is nearly zero (less than 1e-15) and replaces these with the identity quaternion [0, 0, 0, 1].

Parameters:

rot_vec (Sequence | ndarray) – The rotation vector to convert to a rotation quaternion

Returns:

the rotation quaternion(s) corresponding to the input rotation vector(s)

Return type:

ndarray