Particle simulations
...and fluid dynamics.
You can simulate a fluid with particle simulations as follows:
- Use nanometers and microseconds as a unit of measurement; this allows for integer operations throughout. 2^31 gives around 2 meters and around 2000 seconds.
- Simulate using a quad-tree (or oct-tree in 3-D). The leaves of the quad-tree are the particles.
- Each quad-tree node has at least the following attributes:
- Whether a collision is likely to have happened inside it.
- The next time this node or a sub-node of this node needs to be recalculated.
- Each "step" involves copying the quad-tree. Nodes are treated as copy-on-write.
- There are two types of steps: computations made when collisions occur at exact times, and frame-by-frame animation.
- Particles have:
- An origin at time=t1.
- A destination at time=t2. This only needs recomputing if a collision happens. Collisions happen when one particle exherts a force on another. (thought: gravity is a constant force which will always cause collisions)
- The particle is thus treated as a line between two points. The actual location can be computed on the fly if needed.
- An acceleration vector.
- Some mechanism for accumulating forces from surrounding particles.
- Attractiveness curves/formulae to other particles, mass. These characteristics are constants.
- Forces between particles have various components - nearby repulsive forces, distant attractive forces.
- When a particle travels, it marks the quad-tree nodes it could pass through in the line of travel as "collisionable". All particles in those nodes need to calculate whether they collide with each other.
Because gravity will cause collisions at every step, perhaps some fancy quadratic equations could be used? Ideally, the computation for a particle with no collisions would be a single step determining the starting point, ending point and curve.