habitat_sim.utils.common module

Quaternion Math

Quaternion helper functions:

• quat_from_coeffs()
• quat_to_coeffs()
• quat_from_angle_axis()
• quat_to_angle_axis()
• quat_from_two_vectors()
• angle_between_quats()
• quat_rotate_vector()

Misc

• colorize_ids()

Functions

q1: quaternion.quaternion.quaternion, q2: quaternion.quaternion.quaternion) -> float
Computes the angular distance between two quaternions
def colorize_ids(ids)
file_url, local_directory)
theta: float, axis: numpy.ndarray) -> quaternion.quaternion.quaternion
Creates a quaternion from angle axis format
def quat_from_coeffs(coeffs: typing.Union[typing.Sequence[float], numpy.ndarray]) -> quaternion.quaternion.quaternion
Creates a quaternion from the coeffs returned by the simulator backend
def quat_from_magnum(quat: magnum.Quaternion) -> quaternion.quaternion.quaternion
v0: numpy.ndarray, v1: numpy.ndarray) -> quaternion.quaternion.quaternion
Creates a quaternion that rotates the first vector onto the second vector
q: quaternion.quaternion.quaternion, v: numpy.ndarray) -> numpy.ndarray
Helper function to rotate a vector by a quaternion
quat: quaternion.quaternion.quaternion) -> typing.Tuple[float, numpy.ndarray]
Converts a quaternion to angle axis format
def quat_to_coeffs(quat: quaternion.quaternion.quaternion) -> numpy.ndarray
Converts a quaternion into the coeffs format the backend expects
def quat_to_magnum(quat: quaternion.quaternion.quaternion) -> magnum.Quaternion
)
Convenience function to sample a random Magnum::Quaternion. See http://planning.cs.uiuc.edu/node198.html.

Data

d3_40_colors_hex: typing.List[str] = …
Color map for semantic ID rendering.
d3_40_colors_rgb: numpy.ndarray = …
Color map for semantic ID rendering.

Function documentation

def habitat_sim.utils.common.angle_between_quats(q1: quaternion.quaternion.quaternion, q2: quaternion.quaternion.quaternion) -> float

Computes the angular distance between two quaternions

Returns The angular distance between q1 and q2 in radians

def habitat_sim.utils.common.quat_from_angle_axis(theta: float, axis: numpy.ndarray) -> quaternion.quaternion.quaternion

Creates a quaternion from angle axis format

Parameters
theta The angle to rotate about the axis by
axis The axis to rotate about
Returns The quaternion

def habitat_sim.utils.common.quat_from_coeffs(coeffs: typing.Union[typing.Sequence[float], numpy.ndarray]) -> quaternion.quaternion.quaternion

Creates a quaternion from the coeffs returned by the simulator backend

Parameters
coeffs Coefficients of a quaternion in [b, c, d, a] format, where
Returns A quaternion from the coeffs

def habitat_sim.utils.common.quat_from_two_vectors(v0: numpy.ndarray, v1: numpy.ndarray) -> quaternion.quaternion.quaternion

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

Parameters
v0 The starting vector, does not need to be a unit vector
v1 The end vector, does not need to be a unit vector
Returns The quaternion

Calculates the quaternion q such that

v1 = quat_rotate_vector(q, v0)

def habitat_sim.utils.common.quat_rotate_vector(q: quaternion.quaternion.quaternion, v: numpy.ndarray) -> numpy.ndarray

Helper function to rotate a vector by a quaternion

Parameters
q The quaternion to rotate the vector with
v The vector to rotate
Returns The rotated vector

Does

v = (q * qt.quaternion(0, *v) * q.inverse()).imag

def habitat_sim.utils.common.quat_to_angle_axis(quat: quaternion.quaternion.quaternion) -> typing.Tuple[float, numpy.ndarray]

Converts a quaternion to angle axis format

Parameters
quat The quaternion
Returns
• float — The angle to rotate about the axis by
• numpy.ndarray — The axis to rotate about. If , then this is hardcoded to be the +x axis

def habitat_sim.utils.common.quat_to_coeffs(quat: quaternion.quaternion.quaternion) -> numpy.ndarray

Converts a quaternion into the coeffs format the backend expects

Parameters
quat The quaternion
Returns Coefficients of a quaternion in [b, c, d, a] format, where

Data documentation

habitat_sim.utils.common.d3_40_colors_hex: typing.List[str]

Color map for semantic ID rendering.

Same as d3_40_colors_rgb, but in a hexadecimal representation.

d3_40_colors_hex: List[str] = [
"0x1f77b4",
"0xaec7e8",
"0xff7f0e",
"0xffbb78",
"0x2ca02c",
"0x98df8a",
"0xd62728",
"0xff9896",
"0x9467bd",
"0xc5b0d5",
"0x8c564b",
"0xc49c94",
"0xe377c2",
"0xf7b6d2",
"0x7f7f7f",
"0xc7c7c7",
"0xbcbd22",
"0xdbdb8d",
"0x17becf",
"0x9edae5",
"0x393b79",
"0x5254a3",
"0x6b6ecf",
"0x9c9ede",
"0x637939",
"0x8ca252",
"0xb5cf6b",
"0xcedb9c",
"0x8c6d31",
"0xbd9e39",
"0xe7ba52",
"0xe7cb94",
"0x843c39",
]