@@ -15,6 +15,9 @@ mutable struct WithGeometricBeam
1515end
1616
1717
18+
19+
20+
1821# type recipe, e.g. for `plot(WithBeam(system, beam))`
1922@recipe f (:: Type{WithGaussianBeam} , data:: WithGaussianBeam ) = begin
2023 seriestype := :shape
@@ -117,12 +120,70 @@ function color(λ)
117120 color = Colors. HSL (hue_of_λ (λ), 1.0 , 0.5 )
118121end
119122
123+
124+ function contour_element (element:: ThickLens , height)
125+ # first surface
126+ φ = asin (height / element. R1)
127+ Δx = cos (π - φ) * element. R1
128+ φs = range (π - φ, π + φ, 100 )
129+
130+ x = cos .(φs) .* element. R1 .- Δx
131+ y = sin .(φs) .* element. R1
132+
133+
134+ # second surface
135+ φ = asin (- height / element. R2)
136+ Δx = - cos (φ) * element. R2
137+ φs = range (- φ, φ, 100 )
138+ x2 = - cos .(φs) .* element. R2 .- Δx .+ element. t
139+ y2 = - sin .(φs) .* element. R2
140+
141+
142+ # merge x1,x2, y1, y2
143+ x = vcat (x, x2)
144+ y = vcat (y, y2)
145+ return (x, y)
146+ end
147+
148+
149+
150+ function contour_element (element:: ThinLens , height)
151+ return ([0 , 0 ], [height, - height])
152+ end
153+
154+
155+
156+ function contour_element (element, height)
157+ return Float64[], Float64[]
158+ end
159+
160+
120161# user recipe, e.g. for `plot(system, beam)`
121162@recipe f (system:: Vector{<:Element} , beam:: ABCDMatrixOptics.GaussianBeam ) =
122163 WithGaussianBeam (system, beam)
123164
124165@recipe f (system:: Vector{<:Element} , beam:: ABCDMatrixOptics.GeometricBeam ) =
125166 WithGeometricBeam (system, beam)
126167
168+ @recipe f (system:: Vector{<:Element} ; height= 1 ) = begin
169+
170+ seriestype := :shape
171+ linecolor --> color (425e-9 )
172+ fillcolor --> color (425e-9 )
173+ fillalpha --> 0.1
174+
175+ z = 0
176+ xs = []
177+ ys = []
178+ for element in system
179+ @series begin
180+ label --> nothing
181+ x, y = contour_element (element, height)
182+ z = z + ABCDMatrixOptics. dz (element)
183+ x .+ z, y
184+ end
185+ end
186+ end
187+
127188
128189end
0 commit comments