PolyFEM
Loading...
Searching...
No Matches
generate_rotation_mtx.py
Go to the documentation of this file.
1from sympy import symbols, trace, det, log, Pow, Rational, MatrixSymbol, Matrix, ccode, sin, cos
2from sympy import *
3from sympy.matrices import *
4from sympy.printing import ccode
5from pretty_print import C99_print_tensor, C99_print
6import re
7
8x, y, z, alpha = symbols("point(0) point(1) point(2) alpha")
9
10cx, cy, cz = symbols("control_pt(0) control_pt(1) control_pt(2)")
11
12
13def rot_mtx(angle, axis):
14 R = None
15 if axis == 0:
16 R = Matrix([[1, 0, 0], [0, cos(angle), -sin(angle)],
17 [0, sin(angle), cos(angle)]])
18 elif axis == 1:
19 R = Matrix([[cos(angle), 0, sin(angle)], [0, 1, 0],
20 [-sin(angle), 0, cos(angle)]])
21 elif axis == 2:
22 R = Matrix([[cos(angle), -sin(angle), 0],
23 [sin(angle), cos(angle), 0], [0, 0, 1]])
24 else:
25 exit()
26 return R
27
28
29def rot_val(params):
30 p = Matrix([[x], [y], [z]])
31 R_mtx = rot_mtx(params[2], 2) @ rot_mtx(params[1],
32 1) @ rot_mtx(params[0], 0)
33
34 p -= Matrix([[cx], [cy], [cz]])
35 p = R_mtx @ p
36 p += Matrix([[cx], [cy], [cz]])
37 for i in range(3):
38 p[i] += params[3 + i]
39 return p
40
41
42dim = 6
43T = MatrixSymbol('param', dim, 1)
44T_ = Matrix(T)
45
46energy = rot_val(T_)
47grad = energy.diff(T_)
48
49e = []
50for i in range(3):
51 e.append(energy[i])
52print(C99_print(e))
53# exit()
54
55grad = grad[:, 0, :, 0]
56g = []
57for j in range(3):
58 for i in range(6):
59 g.append(grad[i, j])
60
61print(C99_print(g))