source: sasmodels/explore/angles.py @ 64ca163

core_shell_microgelsmagnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 64ca163 was e755d8a, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

use sympy to create rotation formulae

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