Exemple #1
0
Fichier : view.py Projet : adbX/ase
    def my_arc(self, gc, fill, j, X, r, n, A, d):

        if self.images.shapes is not None:
            rx = (self.images.shapes[j, 0]).round().astype(int)
            ry = (self.images.shapes[j, 1]).round().astype(int)
            rz = (self.images.shapes[j, 2]).round().astype(int)
            circle = rx == ry and ry == rz

            if not circle:
                Q = Quaternion(self.images.Q[self.frame][j])
                X2d = np.array([X[j][0], X[j][1]])
                Ellipsoid = np.array([[1. / (rx * rx), 0, 0],
                                      [0, 1. / (ry * ry), 0],
                                      [0, 0, 1. / (rz * rz)]])
                # Ellipsoid rotated by quaternion as Matrix X' = R X R_transpose
                El_r = np.dot(
                    Q.rotation_matrix(),
                    np.dot(Ellipsoid, np.transpose(Q.rotation_matrix())))
                # Ellipsoid rotated by quaternion and axes as
                # Matrix X' =  R_axes X' R_axes
                El_v = np.dot(np.transpose(self.axes), np.dot(El_r, self.axes))
                # Projection of rotated ellipsoid on xy plane
                El_p = Ell = np.array(
                    [[
                        El_v[0][0] - El_v[0][2] * El_v[0][2] / El_v[2][2],
                        El_v[0][1] - El_v[0][2] * El_v[1][2] / El_v[2][2]
                    ],
                     [
                         El_v[0][1] - El_v[0][2] * El_v[1][2] / El_v[2][2],
                         El_v[1][1] - El_v[1][2] * El_v[1][2] / El_v[2][2]
                     ]])
                # diagonal matrix der Ellipse gibt halbachsen
                El_p_diag = np.linalg.eig(El_p)
                # Winkel mit dem Ellipse in xy gedreht ist aus
                # eigenvektor der diagonal matrix
                phi = atan(El_p_diag[1][0][1] / El_p_diag[1][0][0])
                tupl = []
                alpha = np.array(range(16)) * 2 * np.pi / 16
                El_xy = np.array([
                    sqrt(1. /
                         (El_p_diag[0][0])) * np.cos(alpha) * np.cos(phi) -
                    sqrt(1. / (El_p_diag[0][1])) * np.sin(alpha) * np.sin(phi),
                    sqrt(1. /
                         (El_p_diag[0][0])) * np.cos(alpha) * np.sin(phi) +
                    sqrt(1. / (El_p_diag[0][1])) * np.sin(alpha) * np.cos(phi)
                ])

                tupl = (El_xy.transpose() * self.scale +
                        X[j][:2]).round().astype(int)
                # XXX there must be a better way
                tupl = [tuple(i) for i in tupl]

                return self.pixmap.draw_polygon(gc, fill, tupl)
            else:
                return self.pixmap.draw_arc(gc, fill, A[j, 0], A[j, 1], d[j],
                                            d[j], 0, 23040)
        else:
            return self.pixmap.draw_arc(gc, fill, A[j, 0], A[j, 1], d[j], d[j],
                                        0, 23040)
Exemple #2
0
    def my_arc(self, gc, fill, j, X, r, n, A, d):
   
        if self.images.shapes is not None:
            rx = (self.images.shapes[j, 0]).round().astype(int)
            ry = (self.images.shapes[j, 1]).round().astype(int)
            rz = (self.images.shapes[j, 2]).round().astype(int)
            circle = rx == ry and ry == rz

            if not circle:
                Q = Quaternion(self.images.Q[self.frame][j])
                X2d = np.array([X[j][0], X[j][1]])
                Ellipsoid = np.array([[1. / (rx*rx), 0, 0],
                                      [0, 1. / (ry*ry), 0],
                                      [0, 0, 1. / (rz*rz)]
                                      ])
                # Ellipsoid rotated by quaternion as Matrix X' = R X R_transpose
                El_r = np.dot(Q.rotation_matrix(),
                              np.dot(Ellipsoid, 
                                     np.transpose(Q.rotation_matrix())))
                # Ellipsoid rotated by quaternion and axes as 
                # Matrix X' =  R_axes X' R_axes
                El_v = np.dot(np.transpose(self.axes), np.dot(El_r, self.axes))
                # Projection of rotated ellipsoid on xy plane
                El_p = Ell = np.array([
                        [El_v[0][0] - El_v[0][2] * El_v[0][2] / El_v[2][2],
                         El_v[0][1] - El_v[0][2] * El_v[1][2] / El_v[2][2]],
                        [El_v[0][1] - El_v[0][2] * El_v[1][2] / El_v[2][2],
                         El_v[1][1] - El_v[1][2] * El_v[1][2] / El_v[2][2]]
                        ])
                # diagonal matrix der Ellipse gibt halbachsen
                El_p_diag = np.linalg.eig(El_p)
                # Winkel mit dem Ellipse in xy gedreht ist aus 
                # eigenvektor der diagonal matrix
                phi = atan(El_p_diag[1][0][1] / El_p_diag[1][0][0])
                tupl = []
                alpha = np.array(range(16)) * 2 * np.pi / 16
                El_xy = np.array([sqrt(1. / (El_p_diag[0][0])) *
                                  np.cos(alpha)*np.cos(phi) 
                                  - sqrt(1./(El_p_diag[0][1])) * 
                                  np.sin(alpha) * np.sin(phi),
                                  sqrt(1./(El_p_diag[0][0])) * 
                                  np.cos(alpha)*np.sin(phi)
                                  + sqrt(1./(El_p_diag[0][1])) * 
                                  np.sin(alpha) * np.cos(phi)])

                tupl = (El_xy.transpose() * self.scale + 
                        X[j][:2]).round().astype(int)
                # XXX there must be a better way
                tupl = [tuple(i) for i in tupl]

                return self.pixmap.draw_polygon( gc, fill, tupl)
            else:
                return self.pixmap.draw_arc(gc, fill, A[j, 0], A[j, 1], d[j],
                                            d[j], 0, 23040)
        else:
            return self.pixmap.draw_arc(gc, fill, A[j, 0], A[j, 1], d[j], d[j], 
                                        0, 23040)
def rotation(axis, angle):
    """ 
    Generate the rotation matrix 
    given the rotation axis and angle
    """
    norm = n.linalg.norm(axis)
    tol = 2 * n.finfo(n.float).eps
    q = [n.cos(angle / 2)]
    for a in axis:
        q.append(n.sin(angle / 2.0) * a / norm)
    q = Quaternion(q)
    matrix = q.rotation_matrix()
    matrix[abs(matrix) < tol] = 0.0
    return matrix