Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Projectile

Calculator
MENG102-FALL21

Team Members & Group

Ahmed Fahmy Mohamed (202000419)/ 01

Anas Mohamed Mohamed (202000207)/ 01

Nadine Abdelaleem Mahmoud (202000509)/ 03

Suhyb Moustafa Awadalla (202000265)/ 01

Instructor

Dr. Mohamed Mohamed Elshabrawy


Table of Contents

Introduction 2

Figure 1. 2

Governing Equations 3

Methodology 5

Figure 2. 6

Conclusion 7

Video of the Simulation7

Appendix 8

1
Introduction

Projectile motion is the motion of an object that is projected into the air and is only affected by
the acceleration of gravity. The object is called a projectile, and its path is called its trajectory. Originally
the projectile is projected with an initial velocity at an angle to the ground. As the object moves through
the air, it is subjected to constant gravitational acceleration which pulls it vertically downwards along the
y axis. In reality, air resistance is also a force that might affect the acceleration of the projectile, but it is
negligible. This means that the object’s trajectory is along both the x and y axes and can be seen as a
parabola when observed. The only case where the trajectory can be seen as a straight line is if the
projectile is thrown vertically. An example of the projectile and its trajectory can be seen in Figure 1.

Figure 1. The total displacement s of a soccer ball at a point along its trajectory.

Our aim for this project was to create a projectile motion calculator that is able to use some
simple initial parameters to calculate the total time of flight, total horizontal distance traveled, and the
maximum height achieved by a projectile. The calculator was programmed in Python using the equations
of projectile motion which are derived from the basic kinetic equations. It has a functioning user interface
to allow the user to adjust the initial parameters and see the results with ease.

2
Governing Equations

To derive the equations needed to analyze parameters in a projectile motion, we must use the
traditional equations of motion.

x=x 0 +vt

v=v 0 + at

1 2
x=x 0 +v 0 + at
2

2 2
v =v 0 +2 a ( x−x 0 )

When a projectile is launched, it moves at an angle to the x-axis. This angle is used to derive the
vertical and horizontal components of the projectile’s velocity using trigonometry.

v x =v cos θ

v y =v sin θ

The motion is then treated as two independent motions, one in the horizontal direction and one in
the vertical. In the horizontal direction there is no force acting on the projectile which means that the
acceleration is 0 (denoted by “a”). Since there is no acceleration on the x-axis, the horizontal component
of velocity is constant throughout the flight of the projectile. The only function in the horizontal direction
that changes with time is the horizontal position of the projectile denoted by “x”.

x=x 0 +v x t

v x =v 0 cos θ

a x =0

Projectile motion is dependent on the fact that only one force (gravity) acts on a projectile and
thus the projectile only accelerates toward the center of the earth. This means that throughout the flight,
the projectile’s vertical component of velocity decreases at a constant rate of 9.8 ms -2 (assuming that up is

3
the positive y-axis). The vertical position of the projectile also changes with time which is denoted by
“y”.

v 0 y =v 0 sin θ

1 2
y= y 0+ v 0 y t− g t
2

v y =v 0 y −¿

−2
a y =−g=−9.8 ms

These equations can all be used to calculate the desired parameters at any given time and analyze
the projectile motion. However, if time is not given as an original parameter, the following equation can
be used to calculate any of the past parameters. The equation was derived by using the past equations and
eliminating the variable of time by substitution of other functions.

g ( x−x 0 )2
y− y 0=( x−x 0 ) tan θ− 2
( 1+ tan2 θ )
2v 0

4
Methodology

To create our calculator, we used the programming language called Python since we are already
proficient in its use. The first version we created in Python did not incorporate the use of a graphical user
interface as it was only a test version to figure out how to program the equations that we derived in the
previous section. We decided that the parameters that needed to be input by the user would be the initial
velocity of the object, angle of launch, and initial height. Those three parameters allowed us to fully
analyze the projectile motion of an object and were used in the equations of projectile motion to calculate
the desired results. After we got our desired results, we then incorporated those equations into a graphical
user interface using the “tkinter” library which allowed us to create spaces for inputting the parameters, a
button for calculating the results, and a button for resetting the calculator. In addition, to those functions,
it allowed us to add a background, an icon, and set the positions of all parts of our calculator.

As for the calculations, we decided that our results would be the total time of flight, the horizontal
distance traveled by the projectile, and the maximum height of the projectile. To calculate the total time
of flight of the projectile we needed to use the equation of the y-position, knowing that the end point
would be at y=0, to find the time, which was the only unknown variable in that equation. We translated
that equation and its steps into Python code and incorporated it into our program as a variable since it will
be used in the following results.

Next, was the range of travel which is the horizontal distance traveled by the projectile. We used
the equation of the x-position of the projectile and used the time of flight as the time variable in that
equation.

The last result is the maximum height achieved by the projectile during its motion. This can be
calculated by assuming that the projectile’s maximum height was achieved when its vertical component
of velocity was 0 and substituting that in the equation of vertical velocity which would give us the time it
took to reach maximum height. Then, that time would be used in the equation of the y-position. Those
two equations were incorporated as a code in our program.

Finally, A calculate button was made as a method of triggering the running of calculations as
Python functions. Validation functions were also placed to display error messages for the user if the
values that were input were not numbers. Tkinter was used to display the final results of the calculations
for the user. A reset button was also made to clear any past inputs in the calculator.

5
To test our calculator program, we decided to run it using arbitrary inputs and compared the
results to our own manual calculations that used the same initial parameters. The initial values for the
parameters were:

 Initial Velocity = 30 m/s


 Angle of Launch = 15o
 Initial Height = 5 m
After using these parameters to manually calculate and round the time of flight, horizontal
distance travelled, and maximum height, we found them to be:

 Time of Flight = 2.63 s


 Distance Traveled = 76.21 m
 Maximum height = 16.48 m
Our calculator also showed the same results as our calculations as seen in Figure 2.

Figure 2. Projectile motion calculator with results

6
Conclusion
The projectile motion of the object followed a constant horizontal velocity and a vertical velocity that was
consistent with the acceleration of gravity. The result showed that there was both and initial vertical and
horizontal velocity. The video computation method using python was able to simulate an equation of
velocity of ball thrown by the experimenter to a fairly precise level of accuracy and the ball’s path
followed projectile motion formulas. The initial velocity and firing angle both were determined according
to the user’s input in our calculator. For future experiments, to improve the data, we can start taking the
drag force and air resistance into consideration, which is going to result in a more precise outcome.

Video of the Simulation: https://drive.google.com/file/d/1j4MOmzZyjp-


d_bDmfrdd3YHA4dZJrvEZ/view?usp=sharing

7
Appendix

import tkinter as tk

import math

root = tk.Tk()

root.geometry("930x500")

root.iconbitmap("missile.ico")

root.title('Projectile Motion Calcuator')

g=9.8#

#backrgound

bg= tk.PhotoImage(file= "R3.png")

lbg= tk.Label(root, image= bg, bg='#002e39')

lbg.place(x=-10,y=-10)

title = tk.Label(root, fg="white", font = ('times new roman', 20,


'bold'), text = "Projectile Motion Calculator", bg='#002e39')

title.place(x=290, y=15)

8
#input labels

Vi = tk.Label(root, text='Initial Velocity in m/s:',font=("times new


roman",14,"bold", "italic"), fg="white", bg='#002e39')

Vi.place(x=30,y=100)

fa = tk.Label(root, text = 'Angle of Launch in Degrees:',font=("times


new roman",14,"bold", "italic"), fg="white", bg='#002e39')

fa.place(x=30,y=180)

h = tk.Label(root, text= 'Initial Height in meters: ',font=("times new


roman",14,"bold", "italic"), fg="white", bg='#002e39')

h.place(x=30,y=260)

# the function and the validation will be executed when the button is
clicked.

def onClick():

try:

float(initial_velocity_entry.get())

fa_valid.config(text="", bg='#002e39')

except ValueError:

fa_valid.config(text="Please enter a number!",font =


("times new roman",14,"bold", "italic"), bg='#002e39', fg="white")

try:

float(angle_of_launch_entry.get())

9
vi_valid.config(text="", bg='#002e39')

except ValueError:

vi_valid.config(text="Please enter a number!",font =


("times new roman",14,"bold", "italic"), bg='#002e39', fg="white")

try:

float(initial_height_entry.get())

h_valid.config(text="", bg='#002e39')

except ValueError:

h_valid.config(text="Please enter a number!",font =


("times new roman",14,"bold", "italic"), bg='#002e39', fg="white")

initial_velocity = float(initial_velocity_entry.get())

angle_of_launch = float(angle_of_launch_entry.get())

initial_height = float(initial_height_entry.get())

horizontal = initial_velocity *
math.cos(math.radians(angle_of_launch))

exponent = (initial_velocity *
math.sin(math.radians(initial_velocity)))**2

maximum_height = round(initial_height + exponent / (2 * g), 2)

time_of_flight = round((initial_velocity *
math.sin(math.radians(angle_of_launch)) + math.sqrt(exponent + 2 *
initial_height * g))/g, 2)

answer = tk.Label(root, fg="white", text = 'Your time of flight is


'+ str(time_of_flight) + ' seconds.',font = ("times new
roman",12,"bold", "italic"), bg='#002e39')

10
answer.place(x=550,y=100)

distance = abs( round(horizontal * time_of_flight, 2) )

secondanswer = tk.Label(root, fg="white", text = 'Your distance


traveled is ' + str(distance) + ' meters.',font = ("times new
roman",12,"bold", "italic"), bg='#002e39')

secondanswer.place(x=550,y=185)

thirdanswer = tk.Label(root, fg="white", text = 'Your maximum


height is ' + str(maximum_height) + ' meters.',font = ("times new
roman",12,"bold", "italic"), bg='#002e39')

thirdanswer.place(x=550,y=270)

#reset the entries

def Reset():

x.set("")

y.set("")

z.set("")

return

x = tk.DoubleVar()

y = tk.DoubleVar()

z = tk.DoubleVar()

#input entries

11
initial_velocity_entry = tk.Entry(root, borderwidth = 3, textvariable
= x,)

initial_velocity_entry.place(x=290,y=100)

angle_of_launch_entry = tk.Entry(root, borderwidth = 3, textvariable =


y)

angle_of_launch_entry.place(x=290,y=180)

initial_height_entry = tk.Entry(root, borderwidth = 3, textvariable =


z)

initial_height_entry.place(x=290,y=270)

#validation comments

fa_valid=tk.Label(root, text='', bg='#002e39')

fa_valid.place(x=260,y=120)

vi_valid=tk.Label(root, text='', bg='#002e39')

vi_valid.place(x=260,y=210)

h_valid=tk.Label(root, text='', bg='#002e39')

h_valid.place(x=260,y=300)

#buttons

12
calculate_button = tk.Button(root, command = onClick, text =
'CALCULATE!', fg="white", bg='#002e39',font = ("times new
roman",15,"bold", "italic"))

calculate_button.place(x=450,y=400)

reset= tk.Button(root, text="Reset",font = ("times new


roman",16,"bold", "italic") ,command = Reset, fg="white",
bg='#002e39')

reset.place(x=380,y=400)

root.mainloop()

13

You might also like