annotate Resources/Computations/ComputeShearOnSlice.py @ 1335:35469f75faa2

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 31 Mar 2020 15:47:29 +0200
parents 46cb2eedc2e0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
191
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 from sympy import *
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 import pprint
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 init_printing(use_unicode=True)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # Setup "T * S * M_shear" (Equation A.16)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 ex, ey, ew = symbols('ex ey ew')
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 sx, sy = symbols('sx, sy')
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 ti, tj = symbols('ti tj')
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 T = Matrix([[ 1, 0, 0, ti ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 [ 0, 1, 0, tj ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 [ 0, 0, 1, 0 ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 [ 0, 0, 0, 1 ]])
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 # Equation (A.15), if "sx == sy == f"
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 S = Matrix([[ sx, 0, 0, 0 ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 [ 0, sy, 0, 0 ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 [ 0, 0, 1, 0 ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 [ 0, 0, 0, 1 ]])
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 # MM_shear, in Equation (A.14)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 M = Matrix([[ 1, 0, ex, 0 ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 [ 0, 1, ey, 0 ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 [ 0, 0, 1, 0 ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 [ 0, 0, ew, 1 ]])
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 x, y, z, w = symbols('x y z w')
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 p = Matrix([ x, y, z, w ])
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 print("\nT =" % T)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 pprint.pprint(T);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 print("\nS =" % T)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 pprint.pprint(S);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 print("\nM'_shear =" % T)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 pprint.pprint(M);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 print("\nGeneral form of a Lacroute's shear matrix (Equation A.16): T * S * M'_shear =")
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 pprint.pprint(T * S * M);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 print("\nHence, alternative parametrization:")
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 a11, a13, a14, a22, a23, a24, a43 = symbols('a11 a13 a14 a22 a23 a24 a43')
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 A = Matrix([[ a11, 0, a13, a14 ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 [ 0, a22, a23, a24 ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 [ 0, 0, 1, 0 ],
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 [ 0, 0, a43, 1 ]])
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 pprint.pprint(A);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 v = A * p
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 v = v.subs(w, 1)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 print("\nAction of Lacroute's shear matrix A on plane z (taking w=1):\n%s\n" % v)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 print('Output x\' = %s\n' % (v[0]/v[3]))
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 print('Output y\' = %s\n' % (v[1]/v[3]))
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 print('Output z\' = %s\n' % (v[2]/v[3]))