Skip to content

Instantly share code, notes, and snippets.

@mashcom mashcom/trajectory.py
Last active Aug 29, 2015

Embed
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
# @ http://www.facebook.com/blessing.mashcom
# @mashcom digimedia http://www.hookd-up.com
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 http://www.facebook.com/blessing.mashcom\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.