RE: [script] normal vector to xyz rotation?

Date : Mon, 5 Sep 2005 11:21:28 +0100
To : <XSI(at)Softimage.COM>
From : "kim aldis" <kim(at)cg-soup.com>
Subject : RE: [script] normal vector to xyz rotation?
Peter, check out the xsi base archives. Raffael F posted quite a neat solution there.


From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM] On Behalf Of Alan Jones
Sent: 05 September 2005 09:52
To: XSI(at)Softimage.COM
Subject: Re: [script] normal vector to xyz rotation?

Hi 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,

Alan.

On 9/4/05, peterb <peter_b(at)skynet.be> wrote:
probably a lot of people here have tackled this one allready,
I did search in the archive and google, and a lot came up, but it quickly turns complicated, with matrices and all.
just hope there is a simple answer...
 
I would like to place objects on a mesh's points, oriented according to the normal.
getting to the positions is easy enough, finding the normals too.
but going from the normals to an orientation is less so.
note that I do not want to create a cluster per point, and use objtocluster constraint, which is going to give me the result I want.
in the end I want to be doing this with a lot of objects and also particles so making thousands of constraints doesnt seem right if all I'm after is "just a rotation"
 
any hints in where Im going wrong, and wether this is the right approach to the problem?
----------
set sel = selection(0)
set oGeometry = sel.activeprimitive.geometry
set oPoints = oGeometry.Points
 
for each pnt in oPoints
    set ("name" & i)
    oNull.Kinematics.local.parameters("posx").value = pnt.position.x
    oNull.Kinematics.local.parameters("posy").value = pnt.position.y
    oNull.Kinematics.local.parameters("posz").value = pnt.position.z
   
    oNull.Kinematics.global.parameters("rotx").value = pnt.normal.x
    oNull.Kinematics.global.parameters("roty").value = pnt.normal.y
    oNull.Kinematics.global.parameters("rotz").value = pnt.normal.z
next
-------------
now this is obviously no good for the normals/orientations
the normal is a vector, and the rotation are angles, so I cant just replace one with the other right?
 
I tried with radianstodegrees:
    oNull.Kinematics.global.parameters("rotx").value = xsimath.radianstodegrees(pnt.normal.x)
    oNull.Kinematics.global.parameters("roty").value = xsimath.radianstodegrees(pnt.normal.y)
    oNull.Kinematics.global.parameters("rotz").value = xsimath.radianstodegrees(pnt.normal.z)
but that doesnt look right either
 
so looked all over in the scripting reference
and noticed the existence of setfromXYZangles and GetXYZanglesValues.
are these what I need?
--------------------
set sel = selection(0)
set oGeometry = sel.activeprimitive.geometry
set oPoints = oGeometry.Points
for each pnt in oPoints
    set ("name" & i)
    oNull.Kinematics.local.parameters("posx").value = pnt.position.x
    oNull.Kinematics.local.parameters("posy").value = pnt.position.y
    oNull.Kinematics.local.parameters("posz").value = pnt.position.z
 
    set oVector = XSIMath.CreateVector3
        oVector.x = pnt.normal.x
        oVector.y = pnt.normal.y
        oVector.z = pnt.normal.z
 
    set ROT = XSIMath.CreateRotation
    ROT.SetfromXYZAngles oVector
    ROT.GetXYZAnglesValues X, Y, Z
 
    oNull.Kinematics.global.parameters("rotx").value = xsimath.radianstodegrees(X)
    oNull.Kinematics.global.parameters("roty").value = xsimath.radianstodegrees(Y)
    oNull.Kinematics.global.parameters("rotz").value = xsimath.radianstodegrees(Z)
next
----------------------
its different and doesnt look right either?
 
 
 
 


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.