#spherical grid using Fibonacci lattice abstract SphericalGrid <:AbstractCartPos immutable SphFib <:SphericalGrid pos::Array{Float64} xc::Array{Float64,1} #center of the array r::Float64 #radius of array N::Int64 #num ofpoints kd::Array{Float64} #versor θ::Array{Float64,1} #azimuthal angle ϕ::Array{Float64,1} #polar angle X::Float64 #maximum nearest neighbour distance function SphFib(xc,r,N) if N<0 error("N must be greater than 0") end z = zeros(Float64,N) θ = zeros(Float64,N) Δz = 2./N #step in z Δθ = π * (3. - sqrt(5.)) #golden angle z[1] = 1-Δz/2 #initialize z with offset #z is cos(ϕ) for i in 2:N θ[i] = θ[i-1]+Δθ θ[i] = mod(θ[i],2*π) z[i] = z[i-1]-Δz end ϕ = acos(z) x = cos(θ) .* sin(ϕ) y = sin(θ) .* sin(ϕ) pos = r.*[x y z]'.+xc #multiply by radius and translate to center kd = [x y z]' X = max_nearest_neigh(N,pos) new(pos,xc,r,N,kd,θ,ϕ,X) end end immutable SphDir <:SphericalGrid pos::Array{Float64} xc::Array{Float64,1} #center of the array r::Float64 #radius of array N::Int64 #num ofpoints kd::Array{Float64} #versor θ::Array{Float64,1} #azimuthal angle ϕ::Array{Float64,1} #polar angle function SphDir(xc,r,θ,ϕ) x = cos(θ) .* sin(ϕ) y = sin(θ) .* sin(ϕ) z = cos(ϕ) pos = r.*[x y z]'.+xc #multiply by radius and translate to center kd = 2*π*[x y z]' N = length(θ) new(pos,xc,r,N,kd,θ,ϕ) end end #TODO make this more efficient function max_nearest_neigh(N::Int64,pos::Array{Float64,2}) d = zeros(N,N) for i = 1:N, ii = 1:N d[i,ii] = norm(pos[:,i]-pos[:,ii]) end d = d+Inf*speye(N,N) d = sort(d,1) X = maximum(d[1,:]') return X end function Base.show(io::IO, f::SphFib) println("Spherical Fibonacci Lattice") @printf("radius : %.2f m \n",f.r) @printf("center of array : [x;y;z] = [%.2f;%.2f;%.2f]\n",f.xc[1],f.xc[2],f.xc[3]) println("number of pos : $(f.N)") @printf("max nearest neigh dist : %.1e \n",f.X) end function Base.show(io::IO, f::SphDir) println("Spherical Direction") @printf("radius : %.2f m \n",f.r) @printf("center of array : [x;y;z] = [%.2f;%.2f;%.2f]\n",f.xc[1],f.xc[2],f.xc[3]) println("number of pos : $(f.N)") end