View Single Post
  #20  
Old 09-12-2006, 08:34 PM
pbeeson pbeeson is offline
Member
 
Join Date: Aug 2006
Posts: 31
Here is code that works with the Test.wrl I posted earlier. The view is at an angle to the hallway, so a line straight ahead should intersect the wall which is 4.3 meters away. But, this particular line misses the intersection with the closest wall and intersects another wall in the environment (> 10 meters away).

This shows the different results sometimes returned by viz.phys.intersectLine() and viz.intersect().

Code:
import viz, math

viz.go()

env = viz.add('Test.wrl')
env.collidemesh()
env.disable(viz.DYNAMICS)

start_pos=[10.5, 1.3, -21.43391, 23.975]

view=viz.get(viz.MAIN_VIEWPOINT)
view.translate(start_pos[0], start_pos[1], start_pos[2])
view.rotate(0,1,0,start_pos[3], viz.BODY_ORI,viz.ABSOLUTE)

def dist(x1,y1,x2,y2):
    return math.sqrt(pow(x1-x2,2)+pow(y1-y2,2))

def timerCallback(num): 
    end_pos=[start_pos[0]+100*math.sin(start_pos[3]*math.pi/180),
             start_pos[1],
             start_pos[2]+100*math.cos(start_pos[3]*math.pi/180)]
    inters_obj = viz.phys.intersectLine(start_pos[0:3], end_pos)
    print inters_obj.intersectPoint
    print dist(inters_obj.intersectPoint[0],inters_obj.intersectPoint[2],
               start_pos[0],start_pos[2])
    inters_obj = viz.intersect(start_pos[0:3], end_pos)
    print ''
    print inters_obj.intersectPoint
    print dist(inters_obj.intersectPoint[0],inters_obj.intersectPoint[2],
               start_pos[0],start_pos[2])
    print '\n\n'

    

viz.callback(viz.TIMER_EVENT, timerCallback)
viz.starttimer(1, 1, -1)

Last edited by pbeeson; 09-13-2006 at 07:26 AM.
Reply With Quote