WorldViz User Forum How to calculate a distance between a moving Avatar and the viewpoint?
 Register FAQ Search Today's Posts Mark Forums Read

#1
04-25-2017, 08:27 AM
 JohnSenior Member Join Date: Apr 2017 Posts: 4
How to calculate a distance between a moving Avatar and the viewpoint?

Dear smart Forum member,

I need to calculate the distance between the position of Avatars, moving from waypoint to waypoint, and the position of the user. At the end of each trial, the minimum distance between viewpoint of the user and avatar at any given time point of the trial should be printed out. I got this far in regard of calculating the distance towards a stable object (at 0.4, 1.8, 0; in this case):
-------------------------
# Globals
pos = []
minDist = 10000
posModel = [0.4,1.8,0]

#euklidische Distanz
def dist(posModel):
global minDist
pos = viz.MainView.getPosition()
dist = [(a - b)**2 for a, b in zip(pos, posModel)]
dist = math.sqrt(sum(dist))
if dist < minDist:
minDist = dist
print minDist
print dist

vizact.ontimer(0.1,dist, posModel)

def quit():
global minDist
print minDist
viz.quit()

vizact.onkeydown('q',quit)

------------------------
My problem: How do I get the position of Avatars, while they are moving from waypoint to waypoint? Is there a way to get the Position of moving avatars similar to "viz.MainView.getPosition()" for the Position of the user?

Best,
John
#2
04-25-2017, 11:56 PM
 Jeff WorldViz Team Member Join Date: Aug 2008 Posts: 2,471
You can use the getPosition command with any node3D object. This returns the position of the object's center point which is defined in the modeling software. In the case of the avatar, this center point is at the avatar's feet level. To get the distance between points use the vizmat.Distance command. If you're checking the distance between an avatar and the viewpoint you'll want to take into account the different height values of each. The following code prints out the distance between avatars and an avatar and the viewpoint:

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

walk1 = vizact.walkTo([5,0,15])
walk2 = vizact.walkTo([-5,0,15])

def printDistances():
avatar1_pos = avatar1.getPosition()
avatar2_pos = avatar2.getPosition()
x,y,z = viz.MainView.getPosition()
print "Distance between avatars", vizmat.Distance(avatar1_pos,avatar2_pos)
# zero viewpoint height and check distance to avatar
print "Distance between view and avatar1", vizmat.Distance([x,0,z],avatar1_pos)

vizact.ontimer(1,printDistances)```
#3
04-28-2017, 06:57 AM
 JohnSenior Member Join Date: Apr 2017 Posts: 4
Thank you so much!

 Thread Tools Display Modes Rate This Thread Hybrid 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 Getting Vizard Help with AI Announcements Vizard Precision Position Tracker (PPT) Plug-in development

All times are GMT -7. The time now is 03:19 AM.