Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- VelocityInitial = 8.9
- function GetHoopHeight(theta, Vi)
- --set initial values
- Vi = Vi or VelocityInitial
- theta = math.rad(theta)
- Viy = Vi*math.sin(theta)
- Vix = Vi*math.cos(theta)
- --figure out how much time it will take the ball to move 4 meters
- airTime = 4/Vix
- --figure out how high the ball will be at this time
- deltaY = Viy*airTime + -4.905*airTime^2 + 1
- --return answer
- return deltaY
- end
- function GetBucketDistance(theta, Vi)
- --set initial values
- Vi = Vi or VelocityInitial
- theta = math.rad(theta)
- Viy = Vi*math.sin(theta)
- Vix = Vi*math.cos(theta)
- --use the quadratic formula to figure out the function zeros for time in air
- quad1 = (-Viy + math.sqrt(Viy^2 + 19.62))/-9.81
- quad2 = (-Viy - math.sqrt(Viy^2 + 19.62))/-9.81
- --discern which zero is relevant (only one is positive, that's the one required)
- airTime = math.max(quad1, quad2)
- --figure out how far the ball will go before hitting the ground
- deltaX = Vix*airTime
- --return answer
- return deltaX
- end
- hoop = GetHoopHeight(tArgs[1], tArgs[2])
- bucket = GetBucketDistance(tArgs[1], tArgs[2])
- print("Hoop Height: " .. hoop)
- print("Bucket Distance: " .. bucket)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement