find the intersection of a beam coming from from_point, going in from_direction, with our center. Raise an exception if beam won't hit center going that way. Reimplemented from general_optic. Definition at line 1073 of file general_optics.py. 01073 : 01074 """find the intersection of a beam coming from from_point, going in from_direction, with our center. Raise an exception if beam won't hit center going that way.""" 01075 01076 # t=-(a,b,c).(x1,y1,z1) +- sqrt( ( (a,b,c).(x1,y1,z1) )^2 - (x1,y1,z1)^2 + r^2 ) from Mathematica for line (a,b,c)*t+(x1,y1,z1) and sphere of radius r at origin 01077 #the center of curvature of the mirror is derived from the apex position (our location) and the rotation matrix 01078 01079 radius=self.f*2.0 #radius of curvature 01080 01081 centerpos=self.center-self.matrix_to_global[:,2]*radius #position of center of sphere 01082 from0=from_point-centerpos 01083 abcxyz=Numeric.dot(from0, from_direction) 01084 disc=abcxyz*abcxyz - Numeric.dot(from0, from0) + radius*radius 01085 if disc < 0: 01086 raise OpticDirectionError, ("beam misses sphere: "+str(self)+" incoming (x,y,z)="+ 01087 Numeric.array_str(from_point, precision=3, suppress_small=1)+" cosines="+ 01088 Numeric.array_str(from_direction, precision=3, suppress_small=1) ) 01089 01090 tvals =[ t for t in (-abcxyz - math.sqrt(disc), -abcxyz + math.sqrt(disc)) if t > 1e-9] #select only forward solutions 01091 01092 if not tvals: 01093 raise OpticDirectionError, ( "Optic found on backwards side of beam: "+str(self)+" incoming (x,y,z)="+ 01094 Numeric.array_str(from_point, precision=3, suppress_small=1)+" cosines="+ 01095 Numeric.array_str(from_direction, precision=3, suppress_small=1) ) 01096 01097 solns = [ (t, from_point+from_direction*t) for t in tvals] 01098 01099 solns=[ (t,xx) for t,xx in solns if Numeric.dot(xx-centerpos, from_direction)*radius > 0] #pick solution with surface pointing the right way 01100 #there will always only be one of the solutions which passes this test, at most 01101 01102 if not solns: 01103 raise OpticDirectionError, ( "Only interaction with spherical mirror is on wrong side: "+str(self)+" incoming (x,y,z)="+ 01104 Numeric.array_str(from_point, precision=3, suppress_small=1)+" cosines="+ 01105 Numeric.array_str(from_direction, precision=3, suppress_small=1) ) 01106 01107 soln=solns[0] 01108 self.intersection_zhat=(soln[1]-centerpos)/radius #unit surface normal in general direction of beam, useful later 01109 return soln #this is the only possible solution 01110 def transform(self, beam, backwards=0):
|