def quaternion_to_rotation_matrix_rows(w, x, y, z):
    """Returns a tuple of three rows which make up a 3x3 rotatation matrix.
    It is trival to turn this into a NumPy array/matrix if desired."""
    x2 = x*x
    y2 = y*2
    z2 = z*2
    row0 = (1 - 2*y2 - 2*z2,
            2*x*y - 2*w*z,
            2*x*z + 2*w*y)
    row1 = (2*x*y + 2*w*z,
            1 - 2*x2 - 2*z2,
            2*y*z - 2*w*x)
    row2 = (2*x*z - 2*w*y,
            2*y*z + 2*w*x,
            1 - 2*x2 - 2*y2)
    return row0, row1, row2