Search
Verify that formula (7.112) in PRO-Lecture.pdf for quaternion composition holds true. It is already present in the script in Maple, you just need to rewrite it in Python using sympy package.
sympy
Create a function check_7112(theta1_half, theta2_half, v_theta, v_phi, u_theta, u_phi) which takes two rotation half-angles theta1_half and theta2_half and also parameters v_theta, v_phi, u_theta, u_phi for defining two normalized rotation axes $(~v = [v_1, v_2, v_3]^T, u = [u_1, u_2, u_3]^T$) and returns RR21-R21 following the example in the script. In order to express the coordinates of $v$ and $u$ explicitly, it is convenient to use the trigonometric parametrization of the unit sphere.
check_7112(theta1_half, theta2_half, v_theta, v_phi, u_theta, u_phi)
theta1_half
theta2_half
v_theta, v_phi, u_theta, u_phi
RR21-R21
Input/Output specifications:
v_theta, v_phi
u_theta, u_phi
Inside check_7112 define $v$ and $u$ as follows:
check_7112
def check_7112(theta1_half, theta2_half, v_theta, v_phi, u_theta, u_phi): s1 = sympy.sin(theta1_half) c1 = sympy.cos(theta1_half) s2 = sympy.sin(theta2_half) c2 = sympy.cos(theta2_half) v1 = sympy.cos(v_theta) * sympy.sin(v_phi) v2 = sympy.sin(v_theta) * sympy.sin(v_phi) v3 = sympy.cos(v_phi) u1 = sympy.cos(u_theta) * sympy.sin(u_phi) u2 = sympy.sin(u_theta) * sympy.sin(u_phi) u3 = sympy.cos(u_phi) v = sympy.Matrix([v1, v2, v3]) u = sympy.Matrix([u1, u2, u3])
Also, create function R_from_theta_half_axis(theta, v) that takes as input rotation half-angle theta_half (sympy symbol) and axis v (sympy Matrix, 3×1, already normalized) and returns rotation matrix $R$ (sympy Matrix).
R_from_theta_half_axis(theta, v)
theta_half
v
Verify that formula (7.116) in PRO-Lecture.pdf for quaternion composition holds true:
q1
c1
s1v1
q2
c2
s2v2
q21
c21
s21v21
Create a function check_7116(theta1_half, theta2_half, v_theta, v_phi, u_theta, u_phi) which takes two rotation half-angles theta1_half and theta2_half and also parameters v_theta, v_phi, u_theta, u_phi for defining two normalized rotation axes ($v = [v_1, v_2, v_3]^T, u = [u_1, u_2, u_3]^T$) and returns q2q1 - q21 (4×1, sympy Matrix, expected to be zeros).
check_7116(theta1_half, theta2_half, v_theta, v_phi, u_theta, u_phi)
q2q1 - q21
Create function R_from_q(q) that takes as input quaternion (sympy Matrix, 4×1) and returns rotation matrix $R$ (sympy Matrix, 3×3). Create function q_from_R(R) that takes as input rotation matrix $R$ (sympy Matrix, 3×3) and returns quaternion (sympy Matrix, 4×1).
R_from_q(q)
q_from_R(R)
Verify the formula 7.116 with the given rotation. You can use q1.subs() to get numbers
q1.subs()
Implement the solution in a single file hw06.py. The file must contain the check_7112, R_from_theta_half_axis, check_7116, R_from_q, q_from_R functions, such that it can be imported (by an automatic evaluation) as
hw06.py
R_from_theta_half_axis
check_7116
R_from_q
q_from_R
import hw06 res = hw06.check_7112(theta1_half, theta2_half, v_theta, v_phi, u_theta, u_phi) R = hw06.R_from_theta_half_axis(theta_half, v) res = hw06.check_7116(theta1_half, theta2_half, v_theta, v_phi, u_theta, u_phi) R = R_from_q(q) q = q_from_R(R)
Create an empty dictionary in Python:
solution = {}
The keys for this dictionary will be:
“q1”
“q2”
“q21”
“R1”
“R2”
“R21”
Finally, save solution to hw06.json:
solution
hw06.json
import json with open("hw06.json", "w") as outfile: json.dump(solution, outfile)
hw06.zip
hw06.pdf