示例#1
0
def angle_axis2euler(theta, vector, is_normalized=False):
    """
        Convert angle, axis pair to Euler angles
        Parameters
        ----------
        theta : scalar
           angle of rotation
        vector : 3 element sequence
           vector specifying axis for rotation.
        is_normalized : bool, optional
           True if vector is already normalized (has norm of 1).  Default
           False
        Returns
        -------
        z : scalar
        y : scalar
        x : scalar
           Rotations in radians around z, y, x axes, respectively
        Examples
        --------
        >>> z, y, x = angle_axis2euler(0, [1, 0, 0])
        >>> np.allclose((z, y, x), 0)
        True
        Notes
        -----
        It's possible to reduce the amount of calculation a little, by
        combining parts of the ``angle_axis2mat`` and ``mat2euler``
        functions, but the reduction in computation is small, and the code
        repetition is large.
    """
    # Delayed import to avoid cyclic dependencies
    import nibabel.quaternions as nq
    M = nq.angle_axis2mat(theta, vector, is_normalized)
    return mat2euler(M)
示例#2
0
def transformEuler(eul1,rot_type,rot):
    mat1 = euler2mat(*eul1)

    if rot_type == "angle_axis":
        ang1,ax1 = rot
        tmat1 = angle_axis2mat(ax1,ang1)
    elif rot_type == "mat":
        tmat1 = rot
    elif rot_type == "euler":
        eul1 = rot
        tmat1 = euler2mat(*eul1)
    elif rot_type == "towards":
        targ_vec1,ang1 = rot
        cur_vec1 = euler2mat(*eul1)[:,0]
        ax_rot1 = cross(cur_vec1,targ_vec1)
        tmat1 = angle_axis2mat(ang1,ax_rot1)
    else: raise Exception("rotation type %s not understood"%rot_type)
    mat1new = dot(tmat1,mat1)
    return mat2euler(mat1new)
示例#3
0
def minRot(ax1, ax2):
    "find the rotation matrix that takes ax1 to ax2"
    if almostEq(ax1, ax2):
        L.debug("minRot: same vector")
        return eye(3)
    elif almostEq(ax1, -ax2):
        L.debug("minRot: opp vector")
        return -diag([-1, -1, 0])
    else:
        ax_rot = cross(ax2, ax1)
        return angle_axis2mat(angBetween(ax1, ax2), ax_rot)
示例#4
0
def transformEuler(eul1, rot_type, rot):
    mat1 = euler2mat(*eul1)

    if rot_type == "angle_axis":
        ang1, ax1 = rot
        tmat1 = angle_axis2mat(ax1, ang1)
    elif rot_type == "mat":
        tmat1 = rot
    elif rot_type == "euler":
        eul1 = rot
        tmat1 = euler2mat(*eul1)
    elif rot_type == "towards":
        targ_vec1, ang1 = rot
        cur_vec1 = euler2mat(*eul1)[:, 0]
        ax_rot1 = cross(cur_vec1, targ_vec1)
        tmat1 = angle_axis2mat(ang1, ax_rot1)
    else:
        raise Exception("rotation type %s not understood" % rot_type)
    mat1new = dot(tmat1, mat1)
    return mat2euler(mat1new)
示例#5
0
def minRot(ax1,ax2):
    "find the rotation matrix that takes ax1 to ax2"
    if almostEq(ax1,ax2):
        L.debug("minRot: same vector")
        return eye(3)
    elif almostEq(ax1,-ax2):
        L.debug("minRot: opp vector")
        return -diag([-1,-1,0])
    else:
        ax_rot = cross(ax2,ax1)
        return angle_axis2mat(angBetween(ax1,ax2),ax_rot)
示例#6
0
def create_transform(table, slice, row):
    """ Iterates through the motion data table and generates transformation matrices
    
    Args:
        param1: motion_trajectory_data (numpy array)
        param2: slice number
        param3: row number (k-space line)
    
    Returns:
            transformation object corresponding to a 4x4 transformation matrix
    """
    shift = table[slice, row, 0]
    angle = (table[slice, row, 1])
    axis = table[slice, row, 2]
    rot_matrix = quaternions.angle_axis2mat(angle, axis)
    affine_transform = affine_translate(sitk.AffineTransform(3), shift[0],
                                        shift[1], shift[2])
    combined_transform = affine_rotate(affine_transform, rot_matrix)
    return combined_transform
示例#7
0
def angle_axis2euler(theta, vector, is_normalized=False):
    """ Convert angle, axis pair to Euler angles

    Parameters
    ----------
    theta : scalar
       angle of rotation
    vector : 3 element sequence
       vector specifying axis for rotation.
    is_normalized : bool, optional
       True if vector is already normalized (has norm of 1).  Default
       False

    Returns
    -------
    z : scalar
    y : scalar
    x : scalar
       Rotations in radians around z, y, x axes, respectively

    Examples
    --------
    >>> z, y, x = angle_axis2euler(0, [1, 0, 0])
    >>> np.allclose((z, y, x), 0)
    True

    Notes
    -----
    It's possible to reduce the amount of calculation a little, by
    combining parts of the ``angle_axis2mat`` and ``mat2euler``
    functions, but the reduction in computation is small, and the code
    repetition is large.
    """
    # delayed import to avoid cyclic dependencies
    import nibabel.quaternions as nq

    M = nq.angle_axis2mat(theta, vector, is_normalized)
    return mat2euler(M)
示例#8
0
def applyRotEul(eul, ang, ax):
    return mat2euler(dot(angle_axis2mat(-ang, ax), euler2mat(*eul)))
示例#9
0
def applyRotVec(x, ang, ax, origin):
    return dot(angle_axis2mat(ang, ax), x - origin[:, None]) + origin[:, None]
示例#10
0
def applyTwist(thread, twist1, twist2):
    "twist the ends"
    _, or1, _, or2 = getState(thread)
    thread.applyMotion(zeros(3), angle_axis2mat(twist1, or1), zeros(3),
                       angle_axis2mat(twist2, or2))
示例#11
0
文件: twists.py 项目: joschu/surgical
def applyRotEul(eul,ang,ax):
    return mat2euler(dot(angle_axis2mat(-ang,ax),euler2mat(*eul)))
示例#12
0
def applyRotVec(x,ang,ax,origin):
    "rotate a vector x by ang around axis defined by ray origin+ax"
    return dot(angle_axis2mat(ang,ax),x-origin[:,None])+origin[:,None]
示例#13
0
def applyRotEul(eul,ang,ax):
    "compose a rotation of ang around ax with rotation given by euler angles eul"
    return mat2euler(dot(angle_axis2mat(ang,ax),euler2mat(*eul)))
示例#14
0
import mayavi.mlab as mlab
import numpy as np
from nibabel.quaternions import angle_axis2mat

x, y, z = xyz = np.load("xyz.npy")
# orig line
mlab.clf()
mlab.plot3d(x, y, z, color=(1, 0, 0), tube_radius=.1)
# fit quads to both ends

tri_inds = [0, 1, 2]
theta = .5
p0, p1, p2 = (xyz[:, i] for i in tri_inds)
ax_normal = np.cross(p1 - p0, p2 - p0)
ax_tan = p1 - p0
ax_rot = np.dot(angle_axis2mat(theta, ax_normal), ax_tan)

t = np.linspace(-2, 2, 30)
for ax in ax_normal, ax_tan, ax_rot:
    x, y, z = p0[:, None] + ax[:, None] * t[None, :]
    mlab.plot3d(x, y, z, color=(0, 1, 0), tube_radius=.1)
示例#15
0
def applyTwist(thread,twist1,twist2):
    "twist the ends"
    _,or1,_,or2 = getState(thread)
    thread.applyMotion(zeros(3),angle_axis2mat(twist1,or1),zeros(3),angle_axis2mat(twist2,or2))
示例#16
0
import mayavi.mlab as mlab
import numpy as np
from nibabel.quaternions import angle_axis2mat

x,y,z = xyz = np.load("xyz.npy")
# orig line
mlab.clf()
mlab.plot3d(x,y,z,color=(1,0,0),tube_radius=.1)
# fit quads to both ends

tri_inds = [0,1,2]
theta = .5
p0,p1,p2 = (xyz[:,i] for i in tri_inds)
ax_normal = np.cross(p1-p0,p2-p0)
ax_tan = p1 - p0
ax_rot = np.dot(angle_axis2mat(theta,ax_normal),ax_tan)

t = np.linspace(-2,2,30)
for ax in ax_normal,ax_tan,ax_rot:
    x,y,z = p0[:,None] + ax[:,None]*t[None,:]
    mlab.plot3d(x,y,z,color=(0,1,0),tube_radius=.1)
示例#17
0
文件: twists.py 项目: joschu/surgical
def applyRotVec(x,ang,ax,origin):
    return dot(angle_axis2mat(ang,ax),x-origin[:,None])+origin[:,None]