WorldViz User Forum positions on animation path
 User Name Remember Me? Password
 Register FAQ Search Today's Posts Mark Forums Read

 Thread Tools Rating: Display Modes
#1
10-13-2009, 12:27 PM
 whj Member Join Date: Apr 2008 Posts: 60
positions on animation path

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!

Code:
```import viz
viz.go()

import math

viz.MainView.move([0,3,-20])

positions = [ [0,1,10], [10,1,0], [0,1,-10], [-10,1,0], [0,1,10] ]
for x in range(len(positions)):
cp.setPosition(positions[x])

path.loop(viz.CIRCULAR)
viz.CUBIC_BEZIER
path.translatemode(viz.BEZIER)
path.computetangents()
path.setAutoRotate(viz.ON)

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)```
#2
10-16-2009, 12:19 PM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
You won't be able to create a perfect circle using bezier paths. You are better off manually animating the object. Either way, the following modified version of your script will generate a path that is closer to a circle. It uses cubic bezier and you removes the duplicate control point at the end of the path:
Code:
```import viz
import vizmat
import vizact
viz.go()

viz.MainView.move([0,3,-20])

positions = [ [0,1,10], [10,1,0], [0,1,-10], [-10,1,0] ]
for x,pos in enumerate(positions):
cp.setPosition(pos)

path.loop(viz.CIRCULAR)
path.translatemode(viz.CUBIC_BEZIER)
path.computetangents()
path.setAutoRotate(viz.ON)

path.play()

def PrintInfo():
pc = ball.getPosition()
print 'position: ', pc

dist = vizmat.Distance(pc,[0,1,0])
print 'distance: ', dist

vizact.ontimer(0,PrintInfo)```
#3
10-19-2009, 03:13 PM
 whj Member Join Date: Apr 2008 Posts: 60
I'll try that. Thank you.
#4
10-27-2009, 01:21 PM
 whj Member Join Date: Apr 2008 Posts: 60
Hi,

If I happen to create another non-circle path using bezier paths, would the distance we can see/feel in VR is close to the actual distance that calculated by vizmat.Distance().

Thanks!

Quote:
 Originally Posted by farshizzo You won't be able to create a perfect circle using bezier paths. You are better off manually animating the object. Either way, the following modified version of your script will generate a path that is closer to a circle. It uses cubic bezier and you removes the duplicate control point at the end of the path: Code: ```import viz import vizmat import vizact viz.go() 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] ] for x,pos in enumerate(positions): cp = viz.addControlPoint() cp.setPosition(pos) path.add(cp,x+1) path.loop(viz.CIRCULAR) path.translatemode(viz.CUBIC_BEZIER) path.computetangents() path.setAutoRotate(viz.ON) mylink = viz.link(path,ball) path.play() def PrintInfo(): pc = ball.getPosition() print 'position: ', pc dist = vizmat.Distance(pc,[0,1,0]) print 'distance: ', dist vizact.ontimer(0,PrintInfo)```

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements Vizard Precision Position Tracker (PPT) Plug-in development

 Similar Threads Thread Thread Starter Forum Replies Last Post ptjt255 Vizard 1 08-24-2009 11:40 AM Enlil Vizard 3 11-24-2008 04:23 PM whj Vizard 8 11-17-2008 07:41 PM djdesmangles Vizard 2 06-11-2007 03:37 PM djdesmangles Vizard 0 06-06-2007 11:03 AM

All times are GMT -7. The time now is 06:52 PM.

 Contact Us - WorldViz Home - Archive - Top