Skip to content

JLMSC/3d-random-walk-diffusion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random Walk Diffusion Simulation (3D Stochastic Model)

This work presents a computational simulation of a 3D stochastic random walk system combined with a density-based visualization model. A set of particles evolves inside a bounded cubic space, where each particle moves randomly along one of the three axes at each iteration. The system visualizes both spatial distribution and local density using a real-time 3D scatter plot with color mapping.

Introduction

This work implements a discrete random walk simulation in a bounded 3D grid with the following objectives:

  • Simulate stochastic movement of multiple particles in 3D space.
  • Constrain motion inside a finite cubic domain using wrap-around behavior.
  • Compute local spatial density of particle distributions.
  • Visualize particle evolution in real time using Matplotlib 3D rendering.
  • Encode density information into color intensity for visual interpretation.

The system is designed as an exploratory tool for understanding diffusion-like processes and emergent spatial clustering in stochastic systems.

Problem Representation

The simulation operates on a discrete 3D lattice defined as:

$$ (x, y, z) \in [0, G]^3 $$

Where:

  • $G \in \mathbb{N}$ : grid size (spatial boundary)
  • $N \in \mathbb{N}$ : number of particles

Each particle $i$ is represented by:

$$ p_i = (x_i, y_i, z_i) $$

The system state at time $t$ is:

$$ S(t) = {p_1(t), p_2(t), \dots, p_N(t)} $$

Random Walk Dynamics

At each iteration, every particle performs a stochastic update:

  1. A random axis is selected: $x$, $y$, or $z$.
  2. A random step is chosen: $+1$ or $-1$.
  3. Position is updated using modular arithmetic:

$$ p_i(t+1) = (p_i(t) + \text{step}) \pmod{G + 1} $$

This ensures:

  • Constrained motion within bounds.
  • Toroidal (wrap-around) space topology.
  • No particle loss at boundaries.

Density Computation

To analyze spatial clustering, a density metric is computed:

$$ \text{density}_i = \frac{\text{count}(p_i)}{\max(\text{counts})} $$

Where:

  • $\text{count}(p_i)$ is the number of occurrences of position $p_i$.
  • $\max(\text{counts})$ is the highest frequency among all positions.

This produces a normalized density value in the range $[0, 1]$ used for color mapping in visualization.

Results

The system produces:

  • Emergent clustering patterns in bounded space.
  • Density heatmaps over 3D scatter distributions.
  • Dynamic diffusion-like behavior over time.

Higher iteration counts reveal:

  • Region concentration effects.
  • Random equilibrium distribution.
  • Local clustering persistence due to discrete collisions.

Limitations

  • Density computation is $\mathcal{O}(n^2)$.
  • Visualization re-creates scatter plot each frame.
  • No physical forces (purely stochastic motion).
  • Discrete grid approximation may introduce aliasing effects.