Re: Solve & RotationMatrix

*To*: mathgroup at smc.vnet.net*Subject*: [mg76165] Re: Solve & RotationMatrix*From*: Mathieu G <ellocomateo at free.fr>*Date*: Thu, 17 May 2007 05:56:07 -0400 (EDT)*References*: <f21g0q$7d6$1@smc.vnet.net> <f23qq6$oa3$1@smc.vnet.net> <31173113.1179139106764.JavaMail.root@m35> <f2ei6m$spd$1@smc.vnet.net>

DrMajorBob a =E9crit : > Here's a much simpler (and probably more robust) solver, using the fact= > > that the eigenvalues of a rotation matrix are > > {1, Cos[theta] + I Sin[theta], Cos[theta] - I Sin[theta]} > > Add those, subtract 1, divide by 2, and take ArcCos to get theta. > > As before, the real eigenvector is the axis of rotation. > > (* code *) > Clear[realQ, realSelect, randomRotationMatrix, angleVector] > realQ[z_?NumericQ] := Re[z] == z > realQ[v_?VectorQ] := VectorQ[v, realQ] > realQ[v_?MatrixQ] := MatrixQ[v, realQ] > realSelect[m_?MatrixQ] := First@Select[m, realQ, 1] > randomRotationMatrix[] := Module[{t, v}, t = RandomReal[{-Pi, Pi}]; > v = Normalize@Table[RandomReal[], {i, 3}]; > {"angle" -> t, "axis" -> v, > "rotation matrix" -> RotationMatrix[t, v]}] > angleVector[target_?MatrixQ] /; realQ[target] := > Module[{values, vectors}, > {values, vectors} = Eigensystem[target]; > {"angle" -> ArcCos[(Plus @@ values - 1)/2], > "axis" -> realSelect@vectors} > ] > > (*create a test problem*) > randomRotationMatrix[]//TableForm > target="rotation matrix"/.%; > > angle->2.25948 > axis->{0.152625,0.442375,0.883747} > rotation = > > matrix->{{-0.597426,-0.571897,0.562152},{0.792751,-0.315459,0.521567},{= -0.120946,0.757244,0.641836}} > > (*solve for the angle and vector*) > angleVector[target] > > {angle->2.25948,axis->{0.152625,0.442375,0.883747}} > > Bobby > > On Mon, 14 May 2007 04:49:33 -0500, Mathieu G <ellocomateo at free.fr> wro= te: > >> CKWong.P at gmail.com a =E9crit : >>> Obviously, you need to provide the function RotationMatrix[ angle, >>> axisVector ] for the algorithm to work. >>> >>> On the other hand, matrices for rotations about the Cartesian axes, >>> i.e., RotX,RotY, & RotZ, can be written done directly. Why not do so= ? >>> >>> >> Hi, >> Thank you for your reply. >> I am not interested in a simple rotation matrix around an axis, but in >> finding the angles corresponding to a 3D rotation matrix. >> I compute VectN which is the vector normal to my surface, and I am >> interested in getting the rotation parameters that bring VectY to Vect= N. >> Regards, >> Mathieu >> >> > > > Thank you I will be working with that in the next few hours!