MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Solve & RotationMatrix

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*)
target="rotation matrix"/.%;

rotation  =


(*solve for the angle and vector*)



On Mon, 14 May 2007 04:49:33 -0500, Mathieu G <ellocomateo at> wrote:

> CKWong.P at 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 VectN.
> Regards,
> Mathieu


DrMajorBob at

  • Prev by Date: Re: v6 time series package
  • Next by Date: How to use the Simpson 1/3 rule to write this program
  • Previous by thread: Re: Solve & RotationMatrix
  • Next by thread: Re: Solve & RotationMatrix