diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2013-02-28 14:59:55 -0500 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2013-02-28 14:59:55 -0500 |
commit | e4360a48435cc762855d356b208b5544e6f40c4b (patch) | |
tree | 71c6c83c247cb07495265b93ec062eefc3e928a8 /beam_tracing/python/beamTrace.py | |
parent | a08ed173692ce16b79002733003049ec32a02485 (diff) | |
download | wgmr-e4360a48435cc762855d356b208b5544e6f40c4b.tar.gz wgmr-e4360a48435cc762855d356b208b5544e6f40c4b.zip |
Added python version of mode-matching code by Bain Bronner
Diffstat (limited to 'beam_tracing/python/beamTrace.py')
-rw-r--r-- | beam_tracing/python/beamTrace.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/beam_tracing/python/beamTrace.py b/beam_tracing/python/beamTrace.py new file mode 100644 index 0000000..6f2cd96 --- /dev/null +++ b/beam_tracing/python/beamTrace.py @@ -0,0 +1,49 @@ +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
|