Skip to content

Instantly share code, notes, and snippets.

@rfzeg
Created August 10, 2018 09:57
Show Gist options
  • Save rfzeg/089a3126131716a97ccd4efc8976e740 to your computer and use it in GitHub Desktop.
Save rfzeg/089a3126131716a97ccd4efc8976e740 to your computer and use it in GitHub Desktop.
Perform an intrinsic rotation sequence about the Y and then Z axes
from sympy import symbols, cos, sin, pi, sqrt
from sympy.matrices import Matrix
### Create symbols for joint variables
q1, q2 = symbols('q1:3')
# Create a symbolic matrix representing an intrinsic sequence of rotations
# about the Y and then Z axes. Let the rotation about the Y axis be described
# by q1 and the rotation about Z by q2.
# Replace R_y and R_z with the appropriate (symbolic) elementary rotation matrices
R_y = Matrix([[ cos(q1), 0, sin(q1)],
[ 0, 1, 0],
[-sin(q1), 0, cos(q1)]])
R_z = Matrix([[ cos(q2), -sin(q2), 0],
[ sin(q2), cos(q2), 0],
[ 0, 0, 1]])
# and then compute YZ_intrinsic
YZ_intrinsic_sym = R_y * R_z
# Numerically evaluate YZ_intrinsic assuming:
# q1 = 45 degrees and q2 = 60 degrees.
# NOTE: Trigonometric functions in Python assume the input is in radians!
print("Rotation about the Y-axis by 45-degrees and then about the Z-axis by 60-degrees")
YZ_intrinsic_num = YZ_intrinsic_sym.evalf(subs={q1: pi/4, q2: pi/3})
@rfzeg
Copy link
Author

rfzeg commented Aug 10, 2018

On intrinisic sequences of rotations the subsequent elementary rotations are post-multiplied

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment