Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
Testing and Validation

Numerical correctness and validation strategy for the physics engine.


Numerical Integration Method

The physics engine uses Velocity Verlet integration due to its stability and favorable energy conservation properties.

For general motion, the method has:

  • Local truncation error of
    • \( O(\Delta t^4) \) for position
    • \( O(\Delta t^3) \) for velocity
  • Accumulated global error over a fixed simulation time that scales as
    \( O(\Delta t^2) \) for both position and velocity

Constant-Force Special Case

The current simulation supports only constant forces (e.g., gravity and constant thrust).

In this case, acceleration satisfies:

\[ \frac{d\ddot{\vec{r}}}{dt} = 0 \]

Velocity Verlet integrates constant acceleration exactly, meaning the theoretical truncation error is zero. As a result, any deviation from the analytical solution arises solely from floating-point rounding error.


Floating-Point Error Model

For constant-force test cases, the expected bound on position error is:

\[ \lVert \vec{r}_{\text{error}} \rVert \le C \cdot N \cdot \epsilon \cdot \max\!\left(\lVert \vec{r}(t) \rVert\right) \]

where:

  • \( N \) is the number of integration steps

    \[ N = \frac{1}{\Delta t} \]

  • \( \epsilon \) is the machine epsilon for single-precision floating point

    \[ \epsilon \approx 1.19 \times 10^{-7} \]

  • \( \max(\lVert \vec{r}(t) \rVert) \) is the maximum magnitude of the position vector reached during the simulation
  • \( C \) is a small conservative constant accounting for the number of floating-point operations per integration step

Testing Strategy

Unit tests validate the physics core by:

  • Comparing numerical results against closed-form analytical solutions
  • Scaling tolerances according to the floating-point error bound above
  • Verifying correctness across:
    • Zero acceleration
    • Constant velocity
    • Constant acceleration (free fall)
    • Multi-axis force composition
    • Mass scaling under identical forces

This approach ensures that test failures indicate true logical or numerical errors, rather than expected floating-point noise.