# Rotation from a vector

 10 October 2008 Norb Frequenter   ... Technical Artist Electronic Arts Canada Canada Rotation from a vector sigh...it's friday and my brain has stopped functioning...help.. basically I have a normal's vector from the command 'polyInfo -fn' and I have an object facing the positive Z axis with frozen transforms. What I want is to figure out the Y rotation value, so I can match the objects Y rotation with the face normal's Y rotation... I hope that made sense.. share quote
 10 October 2008 sirpalee death from above   portfolio Pal Mezei Software Engineer Luma Pictures Melbourne, Australia To get the best results you need to access, the binormal and the tangent information of the face, and create a rotation matrix like this : | t.x t.y t.z | | n.x n.y n.z | | b.x b.y b.z | t -> tangent vector n -> normal vector b -> binormal vector (I have written a similar constrain node in the c++ api, and I used the method above) share quote
 10 October 2008 Norb Frequenter   ... Technical Artist Electronic Arts Canada Canada In case anyone cares, I did manage to solve this. While the math may or may not be 'correct' I get the angle I'm looking for. I stored the vector data from the face normal as \$v and then used the angleBetween command ignoring the faceNormal's Y vector info (since I could assume the plane will always be flat) `````` angleBetween -er -v1 0 0 1 -v2 \$v1 0 \$v3`````` share quote
 10 October 2008 GennadiyKorol Know-it-Not   portfolio Gennadiy Korol Senior Coffee Maker Animation Lab Israel You are basically measured the angle between the projection of normal on XZ plane, but this will not solve the more complex rotations. I have used the solution proposed by sirpalee on numerous occasions and it never lets you down. You just compose the matrix and be done __________________ Diffusion Curves Wip share quote
 10 October 2008 Norb Frequenter   ... Technical Artist Electronic Arts Canada Canada lol, I wouldn't know what to do with that matrix once I made it :P I'm still wrapping my head around 3D math again as I haven't had to use if for quite some time. share quote
 06 June 2009 vsPiotr The portfolio Piotr Stopniak 3D Artist Toby And Pete Sydney, Australia Gennadiy/Sirpalee, could you elaborate on that in mel format? I'm facing the "more complex rotation"... but have no idea how to use transform matrices. __________________ http://www.tobyandpete.com http://piratorbay.tumblr.com share quote
 06 June 2009 sirpalee death from above   portfolio Pal Mezei Software Engineer Luma Pictures Melbourne, Australia Hi, you should read the corresponding wiki section. http://en.wikipedia.org/wiki/Matrix_(mathematics) http://en.wikipedia.org/wiki/Rotation_matrix http://en.wikipedia.org/wiki/Linear_transformation It's a trivial problem, you should solve it yourself, don't except anyone to tell you how to transform a vector using matrices. You should create a transformation matrix, that I described above, and after that, transform the up vector with that matrix using simple matrix / vector multiplication. Last edited by sirpalee : 06 June 2009 at 06:18 PM. share quote
 06 June 2009 vsPiotr The portfolio Piotr Stopniak 3D Artist Toby And Pete Sydney, Australia Trivial for some You're neglecting the fact that in contrast to most of Eastern Europe, Australian high schools teach basic trigonometry as an optional advanced subject, matrixes don't get mentioned, so my math skills, to the great disappointment of my parents, are piss weak ...besides that, I'm not really a TD. Thanks for the links though, much appreciated. I will study them in more detail. I did manage to get a somewhat working bit of mel using a matrix but I don't quite understand it yet. __________________ http://www.tobyandpete.com http://piratorbay.tumblr.com Last edited by vsPiotr : 06 June 2009 at 10:10 PM. share quote
 06 June 2009 vsPiotr The portfolio Piotr Stopniak 3D Artist Toby And Pete Sydney, Australia Hi, Is this correct? The below code essentially aligns and positions things the way I want them but I'm getting some strange behavior where shear and scale have some small fractional values (like 0.007) I'm can re-set those after xform but it's not that neat. i'm using pointOnSurface (\$infoNode) to get normalized U V and N. it's part of a loop that instances pCube1. `````` float \$p[] = `getAttr (\$infoNode + ".position")`; float \$tu[] = `getAttr (\$infoNode + ".ntu")`; float \$tv[] = `getAttr (\$infoNode + ".ntv")`; float \$no[] = `getAttr (\$infoNode + ".nn")`; string \$inst[] = `instance pCube1`; float \$m[] = { \$tu[0], \$tu[1], \$tu[2], 0, \$no[0], \$no[1], \$no[2], 0, \$tv[0], \$tv[1], \$tv[2], 0, \$p[0], \$p[1], \$p[2], 1}; xform -matrix \$m[0] \$m[1] \$m[2] \$m[3] \$m[4] \$m[5] \$m[6] \$m[7] \$m[8] \$m[9] \$m[10] \$m[11] \$m[12] \$m[13] \$m[14] \$m[15] \$inst[0];`````` __________________ http://www.tobyandpete.com http://piratorbay.tumblr.com share quote
 06 June 2009 ThE_JacO Cultist   portfolio CGConnect Member Raffaele Fragapane Performance Technology Supervisor Animal Logic Sydney, Australia Originally Posted by Norb: lol, I wouldn't know what to do with that matrix once I made it :P I'm still wrapping my head around 3D math again as I haven't had to use if for quite some time. A 3x3 matrix represents rotation + scaling, and it's just three vectors determining the direction (and magnitude for scaling) of the three axis. To get one from a poly face get the normal, get a vector from an edge (adding the vectors of the first and second point of that poly face) and that gives you a reliable upvector, except for very messed up shapes. Once you have those you can run a cross product of your normal by your up-vector, and that will give you a working bi-normal (the second of your axis). Another cross product between that and the normal will give you a third orthogornal axis, the third one. And you're good to go and can populate that matrix. For the second vector it's also an option to project (and normalize, unit in maya) that upvector on the orthogonal plane of the normal, but it's slightly more involved than just running a cross product. If you're not familiar with cross products, I suggest you look them up as part of an elementary study in linear algebra, there's only that far you can go without knowing at least the basics __________________ Come, Join the Cult http://www.cultofrig.com - Rigging from First Principles Last edited by ThE_JacO : 06 June 2009 at 09:36 AM. share quote
 06 June 2009 CGTalk Moderation Expert Thread automatically closed This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum. __________________ CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.