Skip to content

Instantly share code, notes, and snippets.

@mashcom mashcom/
Last active Aug 29, 2015

What would you like to do?
this is beginners demo of how to calculate trajectory using python. this code is not validated and there are no exception catching mechanisms, it for learning purposes
# calculate trajetory
# @author: Mashoko Blessing
# @
# @mashcom digimedia
from math import sin,cos,pi
def calculateTraf(angle, velocity ):
#defining gravity
gravity = float(9.8)
#converting angle to radians
angle =angle * pi / 180
#calculating horizontal and vertical components of the velocity
velocity_h= velocity*cos(angle)
velocity_v = velocity*sin(angle)
#computing time and distance of flight
time_of_flight =2 * float(velocity_v) / gravity
range = float(time_of_flight) * velocity_h
return range, time_of_flight
print("Welcome,this app is not validated to work properly, its for demostration purposes Blessing Mashoko available at\n\n")
print("please enter the angle you are dealing with")
angle =input()
print("enter the velocity")
velocity = input()
ans_range, ans_tof = calculateTraf(float(angle),float(velocity))
print("the range is %.1f metres and time of flight is %.0f seconds" % (ans_range,ans_tof));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.