Geometry utilities#
Genesis World ships a library of geometry helpers for rotations, quaternions, and rigid transforms. They are exposed both at the top level as gs.<name> and under genesis.utils.geom, and they accept NumPy arrays or PyTorch tensors, operating on single values or batches. Use them to build poses, convert between rotation representations, and transform points between frames.
All of them follow the project conventions: quaternions are (w, x, y, z) scalar-first (Hamilton), euler_to_quat and euler_to_R take degrees in extrinsic x-y-z order, and the world frame is right-handed and Z-up. See Conventions for the full set.
import genesis as gs
gs.init()
# Euler (degrees, extrinsic x-y-z) to quaternion (w, x, y, z)
quat = gs.euler_to_quat((0, 0, 90))
# Rotate a point by a quaternion
p_world = gs.transform_by_quat((1.0, 0.0, 0.0), quat)
# Apply a full rigid transform: rotate then translate
p_world = gs.transform_by_trans_quat((1.0, 0.0, 0.0), trans=(0, 0, 1), quat=quat)
Rotation conversions#
Rotations can be expressed as Euler angles, quaternions, 3×3 matrices, rotation vectors, or 4×4 homogeneous transforms. These convert between them.
Function |
Converts |
|---|---|
|
Euler degrees (extrinsic x-y-z) to quaternion |
|
Euler degrees to 3×3 rotation matrix |
|
Euler angles to quaternion, with unit and order options |
|
Quaternion to Euler angles |
|
Quaternion ↔ rotation matrix |
|
Rotation matrix to Euler angles |
|
Axis-angle to quaternion or matrix |
|
Quaternion ↔ rotation vector (axis × angle) |
Note
Argument order differs between axis_angle_to_quat(angle, axis) (angle first) and axis_angle_to_R(axis, theta) (axis first).
Quaternion operations#
Function |
Result |
|---|---|
|
Inverse (conjugate for unit quaternions) |
|
Quaternion product, composing rotation |
|
Rotate vector |
|
Rotate |
|
Spherical linear interpolation at fraction |
|
The identity quaternion |
Rigid transforms#
A rigid transform is a rotation plus a translation, stored either as a (trans, quat) pair or as a 4×4 homogeneous matrix T.
Function |
Result |
|---|---|
|
Rotate |
|
Inverse of the above |
|
|
|
Build a 4×4 matrix from translation and rotation matrix |
|
Apply |
|
Camera extrinsics: eye, target, up to a 4×4 matrix |
Vectors#
Function |
Result |
|---|---|
|
Scale a vector or batch to unit length |
|
Spherical angles to a unit |
Example: orienting an entity#
import genesis as gs
gs.init()
scene = gs.Scene()
box = scene.add_entity(gs.morphs.Box(pos=(0, 0, 0.5), size=(1.0, 1.0, 1.0)))
scene.build()
# Rotate 45 degrees about the world Z axis.
box.set_quat(gs.euler_to_quat((0, 0, 45)))
See also#
Conventions: coordinate frame, rotation, and quaternion conventions
Tensor utilities: converting between NumPy, PyTorch, and Genesis tensors