Author: bugman Date: Fri May 15 10:47:59 2009 New Revision: 9059 URL: http://svn.gna.org/viewcvs/relax?rev=9059&view=rev Log: Created the R_axis_angle() function to generate the rotation matrix from the axis-angle notation. Modified: 1.3/maths_fns/rotation_matrix.py Modified: 1.3/maths_fns/rotation_matrix.py URL: http://svn.gna.org/viewcvs/relax/1.3/maths_fns/rotation_matrix.py?rev=9059&r1=9058&r2=9059&view=diff ============================================================================== --- 1.3/maths_fns/rotation_matrix.py (original) +++ 1.3/maths_fns/rotation_matrix.py Fri May 15 10:47:59 2009 @@ -80,6 +80,62 @@ R[2,2] = 1.0 + (1.0 - ca)*(z**2 - 1.0) +def R_axis_angle(matrix, axis, angle): + """Generate the rotation matrix from the axis-angle notation. + + Conversion equations + ==================== + + From Wikipedia (http://en.wikipedia.org/wiki/Rotation_matrix), the conversion is given by:: + + c = cos(angle); s = sin(angle); C = 1-c + xs = x*s; ys = y*s; zs = z*s + xC = x*C; yC = y*C; zC = z*C + xyC = x*yC; yzC = y*zC; zxC = z*xC + [ x*xC+c xyC-zs zxC+ys ] + [ xyC+zs y*yC+c yzC-xs ] + [ zxC-ys yzC+xs z*zC+c ] + + + @param matrix: The 3x3 rotation matrix to update. + @type matrix: 3x3 numpy array + @param axis: The 3D rotation axis. + @type axis: numpy array, len 3 + @param angle: The rotation angle. + @type angle: float + """ + + # Trig factors. + ca = cos(angle) + sa = sin(angle) + C = 1 - ca + + # Depack the axis. + x, y, z = axis + + # Multiplications (to remove duplicate calculations). + xs = x*sa + ys = y*sa + zs = z*sa + xC = x*C + yC = y*C + zC = z*C + xyC = x*yC + yzC = y*zC + zxC = z*xC + + # Update the rotation matrix. + matrix[0, 0] = x*xC + ca + matrix[0, 1] = xyC - zs + matrix[0, 2] = zxC + ys + matrix[1, 0] = xyC + zs + matrix[1, 1] = y*yC + ca + matrix[1, 2] = yzC - xs + matrix[2, 0] = zxC - ys + matrix[2, 1] = yzC + xs + matrix[2, 2] = z*zC + ca + + def R_euler_zyz(matrix, alpha, beta, gamma): """Function for calculating the z-y-z Euler angle convention rotation matrix.