Rescaled Hexagonal Substrate Movement
Brian S. Yandell
28 July 2026
hexmove.RmdPrompts
I want to develop an app in this repo that begins with
a simulation at some stage, say
mysim <- init.simulation()
mysim <- future.events(mysim, nstep=100)
I want to visualize the position of each organism on the hexagonal substrate of the `triangleApp()` app (with hexagonal grid overlay instead of centroid points) using
symbols as in `substrateApp()`. Place organisms on hexagons
based on their triangular coordinates rather than the horizontal/vertical system used in `substrateApp()`.
I want to be able to step through the simulation, either
one step at a time or multiple steps.
Architectural Rationale & Overview
The hexmoveApp application visualizes host and parasite
spatial positions mapped directly onto a unified hexagonal substrate
network topology (create_substrate).
Instead of rendering substrate components (fr1..fr4,
tw1..tw2, lftop, lfbot) in
isolated rectangular panel facets (as done in the original
substrateApp()), hexmoveApp places every
organism on a continuous hexagonal substrate plane based on its native
tridiagonal coordinates
and its active substrate patch (sub.stage).
Organism coordinates are dynamically rescaled per substrate component
so that all individuals are visualized strictly within the boundaries of
their respective substrate surface patches (fr1,
fr2, lftop, twig, etc.).
Substrate Resolution & Rescaling Coordinate Mapping
1. Substrate Component Resolution
Each organism in an ewing simulation tracks its
substrate position in individual["sub.stage"]. This integer
index maps to specific plant substrate elements defined in
getOrgInteract(community, substrate, species): -
fr1, fr2, fr3, fr4:
Fruit component facets - twig / tw1,
tw2: Twig component facets - lftop,
lfbot: Leaf top and bottom surface facets
substrate_topology
defines topological offsets
and component orientations (dir = "up" or
"down") for each substrate element. Substrate component
names like twig are mapped to tw1 to ensure
every individual is placed precisely on its active substrate patch.
2. Per-Substrate Unit Triangle Rescaling
Simulation coordinates generated by
init.population(width = 100) or rtri() span up
to 100 units. To map organisms accurately within substrate surface
triangles of size
(which may vary per substrate in future configurations):
Local Coordinate Normalization: For the subset of organisms on substrate : Applying a 15% inner padding buffer ():
-
Global Tridiagonal Coordinate Transformation:
- If component orientation is
"up": - If component orientation is
"down"(inverted triangle):
- If component orientation is
Global Cartesian Mapping: Converting to Euclidean coordinates via
tri2car():
This guarantees that all organisms on substrate are displayed strictly inside that substrateβs surface area.
Multi-Species Display Modes & Filtering
hexmoveApp supports multi-species simulation communities
(e.g.Β host and parasite):
Species Filtering: Users can toggle which species to display (
Hostand/orParasite) using inline checkboxes in the sidebar (show_species).-
Multi-Species View Modes:
-
Overlay (1 Map): Renders all selected species (hosts AND parasites) simultaneously on a single unified hexagonal substrate map. Host stage symbols (0,1,2,3β¦) and parasite stage symbols (E,L,P,pβ¦) sit together on the same hexagonal grid layout, allowing direct visualization of spatial host-parasite overlaps. -
Separate (Adjacent Maps): Renders each selected species on its own distinct hexagonal grid map side-by-side (cowplot::plot_grid(ncol = length(species), align = "h")).
-
Hexagonal Grid Overlay (create_hex_overlay)
A discrete hexagonal grid overlay is generated over the substrate
lattice points (sub_obj$points) using create_hex_overlay().
For each lattice center
,
a 6-sided polygon cell is computed:
where radius
scales with grid spacing step and nearest-neighbor distance
.
Interactive Simulation Stepping
The interactive controls in substrateInput and substrateServer provide: -
Stepping Action Buttons: +1 Step,
+10 Steps, +100 Steps, and Reset.
Clicking a step button executes
future.events(sim, nstep = n) and reactively updates the
substrate visualization. - Species Filter & View
Modes: Checkboxes for selecting species (host,
parasite) and radio buttons for
Overlay (1 Map) vs Separate (Adjacent Maps). -
Layout Switching: Toggle between
"Hex Substrate Overlay" (global hexagonal network) and
"Faceted Substrates" (panel view faceted by substrate
element fr1..fr4, twig, lftop,
lfbot). - Layer Controls: Dynamic
checkboxes for Substrate Boundaries (poly), Hex Grid
Overlay (hex), Organism Symbols (organisms),
Substrate Identifiers (centers), and Side Numbers
(labels).
Application Usage
Launch hexmoveApp with an initial simulation object or
run default initialization:
library(ewing)
# Initialize simulation and run initial 100 steps
mysim <- init.simulation()
mysim <- future.events(mysim, nstep = 100)
# Launch interactive Shiny app
hexmoveApp(mysim)The app launcher script is located at inst/scripts/hexmoveApp.R.