#NEWLINE# def quatfrom_m33( m ) : #NEWLINE# #INDENT# 'Convert the top of an m33 matrix into a quaternion.' #NEWLINE# ( m0 , m1 , m2 , m3 , m4 , m5 , m6 , m7 , m8 ) = m #NEWLINE# trace = ( ( ( m0 + m4 ) + m8 ) + 1 ) #NEWLINE# if ( trace > PRECISION ) : #NEWLINE# #INDENT# w = ( math . sqrt ( trace ) / 2 ) #NEWLINE# x = ( ( m5 - m7 ) / ( 4 * w ) ) #NEWLINE# y = ( ( m6 - m2 ) / ( 4 * w ) ) #NEWLINE# z = ( ( m1 - m3 ) / ( 4 * w ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( m0 > m4 ) and ( m0 > m8 ) ) : #NEWLINE# #INDENT# s = ( math . sqrt ( ( ( ( 1.0 + m0 ) - m4 ) - m8 ) ) * 2 ) #NEWLINE# w = ( ( m5 - m7 ) / s ) #NEWLINE# x = ( 0.25 * s ) #NEWLINE# y = ( ( m3 + m1 ) / s ) #NEWLINE# z = ( ( m6 + m2 ) / s ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( m4 > m8 ) : #NEWLINE# #INDENT# s = ( math . sqrt ( ( ( ( 1.0 + m4 ) - m0 ) - m8 ) ) * 2 ) #NEWLINE# w = ( ( m6 - m2 ) / s ) #NEWLINE# x = ( ( m3 + m1 ) / s ) #NEWLINE# y = ( 0.25 * s ) #NEWLINE# z = ( ( m7 + m5 ) / s ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s = ( math . sqrt ( ( ( ( 1.0 + m8 ) - m0 ) - m4 ) ) * 2 ) #NEWLINE# w = ( ( m1 - m3 ) / s ) #NEWLINE# x = ( ( m6 + m2 ) / s ) #NEWLINE# y = ( ( m7 + m5 ) / s ) #NEWLINE# z = ( 0.25 * s ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return quatnormalize ( ( ( - x ) , ( - y ) , ( - z ) , w ) )