whj
10-13-2009, 12:27 PM
Hi, I would like to create an environment in which a ball is going around the original point. My simple code just create an animation path of a circle for a ball and try to figure out the actual positions when the ball pass along the animation path. My question is why the printed positions are not on a circle like what we can see? And so why the distance between the ball and the original point are not the constant value 10? Thanks!
import viz
viz.go()
import math
viz.add('tut_ground.wrl')
ball = viz.add('ball.wrl')
viz.MainView.move([0,3,-20])
path = viz.addAnimationPath()
positions = [ [0,1,10], [10,1,0], [0,1,-10], [-10,1,0], [0,1,10] ]
for x in range(len(positions)):
cp = viz.add(viz.CONTROL_POINT)
cp.setPosition(positions[x])
path.add(cp,x+1)
path.loop(viz.CIRCULAR)
viz.CUBIC_BEZIER
path.translatemode(viz.BEZIER)
path.computetangents()
path.setAutoRotate(viz.ON)
mylink = viz.link(path,ball)
path.play()
def mytimer(num):
pc = ball.getPosition()
print 'position: ', pc
dist = math.sqrt( (pc[0]-0.0)*(pc[0]-0.0) + (pc[2]-0.0)*(pc[2]-0.0) )
print 'distance: ', dist
viz.callback(viz.TIMER_EVENT, mytimer)
viz.starttimer(0,1/60.0,viz.FOREVER)
import viz
viz.go()
import math
viz.add('tut_ground.wrl')
ball = viz.add('ball.wrl')
viz.MainView.move([0,3,-20])
path = viz.addAnimationPath()
positions = [ [0,1,10], [10,1,0], [0,1,-10], [-10,1,0], [0,1,10] ]
for x in range(len(positions)):
cp = viz.add(viz.CONTROL_POINT)
cp.setPosition(positions[x])
path.add(cp,x+1)
path.loop(viz.CIRCULAR)
viz.CUBIC_BEZIER
path.translatemode(viz.BEZIER)
path.computetangents()
path.setAutoRotate(viz.ON)
mylink = viz.link(path,ball)
path.play()
def mytimer(num):
pc = ball.getPosition()
print 'position: ', pc
dist = math.sqrt( (pc[0]-0.0)*(pc[0]-0.0) + (pc[2]-0.0)*(pc[2]-0.0) )
print 'distance: ', dist
viz.callback(viz.TIMER_EVENT, mytimer)
viz.starttimer(0,1/60.0,viz.FOREVER)