def qinv(x, y, z, w):
    """
    compute quaternion inverse
    """
    inv_squared_magnitude = 1. / ( x*x + y*y + z*z + w*w )

    invx = -x * inv_squared_magnitude
    invy = -y * inv_squared_magnitude
    invz = -z * inv_squared_magnitude
    invw = w * inv_squared_magnitude

    return invx,invy,invz,invw