|
| 1 | +from math import pi, sqrt |
| 2 | + |
1 | 3 | from ipywidgets import register
|
2 | 4 |
|
3 | 5 | from .._base.Three import ThreeWidget
|
@@ -30,6 +32,37 @@ def lookAt(self, vector):
|
30 | 32 | def rotateX(self, rad):
|
31 | 33 | self.exec_three_obj_method('rotateX', rad)
|
32 | 34 |
|
| 35 | + def rotateY(self, rad): |
| 36 | + self.exec_three_obj_method('rotateY', rad) |
| 37 | + |
| 38 | + def rotateZ(self, rad): |
| 39 | + self.exec_three_obj_method('rotateZ', rad) |
| 40 | + |
| 41 | + def setRotationFromMatrix(self, m): |
| 42 | + """ |
| 43 | + m is a 3 by 3 matrix, as a list of rows. The columns of this matrix are |
| 44 | + the vectors x, y, and z |
| 45 | + """ |
| 46 | + #x = self.normalize(m[0:3]) |
| 47 | + #y = self.normalize(m[3:6]) |
| 48 | + #z = self.normalize(m[6:9]) |
| 49 | + x = m[0:3] |
| 50 | + y = m[3:6] |
| 51 | + z = m[6:9] |
| 52 | + trace = x[0] + y[1] + z[2] |
| 53 | + if (trace > 0): |
| 54 | + s = 0.5 / sqrt(trace + 1) |
| 55 | + self.quaternion = [(y[2] - z[1]) * s, (z[0] - x[2]) * s, (x[1] - y[0]) * s, 0.25 / s] |
| 56 | + elif (x[0] > y[1] and x[0] > z[2]): |
| 57 | + s = 2.0 * sqrt(1.0 + x[0] - y[1] - z[2]) |
| 58 | + self.quaternion = [0.25 * s, (y[0] + x[1]) / s, (z[0] + x[2]) / s, (y[2] - z[1]) / s] |
| 59 | + elif (y[1] > z[2]): |
| 60 | + s = 2.0 * sqrt(1.0 + y[1] - x[0] - z[2]) |
| 61 | + self.quaternion = [(y[0] + x[1]) / s, 0.25 * s, (z[1] + y[2]) / s, (z[0] - x[2]) / s] |
| 62 | + else: |
| 63 | + s = 2.0 * sqrt(1.0 + z[2] - x[0] - y[1]) |
| 64 | + self.quaternion = [(z[0] + x[2]) / s, (z[1] + y[2]) / s, 0.25 * s, (x[1] - y[0]) / s] |
| 65 | + |
33 | 66 | def _repr_keys(self):
|
34 | 67 | # Don't include aggregate structures in repr
|
35 | 68 | super_keys = super(Object3D, self)._repr_keys()
|
|
0 commit comments