Skip to content

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Collision Simulator

A simple physics-based collision simulator built with React. This project demonstrates the motion of two square boxes on a 1D plane, their collisions with each other, and their interactions with the walls. The simulation is based on fundamental physics equations such as conservation of momentum and elastic collisions.


🚀 Features

  • Box-to-box collisions using conservation of momentum and elastic collision formulas.
  • Wall collisions simulated by reversing velocity (perfectly elastic).
  • Real-time animation with adjustable velocity and mass values.
  • User controls for play/pause and editing simulation parameters.

📐 Physics Behind the Simulation

Position Update Formula

The position of a body is calculated as:

X = v * t + x

Where:

  • x = initial position
  • X = final position
  • v = velocity
  • t = elapsed time

Collision Detection (Box-to-Box)

For two equal-sized square boxes:

X2 - X1 = W
  • X1, X2 = positions of centers
  • W = 2w (where w is half the width of each box)

Expanding with velocity:

(x2 + v2 * t) - (x1 + v1 * t) = W
(x2 - x1) + (v2 - v1) * t = W

t = (W - (x2 - x1)) / (v2 - v1)

Conservation of Momentum

m1 * v1 + m2 * v2 = m1 * V1 + m2 * V2

Where:

  • m = mass
  • v = initial velocity
  • V = final velocity

Elastic Collision Speed Relation

(v1 - v2) = - (V1 - V2)

This ensures approach speed = separation speed.

Final derived velocities:

V2 = (2*m1*v1 + m2*v2 - m1*v2) / (m1 + m2)
V1 = V2 - v1 + v2

Wall Collision

A wall is treated as a body with infinite mass and zero velocity. Instead of fully simulating, the velocity is simply reversed:

V1 = -v1

🛠️ Installation

  1. Clone the repo:

    git clone https://github.com/Hrithwin123/Collision-Simulator.git
    cd Collision-Simulator
  2. Install dependencies:

    npm install
  3. Run the development server:

    npm run dev

🎮 Usage

  • Click Play to start the simulation.
  • Adjust velocity and mass values for each box.
  • Click Apply Values to update parameters during simulation.
  • Observe collisions and wall bounces in real time.

📚 References

  • Elastic collisions: Wikipedia
  • Conservation of momentum
  • Basic kinematics equations

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages