Coverage for navipy/maths/homogeneous_transformations.py : 80%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" """
""" Return matrix to translate by direction vector """ # get 4x4 identity matrix # set the first three rows of the last colum to be the direction vector
""" Return translation vector from translation matrix """ # returns the first three rows of the last colum in the rotation matrix
""" Return matrix to mirror at plane defined by point and normal vector """ # use only the first three columns of the normal vector # get 4x4 identity matrix # substract two times the outer product of the normal vector from the \ # upper left 3x3 matrix of the unit matrix to # set the fourth column of the resutlting matrix to 2* the dot product of \ # the point and the normal vector times the noraml vector
"""Return mirror plane point and normal vector from reflection matrix. """ # pointer to matrix (same as input) # normal: unit eigenvector corresponding to eigenvalue -1 # get eigenvectors with eigenvalue close to length 1 -> unit eigenvector; \ # only for the upper left 3x3 part raise ValueError("no unit eigenvector corresponding to eigenvalue -1") # choose only first of unit length eigenvectors # point: any unit eigenvector corresponding to eigenvalue 1 # find eigenvector with unit length for whole matrix raise ValueError("no unit eigenvector corresponding to eigenvalue 1") # choose last of the unit length eigenvectors
"""Return matrix to scale by factor around origin in direction. Use factor -1 for point symmetry. """ # uniform scaling else: # nonuniform scaling
"""Return scaling factor, origin and direction from scaling matrix. """ # direction: unit eigenvector corresponding to eigenvalue factor # uniform scaling # origin: any eigenvector corresponding to eigenvalue 1 raise ValueError("no eigenvector corresponding to eigenvalue 1")
perspective=None, pseudo=False): """Return matrix to project onto plane defined by point and normal.
Using either perspective point, projection direction, or none of both.
If pseudo is True, perspective projections will preserve relative depth such that Perspective = dot(Orthogonal, PseudoPerspective). """ # perspective projection copy=False) # preserve relative depth else: # parallel projection else: # orthogonal projection
"""Return projection plane and perspective point from projection matrix.
Return values are same as arguments for projection_matrix function: point, normal, direction, perspective, and pseudo. """ # point: any eigenvector corresponding to eigenvalue 1 # direction: unit eigenvector corresponding to eigenvalue 0 raise ValueError("no eigenvector corresponding to eigenvalue 0") # normal: unit eigenvector of M33.T corresponding to eigenvalue 0 # parallel projection else: # orthogonal projection, where normal equals direction vector return point, direction, None, None, False else: # perspective projection i = np.where(abs(np.real(w)) > 1e-8)[0] if not len(i): raise ValueError( "no eigenvector not corresponding to eigenvalue 0") point = np.real(V[:, i[-1]]).squeeze() point /= point[3] normal = - M[3, :3] perspective = M[:3, 3] / np.dot(point[:3], normal) if pseudo: perspective -= normal return point, normal, None, perspective, pseudo
"""Return matrix to shear by angle along direction vector on shear plane.
The shear plane is defined by a point and normal vector. The direction vector must be orthogonal to the plane's normal vector.
A point P is transformed by the shear matrix into P" such that the vector P-P" is parallel to the direction vector and its extent is given by the angle of P-P'-P", where P' is the orthogonal projection of P onto the shear plane. """ raise ValueError("direction and normal vectors are not orthogonal")
"""Return shear angle, direction and plane from shear matrix. """ M = np.array(matrix, dtype=np.float64, copy=False) M33 = M[:3, :3] # normal: cross independent eigenvectors corresponding to the eigenvalue 1 w, V = np.linalg.eig(M33) i = np.where(abs(np.real(w) - 1.0) < 1e-4)[0] if len(i) < 2: raise ValueError("no two linear independent eigenvectors found %s" % w) V = np.real(V[:, i]).squeeze().T lenorm = -1.0 for i0, i1 in ((0, 1), (0, 2), (1, 2)): n = np.cross(V[i0], V[i1]) w = vector_norm(n) if w > lenorm: lenorm = w normal = n normal /= lenorm # direction and angle direction = np.dot(M33 - np.identity(3), normal) angle = vector_norm(direction) direction /= angle angle = np.arctan(angle) # point: eigenvector corresponding to eigenvalue 1 w, V = np.linalg.eig(M) i = np.where(abs(np.real(w) - 1.0) < 1e-8)[0] if not len(i): raise ValueError("no eigenvector corresponding to eigenvalue 1") point = np.real(V[:, i[-1]]).squeeze() point /= point[3] return angle, direction, point, normal
"""Return sequence oftransformations from transformation matrix.
matrix : array_like Non-degenerative homogeneous transformation matrix
Return tuple of: scale : vector of 3 scaling factors shear : list of shear factors for x-y, x-z, y-z axes angles : list of Euler angles about static x, y, z axes translate : translation vector along x, y, z axes perspective : perspective partition of matrix
Raise ValueError if matrix is of wrong type or degenerative. """ raise ValueError("M[3, 3] is zero") raise ValueError("matrix is singular")
else:
np.negative(scale, scale) np.negative(row, row)
perspective=None, axes='xyz'): """Return transformation matrix from sequence oftransformations.
This is the inverse of the decompose_matrix function.
Sequence of transformations: scale : vector of 3 scaling factors shear : list of shear factors for x-y, x-z, y-z axes angles : list of Euler angles about static x, y, z axes translate : translation vector along x, y, z axes perspective : perspective partition of matrix """ R = quaternion.matrix(angles) else:
"""Return True if two matrices perform same transformation. """
"""Return True if two matrices perform same transformation. """ |