WorldViz User Forum simply overlapping objects
 Register FAQ Search Today's Posts Mark Forums Read

#1
04-20-2008, 09:12 PM
 chris Member Join Date: Apr 2008 Posts: 2
simply overlapping objects

hey guys, this should be relatively easy but I cna't figure it out.

Basically I have a set of arbitrary points and a plane that I need to put within the field of points. The thing is, the user can select 3 points and the plane has to align itself with them.

as a simple solution I thought to draw a triangle (triangle_strip) connecting the points and then take it's rotation/position and apply it to the plane (which at this point has been created, just a bunch of triangle strips).

The thing is, is I can't figure out how to do that. I've been messing around with the orientation and rotation of various things and regardless of what I try nothing works. I've tried getting the objects euler, matrix, quat and axis angle, none of which have worked (and actually all are the same for the two objects, who are in two different initial positions and orientations).

So I'm not sure that I can grab the triangles rotation, as I haven't explicitly applied one to it yet. I was just wondering if I'm on the right track, or if I'm overlooking something extremely obvious.

Any help would be appreciated.
thanks
#2
04-21-2008, 07:27 PM
 farshizzo 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.setMatrix(m)

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

#3
04-27-2008, 04:50 PM
 chris Member Join Date: Apr 2008 Posts: 2
Wow that's exactly what I needed thanks!

I also didn't know about ^, that makes life a bit easier.

However this brings up another issue.

While my actual project is a bit more complex then the example I asked for, the solution transfered to it extremely well. The issue now is I'm applying this transformation matrix to an on the fly object, which in itself works, however the transformation is applied at the objects current center, which geometrically is not its center at all. All attempts at object.center have failed.

I was wondering if there was a simple solution for this one.
#4
04-28-2008, 12:39 PM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
The best solution is to create the triangles so their geometric center corresponds to the origin (0,0,0). Is this not a viable option for you?

 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 Announcements Vizard Precision Position Tracker (PPT) Plug-in development

 Similar Threads Thread Thread Starter Forum Replies Last Post halley Vizard 1 05-30-2006 11:01 AM jargon Vizard 7 05-24-2005 11:31 AM vjosh Vizard 1 01-04-2005 11:48 PM benelux Vizard 3 07-22-2004 01:26 PM FlyingWren Vizard 1 09-19-2003 12:13 PM

All times are GMT -7. The time now is 04:02 PM.