import pylab from faceBeamInteraction import * import numpy as np def beamTrace(beams, faces, borders, borderLimits): # trace beam and all it reflections and refractions on faces # for beams and faces structure description see faceBeamInteraction.m # border similar to faces cell array which enclose the beam # i.e. it does not leave the polygon consisting of border faces intensityThreshold = 1e-2 # intensity of the weakest beam we still trace processedBeams = [] nBeams = len(beams) if nBeams == 0: # no more beam to trace return processedBeams # trace each beam in beams cell array intenseEnoughBeams = [] intenseBeamsCounter = 0 for beam in beams: [isFaceHit, hitPosition, hitDistance, newBeams] =\ faceBeamInteraction(beam, faces) if (isFaceHit): beam.hitPosition = hitPosition # remove beams which are to weak to trace nNewBeams = len(newBeams) for newBeam in newBeams: if newBeam.intensity >= intensityThreshold: intenseBeamsCounter += 1 intenseEnoughBeams.append(newBeam) #try: newProcessedBeams = \ beamTrace(intenseEnoughBeams, faces, borders, borderLimits) #except ValueError: # break processedBeams.append(newProcessedBeams) else: # beam does not hit face but it should stop at borders beam.face = None [isFaceHit, hitPosition, hitDistance, newBeams] = \ faceBeamInteraction(beam, borders) if not isFaceHit: print 'borders are badly defined, the beam misses them' return False beam.hitPosition = hitPosition processedBeams.append(newBeams) return processedBeams