Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def drawBeamTrace(self, axes, beam):
""" Draw beam trace corresponding to input beam
Because the laser beam diffracts through space, we cannot
simply propagate the beam over large distances and trace it
(as opposed to rays, where we can). We must split Space()
elements into sub elements to watch the beam size expand.
We arbitrarily split Space() elements into 100 sub elements
before plotting.
"""
highResolution = ImagingPath()
for element in self.elements:
if isinstance(element, Space):
for i in range(100):
highResolution.append(Space(d=element.L/100,
n=element.frontIndex))
else:
highResolution.append(element)
beamTrace = highResolution.trace(beam)
(x, y) = self.rearrangeBeamTraceForPlotting(beamTrace)
axes.plot(x, y, 'r', linewidth=1)
axes.plot(x, [-v for v in y], 'r', linewidth=1)
is the image? Distance after the element by which a ray
must travel to reach the conjugate plane of the front of
the element. A positive distance means the image is "distance"
beyond the back of the element (or to the right, or after).
M2 = Space(distance)*M1
# M2.isImaging == True
"""
if self.D == 0:
distance = float("+inf")
conjugateMatrix = None # Unable to compute with inf
else:
distance = -self.B / self.D
conjugateMatrix = Space(d=distance) * self
return (distance, conjugateMatrix)
def backwardConjugate(self):
""" With an image at the back edge of the element,
where is the object ? Distance before the element by
which a ray must travel to reach the conjugate plane at
the back of the element. A positive distance means the
object is "distance" in front of the element (or to the
left, or before).
M2 = M1*Space(distance)
# M2.isImaging == True
"""
if self.A == 0:
return (None, None)
distance = -self.B / self.A
conjugateMatrix = self * Space(d=distance)
return (distance, conjugateMatrix)
def __init__(self, d, n=1, diameter=float('+Inf'), label=''):
super(Space, self).__init__(A=1,
B=float(d),
C=0,
D=1,
physicalLength=d,
frontVertex=None,
backVertex=None,
frontIndex=n,
backIndex=n,
apertureDiameter=diameter,
label=label)
def drawBeamTrace(self, axes, beam):
""" Draw beam trace corresponding to input beam
Because the laser beam diffracts through space, we cannot
simply propagate the beam over large distances and trace it
(as opposed to rays, where we can). We must split Space()
elements into sub elements to watch the beam size expand.
We arbitrarily split Space() elements into 100 sub elements
before plotting.
"""
highResolution = ImagingPath()
for element in self.elements:
if isinstance(element, Space):
for i in range(100):
highResolution.append(Space(d=element.L/100,
n=element.frontIndex))
else:
highResolution.append(element)
beamTrace = highResolution.trace(beam)
(x, y) = self.rearrangeBeamTraceForPlotting(beamTrace)
axes.plot(x, y, 'r', linewidth=1)
axes.plot(x, [-v for v in y], 'r', linewidth=1)
def transferMatrix(self, upTo=float('+Inf')):
""" Returns a Matrix() corresponding to a partial propagation
if the requested distance is smaller than the length of this element"""
distance = upTo
if distance < self.L:
return Space(distance)
else:
return self