WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 04-21-2008, 07:27 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You will need to use some 3D math to determine the orientation of the triangle. Here is some code that will return the transormation matrix of a triangle, given 3 points:
Code:
import viz
viz.go()


P1 = [-1,1,2]
P2 = [-0.1,2,2.5]
P3 = [1,0.1,2.3]


def GetTriangleMatrix(p1,p2,p3):
	
	#Get vector of p1 to p2
	v1 = viz.Vector(p2) - viz.Vector(p1)
	
	#Get vector of p1 to p3
	v2 = viz.Vector(p3) - viz.Vector(p1)
	
	#Take cross product to determine normal of triangle
	normal = v2 ^ v1
	
	#Determine rotation by rotating forward vector to normal
	m = viz.Matrix()
	m.makeVecRotVec([0,0,1],normal)
	
	#Set position of matrix to center of triangle
	p = viz.Vector(p1) + viz.Vector(p2) + viz.Vector(p3)
	m.setPosition( p / 3.0 )
	
	#Return the transformation matrix
	return m
	
	
#Draw triangle
viz.startlayer(viz.TRIANGLES)
viz.vertexcolor(viz.RED)
viz.vertex(P1)
viz.vertex(P2)
viz.vertex(P3)
viz.endlayer()

#Get matrix of triangle
m = GetTriangleMatrix(P1,P2,P3)

#Create arrow to show triangle rotation/translation
arrow = viz.add('marker.wrl')
arrow.setMatrix(m)

#Setup pivot camera
import vizcam
vizcam.PivotNavigate(center=m.getPosition(),distance=10)

#Add ground
viz.add('tut_ground.wrl')
Reply With Quote
 


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 Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Could not find plugin to load objects... halley Vizard 1 05-30-2006 11:01 AM
putting objects on the screen jargon Vizard 7 05-24-2005 11:31 AM
Changing the Color of On-the-Fly Objects vjosh Vizard 1 01-04-2005 11:48 PM
limits on number of objects benelux Vizard 3 07-22-2004 01:26 PM
3D sound & child objects FlyingWren Vizard 1 09-19-2003 12:13 PM


All times are GMT -7. The time now is 08:41 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC