Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
add boundarymap plot
Browse files Browse the repository at this point in the history
  • Loading branch information
Datseris committed Feb 27, 2022
1 parent 1fb35af commit 2bed7a7
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "InteractiveDynamics"
uuid = "ec714cd0-5f51-11eb-0b6e-452e7367ff84"
repo = "https://github.com/JuliaDynamics/InteractiveDynamics.jl.git"
version = "0.19.0"
version = "0.19.1"


[deps]
Expand Down
24 changes: 22 additions & 2 deletions docs/src/billiards.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# # Visualizations and Animations for Billiards

# All plotting and animating for [DynamicalBilliards.jl](https://juliadynamics.github.io/DynamicalBilliards.jl/dev/) lies within a few well-defined functions from [InteractiveDynamics.jl](https://juliadynamics.github.io/InteractiveDynamics.jl/dev/) that use the [Makie](https://makie.juliaplots.org/stable/) ecosystem.
# All plotting and animating for
# [DynamicalBilliards.jl](https://juliadynamics.github.io/DynamicalBilliards.jl/dev/)
# lies within a few well-defined functions from
# [InteractiveDynamics.jl](https://juliadynamics.github.io/InteractiveDynamics.jl/dev/)
# that use the [Makie](https://makie.juliaplots.org/stable/) ecosystem.

# - For static plotting, you can use the function [`bdplot`](@ref).
# - For static plotting, you can use the function [`bdplot`](@ref) and [`bdplot_boundarymap`](@ref).
# - For interacting/animating, you can use the function [`bdplot_interactive`](@ref).
# This function also allows you to create custom animations, see [Custom Billiards Animations](@ref).
# - For producing videos of time evolution of particles in a billiard, use [`bdplot_video`](@ref).

# ## Plotting
# ```@docs
# bdplot
# bdplot_boundarymap
# ```
# ### Plotting an obstacle with keywords
using DynamicalBilliards, InteractiveDynamics, CairoMakie
Expand Down Expand Up @@ -79,6 +84,21 @@ lines!(ax, xt, yt)
bdplot!(ax, p; velocity_size = 0.1)
fig

### Boundary map plot
using DynamicalBilliards, InteractiveDynamics, CairoMakie

bd = billiard_mushroom()

n = 100 # how many particles to create
t = 200 # how long to evolve each one

bmap, arcs = parallelize(boundarymap, bd, t, n)

colors = [randomcolor() for i in 1:n] # random colors

fig, ax = bdplot_boundarymap(bmap, arcs, color = colors)
fig

# ## Interactive GUI
# ```@docs
# bdplot_interactive
Expand Down
44 changes: 0 additions & 44 deletions examples/billiards/billiard.jl

This file was deleted.

22 changes: 0 additions & 22 deletions examples/billiards/xmas.jl

This file was deleted.

1 change: 1 addition & 0 deletions src/billiards/defs_animating.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ function bdplot_plotting_init!(ax::Axis, bd::Billiard, ps::Vector{<:AbstractPart
)
end

# Boundary map
if !isnothing(bmax)
bmap_points = [Observable([Point2f(c.ξsinθ)]) for c in chs[]]
for i in 1:N
Expand Down
35 changes: 29 additions & 6 deletions src/billiards/defs_plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,36 @@ function remove_axis!(ax)
end

######################################################################################
# Misc.
# Boundary map
######################################################################################
function _estimate_vr(bd)
xmin, ymin, xmax, ymax = DynamicalBilliards.cellsize(bd)
f = max((xmax-xmin), (ymax-ymin))
isinf(f) && error("cellsize of billiard is infinite")
vr = Float32(f/25)
"""
bdplot_boundarymap(bmap, intervals; figkwargs = NamedTuple(), kwargs...)
Plot the output of [`DynamicalBilliards.boundarymap`](@ref) into an axis that
correctly displays information about obstacle arclengths.
Also works for the parallelized version of boundary map.
## Keyword Arguments
* `figkwargs = NamedTuple()` keywords propagated to `Figure`.
* `color` : The color to use for the plotted points. Can be either a
single color or a vector of colors of length `length(bmap)`, in
order to give each initial condition a different color (for parallelized version).
* All other keywords propagated to `scatter!`.
"""
function bdplot_boundarymap(bmap, intervals;
color = JULIADYNAMICS_COLORS[1], figkwargs = NamedTuple(), kwargs...)
fig = Figure(;figkwargs...)
bmapax = obstacle_axis!(fig[1,1], intervals)
if typeof(bmap) <: Vector{<:SVector}
c = typeof(color) <: AbstractVector ? color[1] : color
scatter!(bmapax, bmap; color = c, markersize = 4, kwargs...)
else
for (i, bmapp) in enumerate(bmap)
c = typeof(color) <: AbstractVector ? color[i] : color
scatter!(bmapax, bmapp; color = c, markersize = 3, kwargs...)
end
end
return fig, bmapax
end

function obstacle_axis!(figlocation, intervals)
Expand Down
3 changes: 2 additions & 1 deletion src/billiards/exports.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export bdplot, bdplot!
export bdplot_animstep!
export bdplot_interactive
export bdplot_video
export bdplot_video
export bdplot_boundarymap

0 comments on commit 2bed7a7

Please sign in to comment.