physics_sandbox
A small, dependency-free rigid-body physics sandbox in Rust. Pluggable
integrators, environment forces (gravity, wind, air density), simple
sphere–sphere collisions, and a tiny event bus for collisions and threshold
triggers. Optional retro ASCII terminal visualization and SVG trajectory
export behind the viz feature.
100 kg missile, v₀ = 500 m/s @ 45°, thrust = 5 kN for 3 s. Generated by
examples/missile_svg.rs.
Add it
[]
= "0.1"
# with the terminal visualization + SVG export helpers:
= { = "0.1", = ["viz"] }
Quick start
use ;
let env = new;
let mut world = new;
let id = world.add_body;
for _ in 0..10_000
Modules
| Module | What's in it |
|---|---|
math |
Vec3 and basic linear algebra |
dynamics |
RigidBody, force/torque application, drag |
environment |
Gravity, wind, air density |
integrator |
Integrator trait, EulerIntegrator, RK4Integrator |
collision |
Sphere–sphere collision tests |
events |
EventBus, SimEvent, threshold triggers |
viz (opt.) |
AsciiScope, MultiView, Recorder + SVG export |
Examples
# Plain numeric output
# Visualization (requires the `viz` feature)
Visualization API at a glance
use ;
// 2D ortho scope
let mut scope = new;
// 3D perspective scope (depth-buffered, with a ground reference grid)
let mut scope3d = new_3d
.with_ground_grid;
// Three-panel instrument cluster (SIDE X-Y, TOP X-Z, FRONT Z-Y).
// The most readable option for 3D trajectories in a terminal.
let mut cluster = three_view;
// Record samples during the sim and export an SVG report at the end.
let mut rec = new;
rec.push;
rec.export_svg?;
Features
viz— opt-in terminal visualization and SVG export. Pulls incrosstermfor live rendering; the SVG path is pure Rust string output and adds no extra deps. Gives you:AsciiScope— 2D ortho or 3D perspective, depth-buffered, motion trails with per-cell aging so trails always read against the ground.MultiView— three side-by-side ortho panels (SIDE / TOP / FRONT) for clear readout of 3D trajectories without fighting perspective.Recorder+export_svg— record(t, pos, phase)samples during the sim, then write a 2×2 SVG (SIDE / TOP / FRONT / summary box) with axis ticks, gridlines, color-coded boost/coast segments and an impact marker.
License
Dual-licensed under either of:
- MIT license (LICENSE-MIT)
- Apache License, Version 2.0 (LICENSE-APACHE)
at your option.