MathGroup Archive 1993

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

Search the Archive

Re: Rotations.m package bug?

  • To: mathgroup at
  • Subject: Re: Rotations.m package bug?
  • From: Peter Whaite <peta at>
  • Date: Mon, 20 Dec 1993 11:29:59 -0500

 GB> I think something is wrong here:
 GB> Chop[RotationMatrix3D[00 Degree, 0 Degree, 0 Degree] //N]
 GB> {{1., 0, 0}, {0, 1., 0}, {0, 0, 1.}}

 GB> Chop[RotationMatrix3D[90 Degree, 0 Degree, 0 Degree] //N]
 GB> {{0, 1., 0}, {-1., 0, 0}, {0, 0, 1.}}

 GB> Chop[RotationMatrix3D[0 Degree, 90 Degree, 0 Degree] //N]
 GB> {{1., 0, 0}, {0, 0, 1.}, {0, -1., 0}}

 GB> Chop[RotationMatrix3D[0 Degree, 0 Degree, 90 Degree] //N]
 GB> {{0, 1., 0}, {-1., 0, 0}, {0, 0, 1.}}

 GB> Note that the 2nd and 3rd above are the same. The package uses
 GB> Euler angles to specify the rotation (I'm not certain how
 GB> the axes are aligned, but it doesn't really matter). It appears
 GB> to be impossible to get rotation around each of the 3 principle
 GB> axes.

 GB> Am I making a mistake or is something wrong with RotationMatrix3D?

There are a couple of commonly used Euler angle conventions (consult a
graphics text).  If Rx[a], Ry[b], and Rz[c] represent rotations about the x,
y, and z axes of angles a, b, and c respectively then I seem to recall that
the one with Mathematica is something like...

	R[phi,theta,psi] = Rz[phi] . Rx[theta] . Rz[psi]

I wish this was documented in the Mathematica source. It caused me some grief
once too.  Our convention is XYZ Euler angles.  

	R[phi,theta,psi] = Rz[phi] . Ry[theta] . Rx[psi]

Here's what I wrote to do that.

(* We use a different Euler angle convention than is found in
Geometry'Rotation' *)

RotateXYZShape::usage = "RotateXYZShape[graphics3D, ox, oy, oz] rotates
	the three-dimensional graphics object by the specified XYZ Euler

RotateXYZShape[shape_, ox_, oy_, oz_ ] :=
    Block[{rotmat = N[RotationMatrixXYZ[N[ox],N[oy],N[oz]]]},
	shape /. { poly:Polygon[_] :> Map[(rotmat . #)&, poly, {2}],
		   line:Line[_]    :> Map[(rotmat . #)&, line, {2}],
		   point:Point[_]  :> Map[(rotmat . #)&, point,{1}] }

RotationMatrixXYZ[ox_,oy_,oz_] := 
    {{Cos[oy]*Cos[oz], -(Cos[oy]*Sin[oz]), Sin[oy]}, 
     {Cos[oz]*Sin[ox]*Sin[oy] + Cos[ox]*Sin[oz], 
      Cos[ox]*Cos[oz] - Sin[ox]*Sin[oy]*Sin[oz], -(Cos[oy]*Sin[ox])}, 
     {-(Cos[ox]*Cos[oz]*Sin[oy]) + Sin[ox]*Sin[oz], 
      Cos[oz]*Sin[ox] + Cos[ox]*Sin[oy]*Sin[oz], Cos[ox]*Cos[oy]}}

RotateXYZ[vec:{_,_,_}, ox_, oy_, oz_] :=
	RotationMatrixXYZ[ox,oy,oz] . vec

RotateXYZ[vec:{_,_,_}, ox_, oy_, oz_, pt:{_,_,_}] :=
	pt + RotationMatrixXYZ[ox,oy,oz] . (vec - pt)

 GB> Also, there's a discrepency between the order of the Euler angles
 GB> in the definition of RoatationMatrix3D and where its called in
 GB> Rotate3D in the same package (phi,theta,psi  vs  theta,pha,psi).

Yeah I saw that too.  The parameters are passed to Rotate3D in the same order
so its internally consistent.  It should be changed to be consistent with the

Best of luck.

  • Prev by Date: Re: I want to read numbers written in E-format.
  • Next by Date: Re: using mma in a terminal: cursors doesn't work
  • Previous by thread: Rotations.m package bug?
  • Next by thread: Hermite Differential Equation