1 #!/usr/bin/env python |
|
2 |
|
3 # This file is part of the Printrun suite. |
1 # This file is part of the Printrun suite. |
4 # |
2 # |
5 # Printrun is free software: you can redistribute it and/or modify |
3 # Printrun is free software: you can redistribute it and/or modify |
6 # it under the terms of the GNU General Public License as published by |
4 # it under the terms of the GNU General Public License as published by |
7 # the Free Software Foundation, either version 3 of the License, or |
5 # the Free Software Foundation, either version 3 of the License, or |
33 p1 = [p1x, p1y, project_to_sphere(TRACKBALLSIZE, p1x, p1y)] |
31 p1 = [p1x, p1y, project_to_sphere(TRACKBALLSIZE, p1x, p1y)] |
34 p2 = [p2x, p2y, project_to_sphere(TRACKBALLSIZE, p2x, p2y)] |
32 p2 = [p2x, p2y, project_to_sphere(TRACKBALLSIZE, p2x, p2y)] |
35 a = cross(p2, p1) |
33 a = cross(p2, p1) |
36 |
34 |
37 d = map(lambda x, y: x - y, p1, p2) |
35 d = map(lambda x, y: x - y, p1, p2) |
38 t = math.sqrt(sum(map(lambda x: x * x, d))) / (2.0 * TRACKBALLSIZE) |
36 t = math.sqrt(sum(x * x for x in d)) / (2.0 * TRACKBALLSIZE) |
39 |
37 |
40 if t > 1.0: |
38 if t > 1.0: |
41 t = 1.0 |
39 t = 1.0 |
42 if t < -1.0: |
40 if t < -1.0: |
43 t = -1.0 |
41 t = -1.0 |
44 phi = 2.0 * math.asin(t) |
42 phi = 2.0 * math.asin(t) |
45 |
43 |
46 return axis_to_quat(a, phi) |
44 return axis_to_quat(a, phi) |
47 |
45 |
48 def axis_to_quat(a, phi): |
46 def axis_to_quat(a, phi): |
49 lena = math.sqrt(sum(map(lambda x: x * x, a))) |
47 lena = math.sqrt(sum(x * x for x in a)) |
50 q = map(lambda x: x * (1 / lena), a) |
48 q = [x * (1 / lena) for x in a] |
51 q = map(lambda x: x * math.sin(phi / 2.0), q) |
49 q = [x * math.sin(phi / 2.0) for x in q] |
52 q.append(math.cos(phi / 2.0)) |
50 q.append(math.cos(phi / 2.0)) |
53 return q |
51 return q |
54 |
52 |
55 def build_rotmatrix(q): |
53 def build_rotmatrix(q): |
56 m = (GLdouble * 16)() |
54 m = (GLdouble * 16)() |