#NEWLINE# def euler_from_matrix( matrix , axes = 'sxyz' ) : #NEWLINE# #INDENT# 'Return Euler angles from rotation matrix for specified axis sequence.\n\n    axes : One of 24 axis sequences as string or encoded tuple\n\n    Note that many Euler angle triplets can describe one matrix.\n\n    >>> R0 = euler_matrix(1, 2, 3, \'syxz\')\n    >>> al, be, ga = euler_from_matrix(R0, \'syxz\')\n    >>> R1 = euler_matrix(al, be, ga, \'syxz\')\n    >>> numpy.allclose(R0, R1)\n    True\n    >>> angles = (4*math.pi) * (numpy.random.random(3) - 0.5)\n    >>> for axes in _AXES2TUPLE.keys():\n    ...    R0 = euler_matrix(axes=axes, *angles)\n    ...    R1 = euler_matrix(axes=axes, *euler_from_matrix(R0, axes))\n    ...    if not numpy.allclose(R0, R1): print(axes, "failed")\n\n    ' #NEWLINE# try : #NEWLINE# #INDENT# ( firstaxis , parity , repetition , frame ) = _AXES2TUPLE [ axes . lower ( ) ] #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# M = numpy . array ( matrix , dtype = numpy . float64 , copy = False ) [ : 3 , : 3 ] #NEWLINE# if repetition : #NEWLINE# #INDENT# sy = math . sqrt ( ( ( M [ ( i , j ) ] * M [ ( i , j ) ] ) + ( M [ ( i , k ) ] * M [ ( i , k ) ] ) ) ) #NEWLINE# if ( sy > _EPS ) : #NEWLINE# #INDENT# ax = math . atan2 ( M [ ( i , j ) ] , M [ ( i , k ) ] ) #NEWLINE# ay = math . atan2 ( sy , M [ ( i , i ) ] ) #NEWLINE# az = math . atan2 ( M [ ( j , i ) ] , ( - M [ ( k , i ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ax = math . atan2 ( ( - M [ ( j , k ) ] ) , M [ ( j , j ) ] ) #NEWLINE# ay = math . atan2 ( sy , M [ ( i , i ) ] ) #NEWLINE# az = 0.0 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# cy = math . sqrt ( ( ( M [ ( i , i ) ] * M [ ( i , i ) ] ) + ( M [ ( j , i ) ] * M [ ( j , i ) ] ) ) ) #NEWLINE# if ( cy > _EPS ) : #NEWLINE# #INDENT# ax = math . atan2 ( M [ ( k , j ) ] , M [ ( k , k ) ] ) #NEWLINE# ay = math . atan2 ( ( - M [ ( k , i ) ] ) , cy ) #NEWLINE# az = math . atan2 ( M [ ( j , i ) ] , M [ ( i , i ) ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ax = math . atan2 ( ( - M [ ( j , k ) ] ) , M [ ( j , j ) ] ) #NEWLINE# ay = math . atan2 ( ( - M [ ( k , i ) ] ) , cy ) #NEWLINE# az = 0.0 #NEWLINE# #UNINDENT# #UNINDENT# if parity : #NEWLINE# #INDENT# ( ax , ay , az ) = ( ( - ax ) , ( - ay ) , ( - az ) ) #NEWLINE# #UNINDENT# if frame : #NEWLINE# #INDENT# ( ax , az ) = ( az , ax ) #NEWLINE# #UNINDENT# return ( ax , ay , az )