begin
    import Pkg
    Pkg.activate(joinpath(@__DIR__, ".."))
    using CoupledDipole
    using CairoMakie
    using StaticArrays
    using Rotations
end

Near field of a gold-sphere chain

Five 10 nm-radius gold spheres, spaced by 80 nm in water, are illuminated at 633 nm along z. The first linear polarisation is along x. We plot total electric intensity relative to the unit incident intensity in the xy plane. The point-dipole approximation is not a resolved internal-field model: probes inside particles are excluded from the plot.

begin
    material = Material([633.0], Dict("Au" => epsilon_Au, "medium" => λ -> 1.33))
    cluster = cluster_chain(5, 80, 10, 10, 10)
    x = collect(-220.0:5.0:220.0)
    y = collect(-80.0:5.0:80.0)
    probes = [SVector(xi, yi, 0.0) for xi in x, yi in y][:]
end
2937-element Vector{SVector{3, Float64}}:
 [-220.0, -80.0, 0.0]
 [-215.0, -80.0, 0.0]
 [-210.0, -80.0, 0.0]
 [-205.0, -80.0, 0.0]
 [-200.0, -80.0, 0.0]
 [-195.0, -80.0, 0.0]
 [-190.0, -80.0, 0.0]
 ⋮
 [195.0, 80.0, 0.0]
 [200.0, 80.0, 0.0]
 [205.0, 80.0, 0.0]
 [210.0, 80.0, 0.0]
 [215.0, 80.0, 0.0]
 [220.0, 80.0, 0.0]
begin
    intensity, _, _, positions = map_nf(probes, cluster, material, [RotZ(0.0)];
        evaluate_inside=false)
    @assert size(intensity) == (length(probes), 2)
    @assert all(isfinite, intensity[.!positions.inside, :])
    outside_intensity = copy(intensity[:, 1])
    outside_intensity[positions.inside] .= NaN
end
65-element view(::Vector{Float64}, [1259, 1275, 1291, 1307, 1323, 1347, 1348, 1349, 1363, 1364  …  1574, 1575, 1589, 1590, 1591, 1615, 1631, 1647, 1663, 1679]) with eltype Float64:
 NaN
 NaN
 NaN
 NaN
 NaN
 NaN
 NaN
   ⋮
 NaN
 NaN
 NaN
 NaN
 NaN
 NaN
let
    fig = Figure(size=(750, 350))
    ax = Axis(fig[1, 1], xlabel="x / nm", ylabel="y / nm", aspect=DataAspect())
    hm = heatmap!(ax, x, y, reshape(outside_intensity, length(x), length(y));
        colormap=:viridis)
    Colorbar(fig[1, 2], hm; label="Total |E|^2 / incident |E|^2")
    fig
end