Rigid Body Simulation¶
Overview¶
NovaPhy's rigid body pipeline handles free-floating bodies with collision detection and constraint resolution.
Creating Bodies¶
import numpy as np
import novaphy
builder = novaphy.ModelBuilder()
# Ground plane
builder.add_ground_plane(y=0.0)
# Box body (mass, half-extents)
body = novaphy.RigidBody.from_box(1.0, np.array([0.5, 0.5, 0.5]))
idx = builder.add_body(body, novaphy.Transform.from_translation(np.array([0, 5, 0])))
builder.add_shape(novaphy.CollisionShape.make_box(np.array([0.5, 0.5, 0.5]), idx))
Collision Detection¶
Broadphase¶
Filters candidate collision pairs using axis-aligned bounding boxes:
- Sweep and Prune (SAP) — Default, efficient for mostly-static scenes
- BVH — Better for dynamic scenes with many moving objects
Narrowphase¶
Generates exact contact points for each candidate pair:
| Pair | Algorithm |
|---|---|
| Sphere-Sphere | Analytic distance check |
| Sphere-Plane | Signed distance to plane |
| Box-Sphere | Closest point on box |
| Box-Plane | Vertex projection |
| Box-Box | Separating Axis Theorem (SAT) |
| Convex-Convex | GJK + EPA |
Solvers¶
SolverSemiImplicit (Default)¶
Sequential Impulse solver with:
- Warm starting from previous frame
- Accumulated impulse clamping
- Coulomb friction (tangential impulse <= mu * normal impulse)
- Baumgarte stabilization for penetration correction
SolverXPBD¶
Extended Position Based Dynamics with compliance-based constraints. Operates in maximal coordinates.
Modifying State¶
Python binding limitation
Python bindings return copies of std::vector. Use setter methods to modify C++ state:
Demos¶
| Demo | Description |
|---|---|
demo_pyramid_ball.py |
Pyramid stack with sphere projectile |
demo_friction_ramp.py |
Boxes on a 30-degree ramp |
demo_wall_break.py |
Wall hit by a sphere |
demo_dominoes.py |
Chain reaction dominos |
demo_unified_collision.py |
Gallery of all collision pairs |
demo_pyramids_numerous.py |
Stress test with many pyramids |