Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions source/Tutorials/Intermediate/Tf2/Quaternion-Fundamentals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ Python
3 Inverting a quaternion
^^^^^^^^^^^^^^^^^^^^^^^^

An easy way to invert a quaternion is to negate the w-component:
An easy way to invert a quaternion is to negate the x-, y-, and z-components:

.. code-block:: python

q[3] = -q[3]
q[0] = -q[0]
q[1] = -q[1]
q[2] = -q[2]

.. note::

Expand Down Expand Up @@ -201,16 +203,16 @@ Here's an example to get the relative rotation from the previous robot pose to t

"""
# Extract the values from q0
w0 = q0[0]
x0 = q0[1]
y0 = q0[2]
z0 = q0[3]
x0 = q0[0]
y0 = q0[1]
z0 = q0[2]
w0 = q0[3]

# Extract the values from q1
w1 = q1[0]
x1 = q1[1]
y1 = q1[2]
z1 = q1[3]
x1 = q1[0]
y1 = q1[1]
z1 = q1[2]
w1 = q1[3]

# Compute the product of the two quaternions, term by term
q0q1_w = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1
Expand All @@ -224,10 +226,10 @@ Here's an example to get the relative rotation from the previous robot pose to t
# Return a 4 element array containing the final quaternion (q02,q12,q22,q32)
return final_quaternion

q1_inv[0] = prev_pose.pose.orientation.x
q1_inv[1] = prev_pose.pose.orientation.y
q1_inv[2] = prev_pose.pose.orientation.z
q1_inv[3] = -prev_pose.pose.orientation.w # Negate for inverse
q1_inv[0] = -prev_pose.pose.orientation.x # Negate for inverse
q1_inv[1] = -prev_pose.pose.orientation.y # Negate for inverse
q1_inv[2] = -prev_pose.pose.orientation.z # Negate for inverse
q1_inv[3] = prev_pose.pose.orientation.w

q2[0] = current_pose.pose.orientation.x
q2[1] = current_pose.pose.orientation.y
Expand Down