def rotation_matrix(d):
sin_angle = np.linalg.norm(d)<EOL>if sin_angle == <NUM_LIT:0>:<EOL><INDENT>return np.identity(<NUM_LIT:3>)<EOL><DEDENT>d /= sin_angle<EOL>eye = np.eye(<NUM_LIT:3>)<EOL>ddt = np.outer(d, d)<EOL>skew = np.array([[    <NUM_LIT:0>,  d[<NUM_LIT:2>],  -d[<NUM_LIT:1>]],<EOL>[-d[<NUM_LIT:2>],     <NUM_LIT:0>,   d[<NUM_LIT:0>]],<EOL>[ d[<NUM_LIT:1>], -d[<NUM_LIT:0>],     <NUM_LIT:0>]], dtype=np.float64)<EOL>M = ddt + np.sqrt(<NUM_LIT:1> - sin_angle**<NUM_LIT:2>) * (eye - ddt) + sin_angle * skew<EOL>return M<EOL>
Calculates a rotation matrix given a vector d. The direction of d
corresponds to the rotation axis. The length of d corresponds to
the sin of the angle of rotation.

Variant of: http://mail.scipy.org/pipermail/numpy-discussion/2009-March/040806.html