Re: [script] normal vector to xyz rotation?

Date : Mon, 5 Sep 2005 17:05:18 +0100
To : XSI(at)Softimage.COM
From : Alan Jones <skyphyr(at)gmail.com>
Subject : Re: [script] normal vector to xyz rotation?
Hi Peter,

Glad you got it sorted - microsoft's acos solution truly is elegant ;-) A google seems to provide strange results - some places mention a math object in VBScript though doesn't seem to work for me.

If your other solution is working then I'd go with that - at least until you shift languages

Cheers,

Alan.



On 9/5/05, peterb <peter_b(at)skynet.be> wrote:
 
Hi Alan, seems like your answer was on right on the spot.
 
but on kims suggestion I found back the thread on xsibase:
 
I got it working with Rafaelle's method, that doesnt involve dot product, nor inverse cosine.
just cross product, normalize and putting it into a matrix that goes straight to an object's transform.
 
on the bottom of the page there is a method by Andrea, that is pretty much exactly what you suggested.
this uses the inverse cosine of the dot product and so on:
...
var angle = Math.acos(upVec.dot(polyNormal)); 
...
 
cant find one in vbscript though.
 
what I did come up with is
where inverse cosine is made up like this:
Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
 
microsoft helps to keep things simple :-)
if anyone knows of an inverse cosine function in vbscript, I'd love to know.
 
 
peter
 
 
Excuse my laziness I didn't real through all your code so I've no idea how you're tackling this, but here's a simple approach I'd recommend anyway (I'll explain the math rather than coding it out.)

Take the direction you want to be "up" on your object (probably the y axis I guess so 0,1,0). Get the cross product of that with the normal you want it to rotate to. The result is the axis you want to rotate your object around. To get the angle you want to rotate your object get the dot product of the up axis and the normal. Then get the inverse cosine of this and that will be the angle in radians you want to rotate it. The only problem you'll probably come into this way is defining how it rotates around the normal. You may want to look at doing this with a direction vector which could be global or using the U and V directions or whatever.

Cheers,



Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.