from visual import *
from random import *
from math import *
from time import *
# This program adds vectors which have a magnitude of 1 and
# a random direction in the x-y plane. This simulates the
# "random walk" behavior that may be demonstrated by molecules
# and radiation.
limits=[100,1000,10000,100000,1000000,10000000]
vec = vector(1.0,0.0,0.0)
for lim in limits:
i=0
t0 = time()
vsum=vector(0.0,0.0,0.0)
while i<lim:
theta=2.0*pi*random()
vsum=vsum+rotate(vec,angle=theta,axis=(0,0,1))
i=i+1
print "# of Vectors = ",lim, "; Time = ",time()-t0, "sec"
print " Mag = ",mag(vsum)
print " Angle = ",atan2(vsum.y,vsum.x)*(180.0/pi)," degrees"
print "Done"