from visual import * from time import clock from random import random from math import * # Stars interacting gravitationally # Program uses Numeric Python arrays for high speed computations win=500 ############################################################ # Set up the values ############################################################ # Gravitation. Only works vertically! g = 9.81 # Latitude at which this is taking place in degrees lat = 24 # Muzzle speed of the projectile in m/s speed = 80 # Angle of elevation of gun above Earth's surface angle = 45 # Angular velocity of the Earth in rad/s omega = 0.05 # Distance of gun from target in metres distance = 600 ############################################################ # Do not edit below this line # ############################################################ # convert angles from degrees to radians angle = (angle/360.)*2*pi lat = (lat/360.)*2*pi velocity = vector(0, speed * sin(angle), -speed * cos(angle)) # Define axis length and some other stuff... L = distance + 50 print """ Right button drag to rotate view. Left button drag up or down to move in or out. """ scene = display(title="Coriolis Force on a projectile", width=win, height=win, range=L, forward=(-1,-1,-1)) xaxis = curve(pos=[(0,0,0), (L,0,0)], color=(1.5,0.5,0.5)) yaxis = curve(pos=[(0,0,0), (0,L,0)], color=(0.5,1.5,0.5)) zaxis = curve(pos=[(0,0,0), (0,0,L)], color=(0.5,0.5,0.5)) # Put in the grass at the bottom mybox = box(pos=(0,0,0), length=distance+100, height=1, width=distance+100, color=color.green) ## target = sphere(pos=(0,0,0), radius=10, color=color.red) ball = sphere(pos=(0,0,distance), radius=10, color=color.blue) ball.trail = curve(pos=[ball.pos], color=color.yellow, radius=1) ball.velocity = velocity t = 0 #dt = 0.01 while 1: rate(200) """ For normal motion use the following: ball.pos = ball.pos + ball.velocity*dt ball.trail.append(pos=ball.pos) ball.velocity = ball.velocity + g*dt ######################################## t = dt ball.pos.x = ball.pos.x + (1/3.) * omega * 9.81 * pow(t,3) * cos(lat) - (omega * ball.velocity.x * pow(t,2) * (cos(lat)-sin(lat)))/sqrt(2) print ball.pos.x ball.pos.y = ball.pos.y + (ball.velocity.y * t)/sqrt(2) - 0.5 * 9.81 * pow(t,2) ball.pos.z = ball.pos.z + (ball.velocity.z * t)/sqrt(2) ball.trail.append(pos=ball.pos) """ t = t + 0.005 ball.pos.x = (1/3.) * omega * g * pow(t,3) * cos(lat) - (omega * speed * pow(t,2) * (cos(lat)-sin(lat)))/sqrt(2) #print ball.pos.x ball.pos.y = (speed * t)/sqrt(2) - 0.5 * g * pow(t,2) ball.pos.z = distance + (-speed * t)/sqrt(2) ball.trail.append(pos=ball.pos) #ball.velocity = ball.velocity + g*dt if (ball.y <= 0): print "Landed at (%f, %f, %f)" % (ball.pos.x, ball.pos.y, ball.pos.z) break