Ejemplo n.º 1
0
    def from_axis_angle(axis, angle, is_normalized=False):
        # adapted from
        # https://github.com/matthew-brett/transforms3d/blob/master/transforms3d/quaternions.py

        axis = Vector(axis) if not isinstance(axis, Vector) else axis

        if not is_normalized:
            axis.normalize()
        x, y, z = axis
        c = math.cos(angle)
        s = math.sin(angle)
        C = 1 - c
        xs = x * s
        ys = y * s
        zs = z * s
        xC = x * C
        yC = y * C
        zC = z * C
        xyC = x * yC
        yzC = y * zC
        zxC = z * xC
        return Orientation(np.array([
            [x * xC + c, xyC - zs, zxC + ys],
            [xyC + zs, y * yC + c, yzC - xs],
            [zxC - ys, yzC + xs, z * zC + c],
        ]))
Ejemplo n.º 2
0
 def from_yz(y_vec, z_vec):
     """
     Generate a new Orientation from two vectors using y as reference
     """
     if not isinstance(y_vec, Vector):
         y_vec = Vector(y_vec)
     if not isinstance(z_vec, Vector):
         z_vec = Vector(z_vec)
     y_vec.normalize()
     z_vec.normalize()
     orient = Orientation()
     orient.data[:, 1] = y_vec.data
     orient.data[:, 0] = y_vec.cross(z_vec).normalized().data
     orient.data[:, 2] = Vector(np.cross(orient.data[:, 0], y_vec.data)).normalized().data
     return orient
Ejemplo n.º 3
0
 def from_xy(x_vec, y_vec):
     """
     Generate a new Orientation from two vectors using x as reference
     """
     if not isinstance(x_vec, Vector):
         x_vec = Vector(x_vec)
     if not isinstance(y_vec, Vector):
         y_vec = Vector(y_vec)
     x_vec.normalize()
     y_vec.normalize()
     orient = Orientation()
     orient.data[:, 0] = x_vec.data
     orient.data[:, 2] = x_vec.cross(y_vec).normalized().data
     orient.data[:, 1] = Vector(np.cross(orient.data[:, 2], x_vec.data)).normalized().data
     return orient
Ejemplo n.º 4
0
 def from_xz(x_vec, z_vec):
     """
     Generate a new Orientation from two vectors using x as reference
     """
     if not isinstance(x_vec, Vector):
         x_vec = Vector(x_vec)
     if not isinstance(z_vec, Vector):
         z_vec = Vector(z_vec)
     x_vec.normalize()
     z_vec.normalize()
     orient = Orientation()
     orient._data[:, 0] = x_vec.data
     orient._data[:, 1] = z_vec.cross(x_vec).data
     orient._data[:, 2] = np.cross(x_vec.data, orient._data[:, 1])
     return orient
Ejemplo n.º 5
0
    def from_xz(x_vec, z_vec, ref='x'):
        """
        Generate a new Orientation from two vectors using x as reference
        """
        if not isinstance(x_vec, Vector):
            x_vec = Vector(x_vec)
        if not isinstance(z_vec, Vector):
            z_vec = Vector(z_vec)
        x_vec.normalize()
        z_vec.normalize()
        orient = Orientation()
        orient.data[:, 1] = z_vec.cross(x_vec).normalized().data

        if ref == 'x':
            orient.data[:, 0] = x_vec.data
            orient.data[:, 2] = Vector(np.cross(x_vec.data, orient.data[:, 1])).normalized().data
        elif ref == 'z':
            orient.data[:, 2] = z_vec.data
            orient.data[:, 0] = Vector(np.cross(orient.data[:, 1], z_vec.data)).normalized().data
        else:
            raise ValueError('Value of ref can only be x or z')

        return orient