from __future__ import division
from visual import *
from physutil import *
from visual.graph import *

#Window setup
scene.center = (0,0,0)
scene.range = 5

#Objects
block = box(pos=(0,0,0), length=5, width=1, height=1, color=color.green,make_trail=True)
ball = sphere(pos=vector(-0.5,-10,0), radius=0.15, color=color.red,make_trail=True)

#Parameters and Initial Conditions
mball = 1
mblock = 100
mtot = mball + mblock

vball = vector(0,1000,0)

pball = mball*vball
ptot = pball

Lball = cross(ball.pos,vball)
Ltot = Lball

#Time and time step
t = 0
tf = 1000
dt = 0.00001

#Graph

#Calculation Loop
while t<tf:
	rate(500)

	if ball.pos.y<-0.5 or abs(ball.pos.x)>2.5 or abs(ball.pos.z)>0.5:

		ball.pos = ball.pos + (pball/mball)*dt

	else:

		ball.pos = ball.pos + (ptot/mball)*dt

		Iball = 1
		Iblock = 50
		Itot = Iball + Iblock

		block.rotate(angle=(mag(Ltot)/Itot)*dt,axis=Ltot/mag(Ltot),origin=block.pos)

	t = t + dt