4 - Ball Gravity

Introduction

This simulation shows how the gravity acts on a ball, making it fall and bounce when it hits the ground. It's a classic demonstration of the motion under uniform acceleration and energy transformation.

Concept of Gravity and Free Fall

Gravity is a natural force that pulls the objects towards the center of the Earth. In this simulation, the ball experiences a constant downward acceleration due to the gravity, causing it to speed up as it falls. The rate of acceleration depends on the gravity type selected (e.g., Earth, Moon, Jupiter or Mars).

  1. Objects in free fall accelerate at approximately 9.81 m/s² on Earth.
  2. When the ball hits the ground, it bounces due to the elastic collision principles.
  3. Each bounces loses some energy, resulting in lower heights with each subsequent bounce.

Physics Behind It

  • The gravitational acceleration (g) acts continuously on the ball: thus, increasing its downward velocity over time.
  • When the ball hits the surface, its velocity reverses the direction and reduces in magnitude due to the energy loss during the bounce.
  • Wind and friction parameters can slightly affect horizontal motion, simulating air resistance.
h=12gt2,v=u+gt,Ek=12mv2h = \frac{1}{2} g t^2, \quad v = u + g t, \quad E_k = \frac{1}{2} m v^2
The ball's total energy is a sum of kinetic and potential energy, which transforms during the fall and bounce.

Code Example

let x = 100, y = 100;

let vy = 0;
const gravity = 0.98; // Gravitational acceleration
const bounceFactor = 0.7; // Energy loss on bounce
let ground = 400; // Ground level

function draw(){
   vy += gravity; // Apply gravity to vertical velocity
   y += vy; // Update position

   // Check for collision with ground
   if(y >= ground) {
      y = ground; // Reset position to ground level
      vy = -vy * bounceFactor; // Reverse and reduce velocity for bounce
   }
      //Draw the ball at (x, y)
      circle(200, y, 40);
}

Simulation Parameters

ParameterDescriptionExample Value
Ball Size (px)Determines the diameter of the ball in pixels.40
Mass (kg)Defines the weight of the ball, affecting its momentum and kinetic energy.5
Friction Coefficient (μ)Reduces the motion after bouncing to simulate air resistance.0
Wind (m/s²)Applies a horizontal acceleration simulating air movement.1
Gravity TypeSelects the gravity strength based on different celestial bodies like Earth, Moon, Jupiter, or Mars.Earth (9.81 m/s²)

Tips & Tricks

Did you know
Gravity is the sane force that keeps planets orbiting the sum and also, this simulation mimics the universal attraction on a smaller scale.
Attention!
If the bounce factor is set too high (>1), the ball may gain energy unrealistically and fly off-screen.
Try It Yourself!
Experiment by changing the gravity type and bounce factor to see how they affect the ball's motion.
Concept Mastered!
You've learned the gravitational acceleration, collisions, and energy conservation work together in real-world physics