- 2D Newtonian Particle Simulation
- Particle simulation that uses phone gyroscope and accelerometer to influence the particle.
- Written using OpenGL Graphics, OpenGL Mathematics and c++, using java as a wrapper.
For each particle $i \in [0, N)$ with position $\mathbf{p}_i = (x_i, y_i)$ and velocity$\mathbf{v}_i = (x_i, y_i)$ :
Each particle is mapped to a uniform grid cell:
where
Each frame (or substep), the velocity and position are updated as:
where:
-
$( \mathbf{g} )$ = gravity vector -
$( \mathbf{a} )$ = external acceleration -
$( d )$ = damping factor -
$( \Delta t_{\text{sub}} )$ = substep time interval
For collision handling, each particle checks neighboring cells within offsets:
and for each valid neighbor cell
We only process pairs with
For a neighbor particle ( j ):
Compute relative displacement:
If
Then:
Penetration depth:
Apply equal and opposite corrections:
Relative velocity along the collision normal:
If
Apply impulse with restitution coefficient
Update velocities:
This procedure models:
- Continuous gravity and damping integration
- Spatial partitioning for efficient neighbor lookup
- Overlap correction (position-based collision)
- Elastic response via velocity impulse
Symbols:
| Symbol | Meaning |
|---|---|
| Position of particle ( i ) | |
| Velocity of particle ( i ) | |
| Gravity vector | |
| External acceleration | |
| Damping factor | |
| Coefficient of restitution | |
| Particle radius | |
| Particle assigned cell | |
| Substep timestep |
