from visual import * import math # scene.autoscale=0 # # this program makes an object and rotates it # this version is like rotator1, but it experiments # with various values of various parameters # pmb, 10/24/02 # # make axes xaxis = cylinder ( pos=(0,0,0), axis=(5,0,0), radius=0.05, color=color.red ) yaxis = cylinder ( pos=(0,0,0), axis=(0,5,0), radius=0.05, color=color.green ) zaxis = cylinder ( pos=(0,0,0), axis=(0,0,5), radius=0.05, color=color.blue ) # label axes xlabel = label ( pos= (5,0,0),text='X',height=10, border=5 ) ylabel = label ( pos= (0,5,0),text='Y',height=10, border=5 ) zlabel = label ( pos= (0,0,5),text='Z',height=10, border=5 ) # # make a box whiteBox = box(pos=(0,0,0), length= 5.0, height=1.0, width=0.1, color=color.white) yellowBox = box(pos=(10,0,0), length= 2.0, height=1.0, width=3.0, color=color.yellow) redBox = box(pos=(0,3,0), length= 2.0, height=1.0, width=3.0, color=color.red) blueBox = box(pos=(0,-5,0), length= 0.5, height=1.0, width=0.3, color=color.blue) # # setup for rotation t = 0.0 dt = 0.05 angPos = 0.0 angVel = 0.0 xAxis = ( 1,0,0 ) yAxis = ( 0,1,0 ) zAxis = ( 0,0,1 ) # # main loop while 1: rate(20) t = t+ dt # find angular velocity angAcc = 2 * 3.14159/100.0 angVel = angVel + angAcc * dt angPos = angPos + angVel * dt # the vpython "rotate" takes CHANGES to omega as argument, not omega whiteBox.rotate( angle= angVel * dt, axis = yAxis ) yellowBox.rotate ( angle = angVel * dt, axis= xAxis ) redBox.rotate ( angle = angVel*dt, axis= zAxis ) # docs say "The transform is a rotation of angle radians, # counterclockwise around the line defined by origin and # origin+axis." blueBox.rotate ( angle = angVel*dt, axis= yAxis, origin = xAxis )