Have you ever wondered what the motion of a falling ball neglecting air resistance bounces? Will the ball bounces infinitely if no air resistance? Or will the ball bounces more? It is very hard to create an experiment like this in real world because we need to have a vacuum container to make this happen. Luckily, we can do this experiment in the computer using a simulation.
During our experiment in Physics, we need to determine the highest Kinetic Energy of the three given balls: rubber ball, ping-pong ball, and marble, as they fall from a height. We don't have these balls in our houses and it is hard for us to perform without the help of others. So, I decided to create a simulation of a free-falling ball that bounces.
But before I proceed on to coding, I need to have a plan, or in programming term, I should have a design first. Not the visual representation of the final simulation like the colors, the graphics and such, but the design of the system to orderly maintain the simulation dynamically.
Platform to use
First thing to consider is the platform to publish. I want to share this simulation to my groupmates to let them observe and conclude ideas. To easily share and run this simulation without needing them to download anything, is to develop this in web. I don't know much about websites, so it's another challenge for me since I mostly develop applications in desktop.
System
Next is the system itself. The simulation must have obviously, a ball object. Now, objects have attributes or properties that can be modified to perform different actions. So the ball must have a location, type of ball, color in relation to its type, velocity, a radius, and its elasticity (explained later on).
Our simulation also needs an environment, and in this environment, we remove the air. So we only need two things: the ground or the floor, and the acceleration due to gravity.
Interaction - relation of ball and the environment
Now that we have an object (ball) and an environment, we need to make them interact each other. Like the gravity affects the velocity of the ball, and the action to perform when the ball hits the ground.
The velocity of the ball at a certain time depends on the acceleration due to gravity, and we know that
a = v/t (acceleration = velocity / time)
So,
v = at (velocity = acceleration * time)
and substituting, we get:
velocity = (9.8 m/s^2)(t).
simplifying:
v = 9.8 m / s
Therefore, the velocity of our ball increases relative to our time.
We now have the equation for the velocity of our ball. But we need to calculate its height or the 'y' location. To do that, we need to learn to position the ball and the orientation of it in relation to the screen. Because in programming, the point of origin is not in the center of the screen, but instead at the upper left point.
And instead of having a negative acceleration as the ball goes down, we make it positive since we need to add the velocity and 'y' value to make it go down.
Therefore,
y = currentY + velocity
Next thing we need to have is the integration of elasticity of the ball to its velocity. We know that all balls have the same time taken to reach the ground but different velocity when going up.
To calculate the velocity when it is going up, we only need to multiply -1 to its current velocity, if and only if it is an elastic collision.
But in our simulation, instead of simply multiplying -1 to its velocity, we also need to multiply the elasticity of the ball.
So the new velocity of the ball after it hits the ground will be equated to:
V(after) v = (currentV * - 1) * elasticity
So after hitting the ground, the ball will no longer reach the height it came from.
We now have our plan. To make this into reality, we now proceed into coding..
But, remember what I said above that I don't know much about websites? Now is the time of struggle.
I still need to learn JavaScript, a scripting language for websites, to implement our design. But what makes it even more challenging? I need to finish it tomorrow so we can still do the experiment and submit it on Saturday.
Thankfully, awesome developers all over the world are creating wonderful applications and websites to develop much faster and easier!
I found this JavaScript framework called p5js which has an online editor and can even share your creations to anyone. So, problem solved! 🥳
So I quickly dive into coding. At this time, I was like playing a video game, encountering bugs and errors, killing those bugs, fixing errors, creating the environment, making the ball interact with the environment, polishing, and repeat.
After creating the environment and the physics of the ball, I added some controls. I added slider that controls the height of the drop, some radio buttons that can change the type of the ball, and buttons to reset and drop the ball.
Then, after several hours of learning and implementing at the same time, I finally make it! 🎉🎉🎉
If you want to view the code and tinker around, you can view it with this link, and the simulator with this.
I also had fun dropping the ball and quickly changing its type like dropping it from a height of 75 cm with a type of rubber and quickly change into marble just to test if my algorithm works correctly.
PS. This simulation is still not accurate in the real world experiments (no air resistance) because I do not have that much of data to the three balls when dropped, but this may still be useful like in our experiment which we don't need that much of an accuracy.
Generating and Visualizing Employment Status