(deflection=1.0, seed=None)
return M
Creates a random rotation matrix.

    deflection: the magnitude of the rotation. For 0, no rotation; for 1, completely random
    rotation. Small deflection => small perturbation.

    DOI: http://www.realtimerendering.com/resources/GraphicsGems/gemsiii/rand_rotation.c
         http://blog.lostinmyterminal.com/python/2015/05/12/random-rotation-matrix.html
Creates a random rotation matrix.
Creates a random rotation matrix .
def rand_rotation_matrix(deflection=1.0, seed=None):
    """Creates a random rotation matrix.

    deflection: the magnitude of the rotation. For 0, no rotation; for 1, completely random
    rotation. Small deflection => small perturbation.

    DOI: http://www.realtimerendering.com/resources/GraphicsGems/gemsiii/rand_rotation.c
         http://blog.lostinmyterminal.com/python/2015/05/12/random-rotation-matrix.html
    """
    if seed is not None:
        np.random.seed(seed)

    randnums = np.random.uniform(size=(3,))

    theta, phi, z = randnums

    theta = theta * 2.0 * deflection * np.pi  # Rotation about the pole (Z).
    phi = phi * 2.0 * np.pi  # For direction of pole deflection.
    z = z * 2.0 * deflection  # For magnitude of pole deflection.

    # Compute a vector V used for distributing points over the sphere
    # via the reflection I - V Transpose(V).  This formulation of V
    # will guarantee that if x[1] and x[2] are uniformly distributed,
    # the reflected points will be uniform on the sphere.  Note that V
    # has length sqrt(2) to eliminate the 2 in the Householder matrix.

    r = np.sqrt(z)
    V = (np.sin(phi) * r, np.cos(phi) * r, np.sqrt(2.0 - z))

    st = np.sin(theta)
    ct = np.cos(theta)

    R = np.array(((ct, st, 0), (-st, ct, 0), (0, 0, 1)))

    # Construct the rotation matrix  ( V Transpose(V) - I ) R.
    M = (np.outer(V, V) - np.eye(3)).dot(R)
    return M
def rand_rotation_matrix ( deflection = 1.0 , seed = None ) : if seed is not None : np . random . seed ( seed ) randnums = np . random . uniform ( size = ( 3 , ) ) theta , phi , z = randnums theta = theta * 2.0 * deflection * np . pi # Rotation about the pole (Z). phi = phi * 2.0 * np . pi # For direction of pole deflection. z = z * 2.0 * deflection # For magnitude of pole deflection. # Compute a vector V used for distributing points over the sphere # via the reflection I - V Transpose(V).  This formulation of V # will guarantee that if x[1] and x[2] are uniformly distributed, # the reflected points will be uniform on the sphere.  Note that V # has length sqrt(2) to eliminate the 2 in the Householder matrix. r = np . sqrt ( z ) V = ( np . sin ( phi ) * r , np . cos ( phi ) * r , np . sqrt ( 2.0 - z ) ) st = np . sin ( theta ) ct = np . cos ( theta ) R = np . array ( ( ( ct , st , 0 ) , ( - st , ct , 0 ) , ( 0 , 0 , 1 ) ) ) # Construct the rotation matrix  ( V Transpose(V) - I ) R. M = ( np . outer ( V , V ) - np . eye ( 3 ) ) . dot ( R ) return M