1 | import sympy as sp |
---|
2 | dphi, dpsi, dtheta = sp.var("dphi dpsi dtheta") |
---|
3 | phi, psi, theta = sp.var("phi psi theta") |
---|
4 | x, y, z = sp.var("x y z") |
---|
5 | qx, qy, qz = sp.var("qx qy qz") |
---|
6 | |
---|
7 | def Rx(a): |
---|
8 | return sp.Matrix([[1, 0, 0], [0, sp.cos(a), sp.sin(a)], [0, -sp.sin(a), sp.cos(a)]]) |
---|
9 | def Ry(a): |
---|
10 | return sp.Matrix([[sp.cos(a), 0, sp.sin(a)], [0, 1, 0], [-sp.sin(a), 0, sp.cos(a)]]) |
---|
11 | def Rz(a): |
---|
12 | return sp.Matrix([[sp.cos(a), sp.sin(a), 0], [-sp.sin(a), sp.cos(a), 0], [0, 0, 1]]) |
---|
13 | |
---|
14 | print("==== asymmetric ====") |
---|
15 | q = sp.Matrix([[qx],[qy],[0]]) |
---|
16 | p = sp.Matrix([[x],[y],[z]]) |
---|
17 | jitter = Rx(dphi)*Ry(dtheta)*Rz(dpsi) |
---|
18 | view = Rz(phi)*Ry(theta)*Rz(psi) |
---|
19 | jitter_inv = Rz(-dpsi)*Ry(-dtheta)*Rx(-dphi) |
---|
20 | view_inv = Rz(-psi)*Ry(-theta)*Rz(-phi) |
---|
21 | print(">> jitter rotation") |
---|
22 | for row in jitter*p: print(row) |
---|
23 | print("\n>> jitter plus view") |
---|
24 | for row in view*jitter*p: print(row) |
---|
25 | print("\n>> view reverse") |
---|
26 | for row in view_inv*q: print(row) |
---|
27 | print("\n>> jitter reverse") |
---|
28 | for row in jitter_inv*view_inv*q: print(row) |
---|
29 | |
---|
30 | print("\n\n==== symmetric ====") |
---|
31 | q = sp.Matrix([[qx],[0],[0]]) |
---|
32 | p = sp.Matrix([[x],[y],[z]]) |
---|
33 | jitter = Rx(dphi)*Ry(dtheta) |
---|
34 | view = Rz(phi)*Ry(theta) |
---|
35 | jitter_inv = Ry(-dtheta)*Rx(-dphi) |
---|
36 | view_inv = Ry(-theta)*Rz(-phi) |
---|
37 | print(">> jitter rotation") |
---|
38 | for row in jitter*p: print(row) |
---|
39 | print("\n>> jitter plus view") |
---|
40 | for row in view*jitter*p: print(row) |
---|
41 | print("\n>> view reverse") |
---|
42 | for row in view_inv*q: print(row) |
---|
43 | print("\n>> jitter reverse") |
---|
44 | for row in jitter_inv*view_inv*q: print(row) |
---|