Advertisement
CaptainSpaceCat

Physics Homework MKII

Oct 10th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. local tArgs = {...}
  2. VelocityInitial = 8.9
  3.  
  4. function GetHoopHeight(theta, Vi)
  5.  
  6.     --set initial values
  7.     Vi = Vi or VelocityInitial
  8.     theta = math.rad(theta)
  9.     Viy = Vi*math.sin(theta)
  10.     Vix = Vi*math.cos(theta)
  11.  
  12.     --figure out how much time it will take the ball to move 4 meters
  13.     airTime = 4/Vix
  14.  
  15.     --figure out how high the ball will be at this time
  16.     deltaY = Viy*airTime + -4.905*airTime^2 + 1
  17.  
  18.     --return answer
  19.     return deltaY
  20. end
  21.  
  22. function GetBucketDistance(theta, Vi)
  23.  
  24.     --set initial values
  25.     Vi = Vi or VelocityInitial
  26.     theta = math.rad(theta)
  27.     Viy = Vi*math.sin(theta)
  28.     Vix = Vi*math.cos(theta)
  29.  
  30.     --use the quadratic formula to figure out the function zeros for time in air
  31.     quad1 = (-Viy + math.sqrt(Viy^2 + 19.62))/-9.81
  32.     quad2 = (-Viy - math.sqrt(Viy^2 + 19.62))/-9.81
  33.  
  34.     --discern which zero is relevant (only one is positive, that's the one required)
  35.     airTime = math.max(quad1, quad2)
  36.  
  37.     --figure out how far the ball will go before hitting the ground
  38.     deltaX = Vix*airTime
  39.  
  40.     --return answer
  41.     return deltaX
  42. end
  43.  
  44. hoop = GetHoopHeight(tArgs[1], tArgs[2])
  45. bucket = GetBucketDistance(tArgs[1], tArgs[2])
  46. print("Hoop Height: " .. hoop)
  47. print("Bucket Distance: " .. bucket)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement