find a best-effort transformation matrix which describes our current direction relative to the vector 'up'. This is used to find a matrix which transforms the beam into a coordinate system which looks natural on the optics table. Returns flag, matrix where flag is 0 if there is no obvious solution, and 1 if there is a pretty good solution. If our direction is close to perpendicular to 'up', the matrix puts z in our propagation direction, x perpendicular to 'up' and y perpendicular to x & z. If the beam is close to parallel to 'up', returns the identity matrix. The result when the flag is true is a nice coordinate system in which x lies in the plane of the table, y lies nearly in the cirection of 'up' and z is the beam direction. Definition at line 435 of file general_optics.py. 00435 : 00436 """find a best-effort transformation matrix which describes our current direction relative to the vector 'up'. 00437 This is used to find a matrix which transforms the beam into a coordinate system which looks natural on the optics table. 00438 Returns flag, matrix where flag is 0 if there is no obvious solution, and 1 if there is a pretty good solution. 00439 If our direction is close to perpendicular to 'up', the matrix puts z in our propagation direction, x perpendicular to 'up' and y perpendicular to x & z. 00440 If the beam is close to parallel to 'up', returns the identity matrix. 00441 The result when the flag is true is a nice coordinate system in which x lies in the plane of the table, y lies nearly in the cirection of 'up' 00442 and z is the beam direction. 00443 """ 00444 ar=Numeric.array 00445 dot=Numeric.dot 00446 tr=Numeric.transpose 00447 00448 dir=self.matrix_to_global 00449 z=dir[:,2] 00450 x=cross(up,z) 00451 xmag=sqrt(dot(x,x)) 00452 if xmag < 0.1 : #z is not even close to perpendicular to up! 00453 return 0, Numeric.identity(3).astype(numeric_float) #punt, return false and identity 00454 else: 00455 x=x/xmag 00456 y=cross(z,x) #may be tilted if the beam isn't completely level 00457 direction=tr(ar((x,y,z))) 00458 return 1, dot(tr(direction), dir) #coordinates are rational, return true and transform 00459 def transform_q_to_table(self, qi, up=(0,1,0)):
|