Last active
August 29, 2015 14:02
-
-
Save mashcom/aca98d37ec119108535c to your computer and use it in GitHub Desktop.
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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