From e549e30097204ab9de7a9c38e632a00f9d76337c Mon Sep 17 00:00:00 2001 From: Kevin Peterson <kmpeters@anl.gov> Date: Fri, 24 Feb 2012 23:04:08 +0000 Subject: [PATCH] Implemented 3d rotation transform with angles in radians git-svn-id: https://subversion.xray.aps.anl.gov/kmp/transform/trunk@210 f095f811-4e88-6c84-d33e-e382bdb4531c --- myTransform.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/myTransform.py b/myTransform.py index 52296fb..82ef005 100644 --- a/myTransform.py +++ b/myTransform.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import transform +from numpy import matrix, sin, cos class myTransform(transform.transform): ### The transform functions should be overloaded for each application @@ -12,13 +13,39 @@ class myTransform(transform.transform): # Transform real coordinates into soft coordinates def fwdTrans(self, m_positions, t_positions): - retval = [m_positions[x] * t_positions[x] for x in range(3)] - return retval[:] + """ """ + m_matrix = matrix(m_positions) + th, phi, chi = t_positions + Rx = matrix([[1, 0, 0],[0, cos(th), sin(th)], [0, -sin(th), cos(th)]]) + Ry = matrix([[cos(phi), 0, -sin(phi)], [0, 1, 0], [sin(phi), 0, cos(phi)]]) + Rz = matrix([[cos(chi), sin(chi), 0], [-sin(chi), cos(chi), 0], [0, 0, 1]]) + + R = Rx * Ry * Rz + + # Inverse is R.I + + retval = m_matrix * R + + print retval + + return retval.tolist()[0] # Transform soft coordinates into real coordinates def invTrans(self, tm_positions, t_positions): - retval = [tm_positions[x] / t_positions[x] for x in range(3)] - return retval[:] + """ """ + tm_matrix = matrix(tm_positions) + th, phi, chi = t_positions + Rx = matrix([[1, 0, 0],[0, cos(th), sin(th)], [0, -sin(th), cos(th)]]) + Ry = matrix([[cos(phi), 0, -sin(phi)], [0, 1, 0], [sin(phi), 0, cos(phi)]]) + Rz = matrix([[cos(chi), sin(chi), 0], [-sin(chi), cos(chi), 0], [0, 0, 1]]) + + R = Rx * Ry * Rz + + retval = tm_matrix * R.I + + print retval + + return retval.tolist()[0] if __name__ == "__main__": prefix = 'kmp2:' -- GitLab