Utils

Quaternion Math

Quaternion helper functions

habitat_sim.utils.quat_from_coeffs(coeffs: numpy.array) → quaternion[source]

Creates a quaternion from the coeffs returned by the simulator backend

Parameters

coeffs (np.array) – Coefficients of a quaternion in [b, c, d, a] format, where q = a + bi + cj + dk

Returns

A quaternion from the coeffs

Return type

np.quaternion

habitat_sim.utils.quat_to_coeffs(quat: quaternion) → numpy.array[source]

Converts a quaternion into the coeffs format the backend expects

Parameters

quat (np.quaternion) – The quaternion

Returns

Coefficients of a quaternion in [b, c, d, a] format,

where q = a + bi + cj + dk

Return type

np.array

habitat_sim.utils.quat_from_angle_axis(theta: float, axis: numpy.array) → quaternion[source]

Creates a quaternion from angle axis format

Parameters
  • theta (float) – The angle to rotate about the axis by

  • axis (np.array) – The axis to rotate about.

Returns

The quaternion

Return type

np.quaternion

habitat_sim.utils.quat_to_angle_axis(quat: numpy.quantile) -> (<class 'float'>, <built-in function array>)[source]

Converts a quaternion to angle axis format

Parameters

quat (np.quaternion) – The quaternion

Returns

The angle to rotate about the axis by np.array: The axis to rotate about. If theta = 0, then this is harded coded to be the +x axis

Return type

float

habitat_sim.utils.quat_from_two_vectors(v0: numpy.array, v1: numpy.array) → quaternion[source]

Creates a quaternion that rotates the frist vector onto the second vector

v1 = (q * np.quaternion(0, *v0) * q.inverse()).imag

Parameters
  • v0 (np.array) – The starting vector, does not need to be a unit vector

  • v1 (np.array) – The end vector, does not need to be a unit vector

Returns

The quaternion

Return type

np.quaternion

habitat_sim.utils.angle_between_quats(q1: quaternion, q2: quaternion) → float[source]

Computes the angular distance between two quaternions

Parameters
  • q1 (np.quaternion) –

  • q2 (np.quaternion) –

Returns

The angular distance between q1 and q2 in radians

Return type

float

habitat_sim.utils.quat_rotate_vector(q: quaternion, v: numpy.array) → numpy.array[source]

Helper function to rotate a vector by a quaternion, simply does v = (q * np.quaternion(0, *v) * q.inverse()).imag

Parameters
  • q (np.quaternion) – The quaternion to rotate the vector with

  • v (np.array) – The vector to rotate

Returns

The rotated vector

Return type

np.array

Misc

habitat_sim.utils.colorize_ids(ids)[source]