Created
February 13, 2015 14:12
-
-
Save emwdx/216d907b24746e78491b to your computer and use it in GitHub Desktop.
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
from random import * | |
from math import * | |
g= 9.8 | |
y0 = 1.9 | |
horizontalDistance = 20.0 | |
hoopHeight = 3.05 | |
startingV = 10 | |
startingT = 30 | |
class Projectile(): | |
def __init__(self,v0,theta): | |
self.theta = theta | |
self.v0 = v0 | |
self.error = self.getError(v0,theta) | |
def getError(self,v0,theta): | |
arrivalTime = horizontalDistance/(v0*cos(theta*pi/180)) | |
finalHeight = y0 + v0*sin(theta*pi/180)*arrivalTime-0.5*g*arrivalTime*arrivalTime | |
return (finalHeight-hoopHeight) | |
class Projectiles(): | |
def __init__(self,N,startingV,startingT,endingV,endingT): | |
self.N = N | |
self.startingV = startingV | |
self.startingT = startingT | |
self.endingV = endingV | |
self.endingT = endingT | |
self.array = self.generate() | |
self.ordered = self.array.sort(key=lambda x: abs(x.error)) | |
def generate(self): | |
emptyArray = [] | |
for i in range(self.N): | |
emptyArray.append(Projectile(uniform(self.startingV,self.endingV),uniform(self.startingT,self.endingT))) | |
return emptyArray | |
for j in range(15): | |
startingV = 10 | |
startingT = 40 | |
endingV = startingV*2 | |
endingT = startingT*3 | |
error = 10 | |
changeError = 10 | |
while(abs(changeError)>0.0001): | |
a = Projectiles(5000,startingV,startingT,endingV,endingT) | |
startingV = a.array[0].v0 | |
startingT = a.array[0].theta | |
endingT = a.array[20].theta | |
endingV = a.array[20].v0 | |
changeError = error - a.array[0].error | |
error = a.array[0].error | |
#print("error: "+str(a.array[0].error) +", v0: " + str(a.array[0].v0) + ", theta:"+str(a.array[0].theta)) | |
print("Calc.setExpression({id:"+str(j)+",latex:'("+str(a.array[0].v0)+"*cos("+str(a.array[0].theta*pi/180)+")*t,"+str(y0)+"+"+str(a.array[0].v0)+"*sin("+str(a.array[0].theta*pi/180)+")*t-4.9*t^2)'})") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment