from __future__ import print_function, division from visual import * scene.background = color.white scene.height = scene.width = 600 scene.x = scene.y = 0 # choose clay position 2= top, 3 =left, 4 =full radius position = 3 # wheel m = 0.2 w = frame() bb = [] R = 10 I = 8*m*R**2 for theta in arange(0,2*pi,pi/4): b = sphere(pos=(R*cos(theta), R*sin(theta),0), radius=1.5, color=color.red, frame = w) bb.append(b) for b in bb[:4]: cylinder(pos=(b.pos), axis = (bb[bb.index(b)+4].pos - b.pos), color=(.7,.7,.7), radius = 0.3, frame=w) axle = cylinder(pos=(0,0,-R/4), axis = (0,0,R/2), radius=1, color=(.7,.7,.7), frame=w) clay = sphere(pos=(bb[position].x,20,0), radius=.5, color=(.7,.5,0)) clay.p = vector(0,-10,0) clay.m = 0.1 psc = 0.5 clay.pa = arrow(pos=clay.pos, axis=clay.p*psc, color=color.green, visible = 0) r = (clay.pos - w.pos) clay.L = cross(r, clay.p) print("clay.L = ", clay.L) scene.autoscale = 0 scene.mouse.getclick() clay.pa.visible = 1 # drop clay dt = 0.01 while clay.y > bb[position].y+2+clay.radius: rate(20) clay.pos = clay.pos + (clay.p/clay.m)*dt clay.pa.pos = clay.pos clay.frame = w clay.pa.visible = 0 # all L transferred to wheel # neglect m of clay omega = mag(clay.L)/I print("omega = ", omega) dtheta = omega*dt theta = 0 while 1: rate(50) w.rotate(angle = dtheta, axis = (0,0,1)) theta += dtheta