A physics-based simulation of a jack-in-the-box that realistically models bouncing and collisions using real-world motion principles.
This project simulates a jack-in-the-box mechanism to study the interaction between rigid-body motion and internal impacts. The system’s motion is computed from analytical dynamics, with collisions between the jack and the box resolved using impulse-based methods.
The result is a compact simulation that highlights the role of coordinate frames, equations of motion, and contact dynamics in mechanical behavior.
The system is represented using multiple coordinate frames. A fixed world frame defines the inertial reference. A box frame moves and rotates with the enclosure. A jack frame rotates inside the box and defines the positions of the four tip masses. Points are mapped between frames using rigid-body transformations of the form
pworld = R · pbody + t
Expressing the jack in the box frame simplifies contact detection, since the box walls are fixed in that frame.
The motion of the box and jack is derived using the Euler–Lagrange formulation,
d/dt(∂L/∂q̇) − ∂L/∂q = Q
which governs smooth translational and rotational motion between collisions. These equations are numerically integrated forward in time.
When a jack tip contacts a wall, the collision is treated as an instantaneous event. Instead of integrating through contact, velocities are updated using an impulse-based formulation. The post-impact generalized velocities satisfy
∂L/∂q̇⁺ = ∂L/∂q̇⁻ + Jᵀλ
where (J) is the contact Jacobian and (λ) is the impulse magnitude. The impulse is solved by enforcing the contact constraint together with an energy consistency condition, resulting in realistic momentum transfer between the internal jack and the box. These repeated impacts produce rotation, bouncing, and jitter of the enclosure.
