Skip to content

Commit

Permalink
add plate shape
Browse files Browse the repository at this point in the history
  • Loading branch information
arturgower committed Mar 8, 2021
1 parent 0492d0f commit afdc30e
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 103 deletions.
2 changes: 1 addition & 1 deletion src/MultipleScattering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ __precompile__()
module MultipleScattering

## Shapes
export Shape, Circle, Rectangle, Box, EmptyShape, Halfspace, TimeOfFlight, TimeOfFlightFromPoint
export Shape, Circle, Rectangle, Box, EmptyShape, Halfspace, Plate, TimeOfFlight, TimeOfFlightFromPoint

export outer_radius, volume, name, iscongruent, (), congruent, in, issubset, origin, shape, Sphere, (==), isequal, show
export boundary_functions, boundary_points, boundary_data, bounding_box, box_corners
Expand Down
2 changes: 1 addition & 1 deletion src/physics/special_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ cartesian_to_radial_coordinates(x::Vector) = cartesian_to_radial_coordinates(SVe
radial_to_cartesian_coordinates::Vector) = radial_to_cartesian_coordinates(SVector...))

function cartesian_to_radial_coordinates(x::SVector{3,CT}) where CT
r = sqrt(sum(x .^2)) # note this should be complex if x is complex
r = sqrt(sum(x .^2)) # note this is, and should be, a complex number when x is a complex vector
θ = atan(sqrt(x[1]^2+x[2]^2),x[3])
φ = atan(x[2], x[1])
return [r,θ,φ]
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/halfspace.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Halfspace(normal::AbstractVector{T} [, origin::AbstractVector{T}=zeros()])
N-dimensional [`Shape`](@ref) defined by all points x = origin - λ * normal, for any λ > 0.
A halfspace defined by all the points ``\\mathbf x`` that satify ``(\\mathbf x - \\mathbf o) \\cdot \\mathbf n < 0`` where ``\\mathbf n`` is the unit normal and ``\\mathbf o`` is the origin.
"""
struct Halfspace{T,Dim} <: Shape{T,Dim}
normal::SVector{Dim,T} # outward pointing normal vector
Expand Down
69 changes: 69 additions & 0 deletions src/shapes/plate.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
Plate(normal::AbstractVector{T}, width::T, [, origin::AbstractVector{T}=zeros()])
A plate defined by all the points ``\\mathbf x`` that satify ``|(\\mathbf x - \\mathbf o) \\cdot \\mathbf n| < w /2`` where ``\\mathbf n`` is the unit normal, ``\\mathbf o`` is the origin, and ``w`` is the width.
"""
struct Plate{T,Dim} <: Shape{T,Dim}
normal::SVector{Dim,T} # outward pointing normal vector
width::T # the width
origin::SVector{Dim,T}
end

# Constructors
Plate(normal::AbstractVector{T}, width::T, origin::AbstractVector{T} = zeros(T,length(normal))) where {T} = Plate{T,length(normal)}(normal ./ norm(normal), width, origin)

Plate(normal::NTuple{Dim,T}, width::T, origin::AbstractVector{T} = zeros(T,Dim)) where {T,Dim} = Plate{T,Dim}(normal ./ norm(normal), width, origin)

name(shape::Plate) = "Plate"

volume(shape::Plate) = Inf
outer_radius(hs::Plate{T}) where T = T(Inf)

# import Base.issubset
# function issubset(inner_rect::Plate{T}, outer_rect::Plate{T}) where T
# all(topright(inner_rect) .<= topright(outer_rect)) &&
# all(bottomleft(inner_rect) .>= bottomleft(outer_rect))
# end

import Base.in
function in(x::AbstractVector{T}, p::Plate)::Bool where T
abs(dot(x - p.origin, p.normal)) < p.width / T(2)
end

import Base.(==)
function ==(h1::Plate{T}, h2::Plate{T}) where T
h1.origin == h2.origin &&
h1.width == h2.width &&
h1.normal == h2.normal
end

import Base.isequal
function isequal(h1::Plate{T}, h2::Plate{T}) where T
isequal(h1.origin, h2.origin) &&
isequal(h1.width, h2.width) &&
isequal(h1.normal, h2.normal)
end

function iscongruent(h1::Plate{T}, h2::Plate{T}) where T
(h1.normal == h2.normal) && (h1.width == h2.width)
end

function congruent(h::Plate{T}, x) where T
Plate(h.normal, h.width, x)
end

# function boundary_functions(h::Plate{T,2}, scale::T = 10.0) where T
# surface_vec = [-h.normal[2], h.normal[1]]
#
# function x(t)
# check_boundary_coord_range(t)
# h.origin[1] + surface_vec[1] * width/2 + t * scale * surface_vec[1]
# end
#
# function y(t)
# check_boundary_coord_range(t)
# h.origin[2] + t * scale * surface_vec[2]
# end
#
# return x, y
# end
100 changes: 0 additions & 100 deletions src/shapes/rectangle.jl

This file was deleted.

2 changes: 2 additions & 0 deletions src/shapes/shapes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ end
include("box.jl")
include("sphere.jl")
include("halfspace.jl")
include("plate.jl")
include("time_of_flight.jl")
include("time_of_flight_from_point.jl")
include("empty_shape.jl")

"""
points_in_shape(Shape; res = 20, xres = res, yres = res,
exclude_region = EmptyShape(region), kws...)
Expand Down
16 changes: 16 additions & 0 deletions test/shapetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,20 @@

@test true
end

@testset "Infinite volume shapes" begin
normal = rand(3);
origin = rand(3);
width = 1.0 + rand();
p = Plate(normal, width, origin)
h = Halfspace(normal, origin)

shapes = [p,h];

@test isempty(findall( (volume.(shapes) .== Inf) .== 0))

xs = [rand(3) for i = 1:10];
[[x s for x in xs] for s in shapes]

end
end

0 comments on commit afdc30e

Please sign in to comment.