/collision_simulation

Simulating object collisions || Circles which can bounce off one another if they collide

Primary LanguagePython

Stars


Collision🔮

A Simulating of object collisions designed with Pygame (Python)
Explore the documents »


Table of Contents
  1. About The Project
  2. Parts
  3. Results
  4. License
  5. Refenences
  6. Contact
  7. Roadmap

About The Project

Circles which can bounce off one another if they collide.

Our training will be based on simple circles.

# What are we making?

We can modify the characteristics of the circles to reflect the qualities they represent: We can use circles to make it simpler to use arithmetic to compute collisions, and we can change the properties of the circles to reflect the qualities they represent: More bulk, for example, or a larger radius.

(back to top)

Built With

Major frameworks/libraries used in this project:

(back to top)

Parts

1. What do we need to know to simulate a collision?

"Before we can simulate a collision, we need to know a few things."

First, we must determine which, if any, two objects are colliding.We need to find out how fast the two items are colliding, the angle of incidence , and the mass of each of the objects once we know which two things are colliding.

2. So, how can we figure out which objects are colliding?

When you utilize circles, it's quite basic. Every point around the circumference is the same distance from the center as every other point; the radius is the measurement from the edge to the center. We can tell if two items' outlines meet by calculating the distance between their centers. We can deduce that two circles are colliding if the distance between their centers is smaller than the radius of each circle combined together.

Snow
Forest

3. main.py [Introduction]

The logic for our keyboard ⌨️ and mouse 🖱️ interactions, as well as our main loop, is found on lines 137-202. Clicking in our window will produce a new particle that will only effect the movement of other particles once the mouse is released. The particle will inherit the velocity of the mouse pointer if the mouse was moving when it was released.

4. calculateMovement() Function

All of our objects will have a mass and will attract every other object gravitationally using the calculateMovement() method,which handles the gravity of all of our objects.

The last section of calculateMovement() doesn’t have anything to do with moving the circles: it simply draws a line between our droped circle and every other circle that it’s having an effect on. It’s the line of attraction we looked at earlier, and it illustrates the directions that gravity is pulling our circles in.

You can toggle this on and off with the ‘A’ key.

5. handleCollisions() Function

The handleCollisions() method, which can be found on lines 86-135. Here, we check for colliding objects and adjust their trajectories accordingly

(back to top)

Results

Left button :Use the mouse to create a new moving object.

ScreenCapture Preview 🖼️

(back to top)

Refenences

(back to top)

Contacts

Project Link: https://github.com/RabihND/collision_simulation

(back to top)

Roadmap

(back to top)