Skip to content

Commit ee47611

Browse files
committed
Add detailed comments for quaternion multiplication
1 parent 9411593 commit ee47611

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/jaxsim/math/quaternion.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,17 @@ def derivative(
8787
# Construct pure quaternion: (scalar damping term, angular velocity components)
8888
ω_quat = jnp.hstack([K * safe_norm(ω) * (1 - safe_norm(quaternion)), ω])
8989

90-
# Apply quaternion multiplication based on frame representation
90+
# Quaternion multiplication using index tables.
91+
# This approach avoids using the explicit quaternion multiplication formula
92+
# by encoding the necessary element-wise products and signs via indexed operations.
93+
# Given two quaternions q and w, their Hamilton product q ⊗ w can be written
94+
# as a combination of q[i] * w[j] terms with appropriate signs.
95+
# i_idx and j_idx define which elements of the outer product q ⊗ w to select.
96+
# For example, i_idx[1][2] = 2 and j_idx[1][2] = 3 means: take q[2] * w[3] for this term.
97+
# sign_matrix[i][j] gives the sign (+1 or -1) to apply to each q[i] * w[j] term,
98+
# depending on quaternion multiplication rules.
99+
# This indexed summation reproduces the Hamilton product of quaternions in a
100+
# vectorized way, and is suitable for use with JAX.
91101
i_idx = jnp.array([[0, 1, 2, 3], [0, 1, 2, 3], [0, 2, 3, 1], [0, 3, 1, 2]])
92102
j_idx = jnp.array([[0, 1, 2, 3], [1, 0, 3, 2], [2, 0, 1, 3], [3, 0, 2, 1]])
93103
sign_matrix = jnp.array(

0 commit comments

Comments
 (0)