Skip to content

Commit e13cf1e

Browse files
committed
add function to plot thick lens
1 parent d3d3f0f commit e13cf1e

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

ext/ABCDMatrixOpticsPlotExt.jl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ mutable struct WithGeometricBeam
1515
end
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)
118121
end
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

128189
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ using Plots
123123
for λ in [100e-9, 500e-9]
124124
for beam in [GaussianBeam(w0=100e-6, λ=λ, n=1.3, zpos=0), GeometricBeam(w=100e-6, k=0.0)]
125125
p = plot([FreeSpace(100e-3)], beam)
126+
p = plot!([FreeSpace(100e-3), ThinLens(100e-3), Thicklens(R1=100e-3, R2=200e-3, t=0.0)], height=10)
126127
@test p == p
127128
end
128129
end

0 commit comments

Comments
 (0)