concepts.math.rotationlib_xyzw#

Tools for converting between rotation representations.

Conventions#

  • All functions accept batches as well as individual rotations.

  • All rotation conventions match respective MuJoCo defaults (e.g., quaternions use wxyz convention).

    Note that this is DIFFERENT from PyBullet (which uses xyzw).

  • All angles are in radians.

  • Matricies follow LR convention.

  • Euler Angles are all relative with ‘xyz’ axes ordering.

  • See specific representation for more information.

Representations#

Euler

There are many euler angle frames – here we will strive to use the default in MuJoCo, which is eulerseq=’xyz’.

This frame is a relative rotating frame, about x, y, and z axes in order. Relative rotating means that after we rotate about x, then we use the new (rotated) y, and the same for z.

Quaternions

These are defined in terms of rotation (angle) about a unit vector (x, y, z) We use the following <qx, qy, qz, qw> convention:

qx = sin(angle / 2) * x
qy = sin(angle / 2) * y
qz = sin(angle / 2) * z
qw = cos(angle / 2)

Note that quaternions are ambiguous, because we can represent a rotation by angle about vector <x, y, z> and -angle about vector <-x, -y, -z>. To choose between these, we pick “first nonzero positive”, where we make the first nonzero element of the quaternion positive.

This can result in mismatches if you’re converting an quaternion that is not “first nonzero positive” to a different representation and back.

Axis Angle

Warning

(Not currently implemented) These are very straightforward. Rotation is angle about a unit vector.

XY Axes

Warning

(Not currently implemented) We are given x axis and y axis, and z axis is cross product of x and y.

Z Axis

Warning

This is NOT RECOMMENDED. Defines a unit vector for the Z axis, but rotation about this axis is not well defined.

Instead pick a fixed reference direction for another axis (e.g. X) and calculate the other (e.g. Y = Z cross-product X), then use XY Axes rotation instead.

SO3

Warning

(Not currently implemented) While not supported by MuJoCo, this representation has a lot of nice features. We expect to add support for these in the future.

TODOs/Missings
  • Rotation integration or derivatives (e.g. velocity conversions)

  • More representations (SO3, etc)

  • Random sampling (e.g. sample uniform random rotation)

  • Performance benchmarks/measurements

  • (Maybe) define everything as to/from matricies, for simplicity

Functions

as_rotation(r)

Convert a 3x3 matrix or a quaternion into a standard 3x3 matrix representation.

as_rotation_xyzw(r)

Convert a 3x3 matrix or a quaternion into a standard 3x3 matrix representation.

axisangle2quat(axis, angle)

axisangle2quat_xyzw(axis, angle)

cross(a, b)

This is a walk around of an type annotation bug of numpy when used in pycharm

enumerate_quaternion_from_vectors(...[, ...])

Enumerate all possible quaternions that rotate input_normal to target_normal.

enumerate_quaternion_from_vectors_xyzw(...)

Enumerate all possible quaternions that rotate input_normal to target_normal.

euler2mat(euler[, homogeneous])

Convert Euler Angles to Rotation Matrix.

euler2point_euler(euler)

euler2quat(euler)

Convert Euler Angles to Quaternions.

euler2quat_xyzw(euler)

Convert Euler Angles to Quaternions.

find_orthogonal_vector(v)

Find an orthogonal vector to the given vector.

get_parallel_rotations()

Returns a list of all possible rotations that are parallel to the canonical axes.

mat2euler(mat)

Convert Rotation Matrix to Euler Angles.

mat2pos_quat(mat)

Convert a 4x4 matrix to a position and quaternion vector.

mat2pos_quat_xyzw(mat)

Convert a 4x4 matrix to a position and quaternion vector.

mat2quat(mat)

Convert Rotation Matrix to Quaternion.

mat2quat_xyzw(mat)

Convert Rotation Matrix to Quaternion.

normalize_angles(angles)

Puts angles in [-pi, pi] range.

normalize_vector(v)

Normalize a vector.

point_euler2euler(euler)

point_quat2quat(quat)

point_quat2quat_xyzw(quat)

pos_quat2mat(pos, quat)

Convert position and quaternion to a 4x4 matrix.

pos_quat2mat_xyzw(pos, quat)

Convert position and quaternion to a 4x4 matrix.

quat2axisangle(quat)

quat2axisangle_xyzw(quat)

quat2euler(quat)

Convert Quaternion to Euler Angles.

quat2euler_xyzw(quat)

Convert Quaternion to Euler Angles.

quat2mat(quat[, homogeneous])

Convert Quaternion to Euler Angles.

quat2mat_xyzw(quat[, homogeneous])

Convert Quaternion to Euler Angles.

quat2point_quat(quat)

quat_conjugate(q)

quat_conjugate_xyzw(q)

quat_diff(q0, q1[, return_axis])

quat_diff_in_axis_angle(q0, q1)

quat_diff_in_axis_angle_xyzw(q0, q1)

quat_diff_xyzw(q0, q1[, return_axis])

quat_identity()

quat_identity_xyzw()

quat_mul(q0, q1, *args)

Multiply two quaternions.

quat_mul_xyzw(q0, q1, *args)

Multiply two quaternions.

quat_pow(q, n)

quat_pow_xyzw(q, n)

quat_rot_vec(q, v0)

quat_rot_vec_batch(q, v0)

quat_rot_vec_batch_xyzw(q, v0)

quat_rot_vec_xyzw(q, v0)

quat_xyzw2point_quat(quat)

quaternion_from_axes(x, y, z)

Converts a rotation matrix to a quaternion.

quaternion_from_axes_xyzw(x, y, z)

Converts a rotation matrix to a quaternion.

quaternion_from_vectors(vec1, vec2)

Create a rotation quaternion q such that q * vec1 = vec2.

quaternion_from_vectors_xyzw(vec1, vec2)

Create a rotation quaternion q such that q * vec1 = vec2.

rotate_vector(v, q)

Rotate a vector by a quaternion.

rotate_vector_batch(v_batch, q)

Rotate a vector by a quaternion.

rotate_vector_batch_xyzw(v_batch, q)

Rotate a vector by a quaternion.

rotate_vector_xyzw(v, q)

Rotate a vector by a quaternion.

round_to_straight_angles(angles)

Returns closest angle modulo 90 degrees

rpy(r, p, y[, degree])

Create a quaternion from euler angles.

slerp(q0, q1, t)

Spherical linear interpolation between two quaternions.

slerp_xyzw(q0, q1, t)

Spherical linear interpolation between two quaternions.

subtract_euler(e1, e2)

wxyz2xyzw(quat)

xyzw2wxyz(quat)