#NEWLINE# def euler_matrix( ai , aj , ak , axes = 'sxyz' ) : #NEWLINE# #INDENT# "Return homogeneous rotation matrix from Euler angles and axis sequence.\n\n    ai, aj, ak : Euler's roll, pitch and yaw angles\n    axes : One of 24 axis sequences as string or encoded tuple\n\n    >>> R = euler_matrix(1, 2, 3, 'syxz')\n    >>> numpy.allclose(numpy.sum(R[0]), -1.34786452)\n    True\n    >>> R = euler_matrix(1, 2, 3, (0, 1, 0, 1))\n    >>> numpy.allclose(numpy.sum(R[0]), -0.383436184)\n    True\n    >>> ai, aj, ak = (4*math.pi) * (numpy.random.random(3) - 0.5)\n    >>> for axes in _AXES2TUPLE.keys():\n    ...    R = euler_matrix(ai, aj, ak, axes)\n    >>> for axes in _TUPLE2AXES.keys():\n    ...    R = euler_matrix(ai, aj, ak, axes)\n\n    " #NEWLINE# try : #NEWLINE# #INDENT# ( firstaxis , parity , repetition , frame ) = _AXES2TUPLE [ axes ] #NEWLINE# #UNINDENT# except ( AttributeError , KeyError ) : #NEWLINE# #INDENT# _TUPLE2AXES [ axes ] #NEWLINE# ( firstaxis , parity , repetition , frame ) = axes #NEWLINE# #UNINDENT# i = firstaxis #NEWLINE# j = _NEXT_AXIS [ ( i + parity ) ] #NEWLINE# k = _NEXT_AXIS [ ( ( i - parity ) + 1 ) ] #NEWLINE# if frame : #NEWLINE# #INDENT# ( ai , ak ) = ( ak , ai ) #NEWLINE# #UNINDENT# if parity : #NEWLINE# #INDENT# ( ai , aj , ak ) = ( ( - ai ) , ( - aj ) , ( - ak ) ) #NEWLINE# #UNINDENT# ( si , sj , sk ) = ( math . sin ( ai ) , math . sin ( aj ) , math . sin ( ak ) ) #NEWLINE# ( ci , cj , ck ) = ( math . cos ( ai ) , math . cos ( aj ) , math . cos ( ak ) ) #NEWLINE# ( cc , cs ) = ( ( ci * ck ) , ( ci * sk ) ) #NEWLINE# ( sc , ss ) = ( ( si * ck ) , ( si * sk ) ) #NEWLINE# M = numpy . identity ( 4 ) #NEWLINE# if repetition : #NEWLINE# #INDENT# M [ ( i , i ) ] = cj #NEWLINE# M [ ( i , j ) ] = ( sj * si ) #NEWLINE# M [ ( i , k ) ] = ( sj * ci ) #NEWLINE# M [ ( j , i ) ] = ( sj * sk ) #NEWLINE# M [ ( j , j ) ] = ( ( ( - cj ) * ss ) + cc ) #NEWLINE# M [ ( j , k ) ] = ( ( ( - cj ) * cs ) - sc ) #NEWLINE# M [ ( k , i ) ] = ( ( - sj ) * ck ) #NEWLINE# M [ ( k , j ) ] = ( ( cj * sc ) + cs ) #NEWLINE# M [ ( k , k ) ] = ( ( cj * cc ) - ss ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# M [ ( i , i ) ] = ( cj * ck ) #NEWLINE# M [ ( i , j ) ] = ( ( sj * ss ) - cs ) #NEWLINE# M [ ( i , k ) ] = ( ( sj * cc ) + ss ) #NEWLINE# M [ ( j , i ) ] = ( cj * sk ) #NEWLINE# M [ ( j , j ) ] = ( ( sj * ss ) + cc ) #NEWLINE# M [ ( j , k ) ] = ( ( sj * cs ) - sc ) #NEWLINE# M [ ( k , i ) ] = ( - sj ) #NEWLINE# M [ ( k , j ) ] = ( cj * si ) #NEWLINE# M [ ( k , k ) ] = ( cj * ci ) #NEWLINE# #UNINDENT# return M