In this project we design a dynamic simulation of a jack inside a box. Jack can freely move inside the box, but as the 2 objects collide with each other impact rules are applied to simulate a result we would expect to happen in reality. Our objects have masses, Inertia, and gravity.
The project utilizes the Euler-Lagrange equation(figure 1). With the Euler Lagrange, we can simulate the system, such as add gravity. For the impact, we consider the Jack as 4 balls at the edge of him all of which are connected with each other. We define them as frames and keep track of their position(figure 2). Having defined 4 additional frames at the middle of each wall of our box(figure 3) we check the manhattan distance between these frames (16 in total) on each step of the simulation. If the distance is zero in any of those equations then an impact has occurred and we update the systems velocities properly.
Fig. 1 Euler-Lagrange Equastion
Fig. 2 Jack Frames
Fig. 3 Box Frames
After the project is complete we are able to do different simulations with simple code modifications. Modifications such as applying rotation forces, gravity, or choose which object gets affected by the impact. Below we see some simulations of our system.
Fig. 4 Gravity on Jack
Fig. 5 Grafic plots of fig.4
At figure 4 we set gravity only at Jack and the impact affecting both items. As a result, Jack due to gravity forces the box to move down. At figure 5 we see the plots of position and velocity for both items.
Fig. 6 Traslation Forces
At figure 6 we apply oscilating forces at the box leading in a right to left movement or up and down. In the first example (left gif) both items do not have gravity. While on the second example(right gif) Jack has gravity which makes the forces applied to the box incapable of keeping a "perfect oscillation" since the gravity force increases the energy of the box due to the impact leading hit towards the floor. both of the objects get affected by the impacts in both examples.
Fig. 7 Rotation Forces
At figure 7 we apply rotation forces at the box and Jack is under the influance of gravity. On the first gif (left) the impact does not affect the box this is why his position does not change. While on the second gif(right) the impact affects both items eventually forcing the box to go downwards.