View Single Post
Old 06-02-2004, 02:55 PM   #8 (permalink)
Rene
Senior Member
 
Join Date: Jul 2003
Location: The Netherlands
Posts: 141
Send a message via ICQ to Rene
Default

Your second question took me some time to get right, mostly because of a different result between my calculator and gmax. I don't know if your familiar with matrix and vector calculations however I will use some terms that may not ring a bell. gmax has internal functions for all of these.

To map your point B onto point C using rotations you'll first need the vectors from the rotation origin (point A in this case). You can either calculate them manually or be a bit creative with the coordsys like I did. Now normally I would advise you to normalize these vectors but maxscript gives weird results when calculating with the normalized values. So we'll first calculate and then normalize.

You'll need the cross product between the vectors. This results in an rotation axis. Normalize the result.

Now you need the dot product and devide it by the product of the lenghts of the vectors (same result as calculating with normalized vectors). This gives the cosinus of the angle between the two vectors. Inverse it to get the actual angle.

All that's left now is to rotate the origin (point A) in it's local coordsys.


In maxscript this would make:

Code:
vAB = in coordsys $A.transform $B.pos
vAC = in coordsys $A.transform $C.pos

axis = normalize(cross vAB vAC)
angle = acos ((dot vAB vAC) / ((length vAB) * (length vAC)))

in coordsys local $A.rotation = (angleAxis angle axis)
Rene is offline   Reply With Quote