Ejemplo n.º 1
0
 def rotate_z(cls, angle, dtype=FLOAT) -> 'Transform':
     m = np.eye(4, 4, dtype=dtype)
     sin_t = np.sin(np.deg2rad(angle))
     cos_t = np.cos(np.deg2rad(angle))
     m[0][0] = cos_t
     m[0][1] = -sin_t
     m[1][0] = sin_t
     m[1][1] = cos_t
     return cls(m, m.T, dtype)
Ejemplo n.º 2
0
def slerp(t: FLOAT, q1: 'Quaternion', q2: 'Quaternion') -> 'Quaternion':
    cos_theta = dot(q1, q2)
    if (cos_theta > 1. - EPS):
        return ((1. - t) * q1 + t * q2).normalized()
    else:
        theta = np.arccos(np.clip(cos_theta, -1., 1.))
        thetap = theta * t
        qperp = (q2 - q1 * cos_theta).normalized()
        return q1 * np.cos(thetap) + qperp * np.sin(thetap)
Ejemplo n.º 3
0
    def rotate(cls, angle, axis: 'geo.Vector', dtype=FLOAT) -> 'Transform':
        a = geo.normalize(axis)

        s = np.sin(np.deg2rad(angle))
        c = np.cos(np.deg2rad(angle))

        m = np.eye(4, 4, dtype=dtype)

        m[0][0] = a.x * a.x + (1. - a.x * a.x) * c
        m[0][1] = a.x * a.y * (1. - c) - a.z * s
        m[0][2] = a.x * a.z * (1. - c) + a.y * s
        m[1][0] = a.x * a.y * (1. - c) + a.z * s
        m[1][1] = a.y * a.y + (1. - a.y * a.y) * c
        m[1][2] = a.y * a.z * (1. - c) - a.x * s
        m[2][0] = a.x * a.z * (1. - c) - a.y * s
        m[2][1] = a.y * a.z * (1. - c) + a.x * s
        m[2][2] = a.z * a.z + (1. - a.z * a.z) * c

        return cls(m, m.T, dtype)