Re: Fw: [script] normal vector to xyz rotation?

Date : Mon, 5 Sep 2005 19:56:00 +0100
To : XSI(at)Softimage.COM
From : Alan Jones <skyphyr(at)gmail.com>
Subject : Re: Fw: [script] normal vector to xyz rotation?
That would be correct (cos always returns a value between -1 and 1) - if you've got a dot product greater than that your vectors weren't unit vectors (normalized).

Hope this helps.

Cheers,

Alan.

On 9/5/05, peterb <peter_b(at)skynet.be> wrote:

>hm I m not gonna switch languages because of a math function now?
>thats like deciding to switch to japanese because you feel there's some characters missing in our alphabet. (yeah its a flawed comparison)
>
>now I did work it out with the acos, and I ll be needing this,
>since I wanna do this on particles, and they dont have a transform matrix.
>
>btw it ran MUCH faster that way, but there can be some other things that are influencing it.
>right now I have one version, with the matrix method, to place nulls on points,
>and another version using the arccos method, to place particles on points, the second being more performant.
>
>however, it seems that the formula is flawed, I get 'division by zero' errors.
>and its quite obvious: if X=1 then (x*x + 1) gives zero.
>Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
 
apparently the arccos function only accepts numbers between -1 and 1 at the input...
 
 
>
>I'll have to try and find a better arccos formula somewhere..
 
,

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.