14 cphi = (rm[0,0]+rm[1,1]+rm[2,2]-1.0)/2.0
15 if (np.abs(cphi) < 0.98):
18 ssphi = ((rm[1,0]-rm[0,1])**2 + (rm[0,2]-rm[2,0])**2 + (rm[2,1]-rm[1,2])**2)/4.0
19 phi = np.arcsin(np.sqrt(ssphi))
24 e[0] = (rm[2,1]-rm[1,2])/(np.sin(phi)*2.0)
25 e[1] = (rm[0,2]-rm[2,0])/(np.sin(phi)*2.0)
26 e[2] = (rm[1,0]-rm[0,1])/(np.sin(phi)*2.0)
27 e = e/np.sqrt(np.sum(e*e))
30 q[0] = e[0]*np.sin(phi/2.0)
31 q[1] = e[1]*np.sin(phi/2.0)
32 q[2] = e[2]*np.sin(phi/2.0)
33 q[3] = np.cos(phi/2.0)