1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
|