## [Algorithms] Direction+Up vector to Axis/angle

 [Algorithms] Direction+Up vector to Axis/angle From: Max Gilead - 2000-11-19 13:07:57 ```Hello! Question: how to convert direction and up vectors to axis/angle rotation? ------------------------------------------------------------------------- Similar subject has been discussed recently in 'vector+angle' thread but without any real answer. In my solution I tried to duplicate Mesa3D sources but I must have done something wrong... Can you explain me what should I do? Or maybe someone could take a look at my code (I use Point3d class for both vertices and vectors). My camera is based on OpenGL scheme and is specified by: position, axis/angle rotation, fov, near/far clipping planes. public void lookAt(Point3d eye, Point3d target, Point3d up) { setPosition(eye); // updates camera position // this is based on Mesa3D's glu.c lookAt(...) method Point3d z = eye.sub(target).normalize(); Point3d y = up; Point3d x = y.cross(z); y = z.cross(x).normalize(); x.normalize(); // converting to Axis/Angle Matrix3d m = new Matrix3d(x.x, x.y, x.z, y.x, y.y, y.z, z.x, z.y, z.z); rotation = new AxisAngled(m).normalize(); } and from class AxisAngled: public void set(Matrix3d matrix) { // x, y and z must be computed prior to computing angle // (because of axisLength() which needs them) x = matrix.e8 - matrix.e6; y = matrix.e3 - matrix.e7; z = matrix.e4 - matrix.e2; a = Math.atan2(axisLength() / 2.0, (matrix.e1 + matrix.e5 + matrix.e9 - 1.0) / 2.0); } Any suggestions / fixes? Can this be done simpler (without intermediate matrix stage)? Do you have *any* working code that converts vectors to axis/angle? Help! Bye, Max -- ----------------------------------------------- Max Gilead gilead@... XMage library http://xmage.sourceforge.net ----------------------------------------------- -- Sex on TV is bad. You might fall off... ```

 [Algorithms] Direction+Up vector to Axis/angle From: Max Gilead - 2000-11-19 13:07:57 ```Hello! Question: how to convert direction and up vectors to axis/angle rotation? ------------------------------------------------------------------------- Similar subject has been discussed recently in 'vector+angle' thread but without any real answer. In my solution I tried to duplicate Mesa3D sources but I must have done something wrong... Can you explain me what should I do? Or maybe someone could take a look at my code (I use Point3d class for both vertices and vectors). My camera is based on OpenGL scheme and is specified by: position, axis/angle rotation, fov, near/far clipping planes. public void lookAt(Point3d eye, Point3d target, Point3d up) { setPosition(eye); // updates camera position // this is based on Mesa3D's glu.c lookAt(...) method Point3d z = eye.sub(target).normalize(); Point3d y = up; Point3d x = y.cross(z); y = z.cross(x).normalize(); x.normalize(); // converting to Axis/Angle Matrix3d m = new Matrix3d(x.x, x.y, x.z, y.x, y.y, y.z, z.x, z.y, z.z); rotation = new AxisAngled(m).normalize(); } and from class AxisAngled: public void set(Matrix3d matrix) { // x, y and z must be computed prior to computing angle // (because of axisLength() which needs them) x = matrix.e8 - matrix.e6; y = matrix.e3 - matrix.e7; z = matrix.e4 - matrix.e2; a = Math.atan2(axisLength() / 2.0, (matrix.e1 + matrix.e5 + matrix.e9 - 1.0) / 2.0); } Any suggestions / fixes? Can this be done simpler (without intermediate matrix stage)? Do you have *any* working code that converts vectors to axis/angle? Help! Bye, Max -- ----------------------------------------------- Max Gilead gilead@... XMage library http://xmage.sourceforge.net ----------------------------------------------- -- Sex on TV is bad. You might fall off... ```
 Re: [Algorithms] Direction+Up vector to Axis/angle From: Joe Ante - 2000-11-19 14:26:35 ```> Hello! > > Question: how to convert direction and up vectors to axis/angle > rotation? http://www.magic-software.com/Source/MgcCore3D/MgcMatrix3.cpp bye joe ```
 Re: [Algorithms] Direction+Up vector to Axis/angle From: Max Gilead - 2000-11-21 23:48:46 ```Joe Ante wrote: > > Hello! > > > > Question: how to convert direction and up vectors to axis/angle > > rotation? > http://www.magic-software.com/Source/MgcCore3D/MgcMatrix3.cpp Excuse me maybe stupid question but what should I use from this class? It doesn't seem to deal with Axis/Angles except for set/get methods. My conversion method (matrix -> a&a) I have included seems to work OK. Today I spent another 5 hours trying to figure out how to convert this... damn direction/up vector to axis/angle. Help!! Maybe some code sample? I'm stuck. Thanks Max -- ----------------------------------------------- Max Gilead gilead@... XMage library http://xmage.sourceforge.net ----------------------------------------------- -- Sex on TV is bad. You might fall off... ```
 Re: [Algorithms] Direction+Up vector to Axis/angle From: Jeff Lander - 2000-11-22 06:45:19 ```You can convert a direction and up vector into a matrix very easily. In fact they already are two thirds of the rotation matrix. Recall that the columns of a rotation matrix define the local X,Y,and Z axes of the local frame. With the up and direction you have Y and Z. Take the cross product of those two to get X. Then use Mr. Eberly's matrix->a&a code to get your result. (Of course I am assuming a Y-up world, but you get the idea) Of course if you factor in the cross product into the matrix->a&a code you could probably optimize the whole thing a bit to give you an even more speedy routine, but that's up to you. -Jeff At 12:44 AM 11/22/2000 +0100, you wrote: >Joe Ante wrote: > > > > Hello! > > > > > > Question: how to convert direction and up vectors to axis/angle > > > rotation? > > http://www.magic-software.com/Source/MgcCore3D/MgcMatrix3.cpp > >Excuse me maybe stupid question but what should I use from this class? >It doesn't seem to deal with Axis/Angles except for set/get methods. My >conversion method (matrix -> a&a) I have included seems to work OK. > >Today I spent another 5 hours trying to figure out how to convert >this... damn direction/up vector to axis/angle. Help!! Maybe some code >sample? I'm stuck. > >Thanks >Max > > > >-- >----------------------------------------------- >Max Gilead gilead@... >XMage library http://xmage.sourceforge.net >----------------------------------------------- >-- Sex on TV is bad. You might fall off... > > > >_______________________________________________ >GDAlgorithms-list mailing list >GDAlgorithms-list@... >http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list ============================================ Darwin 3D http://www.darwin3d.com Game Technology Seminars http://www.techsem.com ```
 Re: [Algorithms] Direction+Up vector to Axis/angle From: - 2000-11-22 06:58:40 ```Max Gilead wrote: >Joe Ante wrote: > >> > Hello! >> > >> > Question: how to convert direction and up vectors to axis/angle >> > rotation? >> http://www.magic-software.com/Source/MgcCore3D/MgcMatrix3.cpp > >Excuse me maybe stupid question but what should I use from this class? >It doesn't seem to deal with Axis/Angles except for set/get methods. My >conversion method (matrix -> a&a) I have included seems to work OK. > If you indeed have matrix-> axis angle, then your problem is essentially solved, because direction and up vector give you directly two rows (or columns, depending on your matrix convention) of the rotation matrix, the third row (or column) being their cross product. The fact that direction and up vector give you two rows of the matrix is an instance of what is THE most important defining property of transformation matrices, which you would learn in any decent course in linear algebra. BTW, the derivation of matrix -> axis angle is a bit more complicated--it is essentially an eigenvalue problem, from a little more advanced part of the linear algebra course. >Today I spent another 5 hours trying to figure out how to convert >this... damn direction/up vector to axis/angle. Help!! Maybe some code >sample? I'm stuck. > >Thanks >Max ```