Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it does not do anything because they are the same either way. However,
subclasses can override this function and act accordingly.
"""
super(DielectricInterface, self).flipOrientation()
temp = self.n1
self.n1 = self.n2
self.n2 = temp
self.R = -self.R
self.C = - (self.n2 - self.n1) / (self.n2 * self.R)
self.D = self.n1 / self.n2
return self
class ThickLens(Matrix):
"""A thick lens of first radius R1 and then R2, with an index n
and length d
Parameters
----------
n : float
The refraction index of the thick lens. This value cannot be negative.
R1 : float
The first radius of thick lens
R2 : float
The second radius of the thick lens
thickness : float
The length of the thick lens. This value cannot be negative.
diameter : float (Optional)
The diameter of the thick lens. (default=Inf)
label : string (Optional)
""" String description that allows the use of print(Matrix())
"""
description = "\n / \\ \n"
description += "| {0:6.3f} {1:6.3f} |\n".format(self.A, self.B)
description += "| |\n"
description += "| {0:6.3f} {1:6.3f} |\n".format(self.C, self.D)
description += " \\ /\n"
if self.C != 0:
description += "\nf={0:0.3f}\n".format(-1.0 / self.C)
else:
description += "\nf = +inf (afocal)\n"
return description
class Lens(Matrix):
"""A thin lens of focal f, null thickness and infinite or finite diameter
Parameters
----------
f : float
The focal length of the lens
diameter : float
The diameter (default=Inf)
label : string
The label of the lens
Examples
--------
>>> from raytracing import *
>>> #define a lens with f=5 and diameter 20
>>> L=Lens(f=5,diameter=20,label='Lens')
def flipOrientation(self):
""" This function flips the element around (as in, we turn a lens around front-back).
Notes
-----
In this case, R -> -R. It is important to call the
super implementation because other things must be flipped (vertices for instance)
"""
super(CurvedMirror, self).flipOrientation()
self.C = - self.C
return self
class Space(Matrix):
"""Free space of length d
Parameters
----------
d : float
the length of the free space
n : float
The refraction index of the space. This value cannot be negative. (default=1)
diameter : float
The diameter of the free space (default=Inf)
label : string
The label of the free space
Examples
--------
>>> from raytracing import *
pointsOfInterest : List
List of points of interest for the input element
"""
(f1, f2) = self.focusPositions(z)
pointsOfInterest = []
if f1 is not None:
pointsOfInterest.append({'z': f1, 'label': '$F_f$'})
if f2 is not None:
pointsOfInterest.append({'z': f2, 'label': '$F_b$'})
return pointsOfInterest
class CurvedMirror(Matrix):
"""A curved mirror of radius R and infinite or finite diameter.
Parameters
----------
R : float
the radius of curvature of the mirror
diameter : float
The diameter of the element (default=Inf)
label : string
The label of the curved mirror
Examples
--------
>>> from raytracing import *
>>> #define a curved mirror with R=5 and diameter 20
>>> M=CurvedMirror(R=5,diameter=20,label='curved mirror')
# The back vertex of the combination is the back vertex of the self
# element, occuring last, if it exists. If it does not, it is the
# back vertex of the rightSideMatrix (which may or may not exist).
# Vertices are measured with respect to the front edge of the
# combined element.
fv = rightSideMatrix.frontVertex
if fv is None and self.frontVertex is not None:
fv = rightSideMatrix.L + self.frontVertex
if self.backVertex is not None:
bv = rightSideMatrix.L + self.backVertex
else:
bv = rightSideMatrix.backVertex
return Matrix(a, b, c, d, frontVertex=fv, backVertex=bv, physicalLength=L)
# Length of this element
self.L = float(physicalLength)
# Aperture
self.apertureDiameter = apertureDiameter
# First and last interfaces. Used for BFL and FFL
self.frontVertex = frontVertex
self.backVertex = backVertex
# Index of refraction at entrance and exit.
self.frontIndex = frontIndex
self.backIndex = backIndex
self.label = label
self.isFlipped = False
super(Matrix, self).__init__()
isImaging: True
>>> # M2 is an ABCD matrix of free space (d=2)
>>> M2= Matrix(A=1,B=2,C=0,D=1,physicalLength=2,label='Lens')
>>> print('isImaging:' , M2.isImaging)
isImaging: False
Notes
-----
In this case:
A = transverse magnification
D = angular magnification
And as usual, C = -1/f (always).
"""
return abs(self.B) < Matrix.__epsilon__
The length of the propagation (default=Inf)
Returns
-------
transferMatrix : object of class Matrix
the corresponding matrix to the propagation
"""
if self.L <= upTo:
return self
else:
return Space(upTo, self.n, self.apertureDiameter) * DielectricInterface(1.0, self.n, float("+inf"),
self.apertureDiameter)
class Aperture(Matrix):
"""An aperture of finite diameter, null thickness.
Parameters
----------
diameter : float
The diameter of the aperture to be considered
label : string
The label of the aperture
Examples
--------
>>> from raytracing import *
>>> #define an aperture of diameter 10
>>> A=Aperture(diameter=10,label='aperture')
>>> print('The transfer matrix of aperture :' ,A)
The transfer matrix of aperture :
with other `Matrix`, with a `Ray` or a `GaussianBeam`.
For instance, with M1 = Matrix() and M2 = Matrix(), one can write
M3 = M1*M2. With r = Ray(), one can apply the M1 transform to a ray
with rOut = M1*r
Examples
--------
>>> from raytracing import *
>>> M1= Matrix(A=1,B=0,C=-1/3,D=1,label='Lens')
>>> M2= Matrix(A=1,B=0,C=-1/3,D=1,label='Lens')
>>> print('product M2*M1 :' , M2*M1)
"""
if isinstance(rightSide, Matrix):
return self.mul_matrix(rightSide)
elif isinstance(rightSide, Ray):
return self.mul_ray(rightSide)
elif isinstance(rightSide, GaussianBeam):
return self.mul_beam(rightSide)
else:
raise TypeError(
"Unrecognized right side element in multiply: '{0}'\
cannot be multiplied by a Matrix".format(rightSide))