1 '''Defines the ThinLens class for theia.'''
2
3
4
5
6
7
8 import numpy as np
9 from ..helpers import settings
10 from ..helpers.units import mm, cm, deg, pi
11 from ..helpers.geometry import rectToSph
12 from .optic import Optic
13
15 '''
16
17 ThinLens class.
18
19 This class represents thin lenses, which are specified only by their focal
20 lengths, diameter, position and orientation. Only the initializer and the
21 printing distinguishes thin lenses (in implementation) from other lenses.
22
23 Actions:
24 * T on HR: 0
25 * R on HR: + 1
26 * T on AR: 0
27 * R on AR: + 1
28
29 *=== Additional attributes with respect to the Optic class ===*
30
31 Focal: focal length of the lens as given in initializer. [float]
32
33 *=== Name ===*
34
35 ThinLens
36
37 **Note**: the curvature of any surface is positive for a concave surface
38 (coating inside the sphere).
39 Thus kurv*HRNorm/|kurv| always points to the center
40 of the sphere of the surface, as is the convention for the lineSurfInter of
41 geometry module. Same for AR.
42
43 ******* HRK > 0 and ARK > 0 ******* HRK > 0 and ARK < 0
44 ***** ******** and |ARK| > |HRK|
45 H***A H*********A
46 ***** ********
47 ******* *******
48
49
50 '''
51
52 Name = "ThinLens"
53
54 - def __init__(self, Focal = 10.e-2, KeepI = False, Theta = pi/2., Phi = 0.,
55 Diameter = 5.e-2, R = .1, T = .9,
56 X = 0., Y = 0., Z = 0., Ref = None):
57 '''ThinLens initializer.
58
59 Parameters are the attributes.
60
61 Returns a ThinLens.
62
63 '''
64
65 TonHR = 0
66 RonHR = 1
67 TonAR = 0
68 RonAR = 1
69
70
71 self.Focal = float(Focal)
72 Theta = float(Theta)
73 Phi = float(Phi)
74 Diameter = float(Diameter)
75 R = float(R)
76 T = float(T)
77 Wedge = 0.
78 Alpha = 0.
79
80
81 HRNorm = np.array([np.sin(Theta)*np.cos(Phi),
82 np.sin(Theta) * np.sin(Phi),
83 np.cos(Theta)], dtype = np.float64)
84 Center = np.array([X, Y, Z], dtype = np.float64)
85 N = 1.4548
86
87
88 HRK = - 0.5/(self.Focal*(N - 1.))
89 ARK = HRK
90 ARNorm = - HRNorm
91
92
93 if self.Focal >= 0.:
94 Thickness = settings.zero
95 else:
96 try:
97 theta = np.arcsin(Diameter * HRK/2.)
98 except FloatingPointError:
99 theta = pi/2.
100 Thickness = 2.*settings.zero + 2.*(1.-np.cos(theta))/HRK
101 HRCenter = Center + Thickness*HRNorm/2.
102 ARCenter = Center - Thickness*HRNorm/2.
103
104
105 super(ThinLens, self).__init__(ARCenter = ARCenter, ARNorm = ARNorm,
106 N = N,
107 HRK = HRK, ARK = ARK,
108 ARr = R, ARt = T, HRr = R, HRt = T, KeepI = KeepI,
109 HRCenter = HRCenter, HRNorm = HRNorm, Thickness = Thickness,
110 Diameter = Diameter, Wedge = Wedge, Alpha = Alpha,
111 TonHR = TonHR, RonHR = RonHR, TonAR = TonAR, RonAR = RonAR,
112 Ref = Ref)
113
114
115 if settings.warning:
116 self.geoCheck("thinlens")
117
119 '''Returns the list of lines necessary to print the object.
120 '''
121 sph = rectToSph(self.HRNorm)
122 return ["ThinLens: %s {" % str(self.Ref),
123 "Diameter: %scm" % str(self.Dia/cm),
124 "Focal: %smm" % str(self.Focal/mm),
125 "Center: %s" % str(self.HRCenter),
126 "Norm: (%s, %s)deg" % (str(sph[0]/deg), str(sph[1]/deg)),
127 "HRKurv, ARKurv: %s, %s" % (str(self.HRK), str(self.ARK)),
128 "R, T: %s, %s" % (str(self.HRr),str(self.HRt)),
129 "}"]
130