Skip to content
Snippets Groups Projects
Commit e319a6f1 authored by kpetersn's avatar kpetersn
Browse files

Added sanityCheck.py, a script used to find the error when I was converting...

Added sanityCheck.py, a script used to find the error when I was converting this python script to a sequence program

git-svn-id: https://subversion.xray.aps.anl.gov/kmp/transform/trunk@542 f095f811-4e88-6c84-d33e-e382bdb4531c
parent 4a0161c7
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
#start this with epd python: /APSshare/epd/rh5-x86/bin/python labTransform.py
# /APSshare/epd/rh5-x86_64/bin/python labTransform.py
from numpy import matrix, sin, cos, degrees, radians
import math
sinTh = 0.0
cosTh = 0.0
sinPhi = 0.0
cosPhi = 0.0
sinChi = 0.0
cosPhi = 0.0
def fwdTrans(m_positions, t_positions):
""" """
m_matrix = matrix(m_positions)
m_matrix.shape=3,1
th, phi, chi = [radians(x) for x in t_positions]
Rth = matrix([[cos(th), -sin(th), 0], [sin(th), cos(th), 0], [0, 0, 1]])
Rphi = matrix([[1, 0, 0],[0, cos(phi), -sin(phi)],[0, sin(phi), cos(phi)]])
Rchi = matrix([[sin(chi), 0, -cos(chi)], [0, 1, 0], [cos(chi), 0, sin(chi)]])
R = Rth * Rchi * Rphi
print R
retval = R * m_matrix
#!print retval
retval.shape=1,3
return retval.tolist()[0]
# Transform soft coordinates into real coordinates
def invTrans(tm_positions, t_positions):
""" """
tm_matrix = matrix(tm_positions)
tm_matrix.shape=3,1
th, phi, chi = [radians(x) for x in t_positions]
Rth = matrix([[cos(th), -sin(th), 0], [sin(th), cos(th), 0], [0, 0, 1]])
Rphi = matrix([[1, 0, 0],[0, cos(phi), -sin(phi)],[0, sin(phi), cos(phi)]])
Rchi = matrix([[sin(chi), 0, -cos(chi)], [0, 1, 0], [cos(chi), 0, sin(chi)]])
R = Rth * Rchi * Rphi
# Inverse (R.I) is the same as the transpose (R.T) for rotations
print R.T
retval = R.T * tm_matrix
retval.shape=1,3
#!print "retval",retval.tolist()
return retval.tolist()[0]
def doTrig(th, phi, chi):
global sinTh, cosTh, sinPhi, cosPhi, sinChi, cosChi
sinTh = math.sin( th * math.pi / 180.0 )
cosTh = math.cos( th * math.pi / 180.0 )
sinPhi = math.sin( phi * math.pi / 180.0 )
cosPhi = math.cos( phi * math.pi / 180.0 )
sinChi = math.sin( chi * math.pi / 180.0 )
cosChi = math.cos( chi * math.pi / 180.0 )
# fwdTrans
def calcTM1rbv(m1, m2, m3):
global sinTh, cosTh, sinPhi, cosPhi, sinChi, cosChi
return ( m1 * (cosTh * sinChi) - m2 * (cosTh * cosChi * sinPhi + sinTh * cosPhi) + m3 * (sinTh * sinPhi - cosTh * cosChi * cosPhi) )
def calcTM2rbv(m1, m2, m3):
global sinTh, cosTh, sinPhi, cosPhi, sinChi, cosChi
return ( m1 * (sinTh * sinChi) + m2 * (cosTh * cosPhi - sinTh * cosChi * sinPhi) - m3 * (sinTh * cosChi * cosPhi + cosTh * sinPhi) )
def calcTM3rbv(m1, m2, m3):
global sinTh, cosTh, sinPhi, cosPhi, sinChi, cosChi
return ( m1 * cosChi + m2 * sinChi * sinPhi + m3 * sinChi * cosPhi )
def seqFwdTrans(m_pos, t_pos):
doTrig(t_pos[0], t_pos[1], t_pos[2])
rv1 = calcTM1rbv(m_pos[0], m_pos[1], m_pos[2])
rv2 = calcTM2rbv(m_pos[0], m_pos[1], m_pos[2])
rv3 = calcTM3rbv(m_pos[0], m_pos[1], m_pos[2])
return [rv1, rv2, rv3]
# invTrans
def calcM1val(tm1, tm2, tm3):
global sinTh, cosTh, sinPhi, cosPhi, sinChi, cosChi
# This was my original error
#return ( tm1 * cosTh * cosChi + tm2 * sinTh * sinChi + tm3 * cosChi )
return ( tm1 * cosTh * sinChi + tm2 * sinTh * sinChi + tm3 * cosChi )
def calcM2val(tm1, tm2, tm3):
global sinTh, cosTh, sinPhi, cosPhi, sinChi, cosChi
return ( tm3 * (sinChi * sinPhi) - tm1 * (cosTh * cosChi * sinPhi + sinTh * cosPhi) + tm2 * (cosTh * cosPhi - sinTh * cosChi * sinPhi) )
def calcM3val(tm1, tm2, tm3):
global sinTh, cosTh, sinPhi, cosPhi, sinChi, cosChi
return ( tm1 * (sinTh * sinPhi - cosTh * cosChi * cosPhi) - tm2 * (sinTh * cosChi * cosPhi + cosTh * sinPhi) + tm3 * (sinChi * cosPhi) )
def seqInvTrans(tm_pos, t_pos):
doTrig(t_pos[0], t_pos[1], t_pos[2])
rv1 = calcM1val(tm_pos[0], tm_pos[1], tm_pos[2])
rv2 = calcM2val(tm_pos[0], tm_pos[1], tm_pos[2])
rv3 = calcM3val(tm_pos[0], tm_pos[1], tm_pos[2])
return [rv1, rv2, rv3]
if __name__ == "__main__":
m = [10, 10, 10]
t = [0, 0, 0]
pyTM = fwdTrans(m, t)
seqTM = seqFwdTrans(m, t)
print pyTM
print seqTM
pyM = invTrans(pyTM, t)
seqM = seqInvTrans(seqTM, t)
print pyM
print seqM
print
m = [10, 10, 10]
t = [30, 30, 30]
pyTM = fwdTrans(m, t)
seqTM = seqFwdTrans(m, t)
print pyTM
print seqTM
pyM = invTrans(pyTM, t)
seqM = seqInvTrans(seqTM, t)
print pyM
print seqM
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment