Skip to content

Commit d3924d1

Browse files
azzamshaikhkscottz
authored andcommitted
Update quaternion tutorial (#6069)
Signed-off-by: Katherine Scott <[email protected]> Co-authored-by: kscottz <[email protected]> (cherry picked from commit f08a6f9)
1 parent d2266cc commit d3924d1

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

source/Tutorials/Intermediate/Tf2/Quaternion-Fundamentals.rst

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@ Python
156156
3 Inverting a quaternion
157157
^^^^^^^^^^^^^^^^^^^^^^^^
158158

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

161161
.. code-block:: python
162162
163-
q[3] = -q[3]
163+
q[0] = -q[0]
164+
q[1] = -q[1]
165+
q[2] = -q[2]
164166
165167
.. note::
166168

@@ -201,16 +203,16 @@ Here's an example to get the relative rotation from the previous robot pose to t
201203
202204
"""
203205
# Extract the values from q0
204-
w0 = q0[0]
205-
x0 = q0[1]
206-
y0 = q0[2]
207-
z0 = q0[3]
206+
x0 = q0[0]
207+
y0 = q0[1]
208+
z0 = q0[2]
209+
w0 = q0[3]
208210
209211
# Extract the values from q1
210-
w1 = q1[0]
211-
x1 = q1[1]
212-
y1 = q1[2]
213-
z1 = q1[3]
212+
x1 = q1[0]
213+
y1 = q1[1]
214+
z1 = q1[2]
215+
w1 = q1[3]
214216
215217
# Compute the product of the two quaternions, term by term
216218
q0q1_w = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1
@@ -224,10 +226,10 @@ Here's an example to get the relative rotation from the previous robot pose to t
224226
# Return a 4 element array containing the final quaternion (q02,q12,q22,q32)
225227
return final_quaternion
226228
227-
q1_inv[0] = prev_pose.pose.orientation.x
228-
q1_inv[1] = prev_pose.pose.orientation.y
229-
q1_inv[2] = prev_pose.pose.orientation.z
230-
q1_inv[3] = -prev_pose.pose.orientation.w # Negate for inverse
229+
q1_inv[0] = -prev_pose.pose.orientation.x # Negate for inverse
230+
q1_inv[1] = -prev_pose.pose.orientation.y # Negate for inverse
231+
q1_inv[2] = -prev_pose.pose.orientation.z # Negate for inverse
232+
q1_inv[3] = prev_pose.pose.orientation.w
231233
232234
q2[0] = current_pose.pose.orientation.x
233235
q2[1] = current_pose.pose.orientation.y

0 commit comments

Comments
 (0)