home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e032 / 3.ddi / FILES / GEOMETRY.PAK / ROTATION.M < prev   
Encoding:
Text File  |  1992-07-29  |  1.9 KB  |  83 lines

  1.  
  2. (* :Title: Rotations *)
  3.  
  4. (* :Author: S. Wolfram *)
  5.  
  6. (* :Summary: Rotations in 2 and 3 dimensions *)
  7.  
  8. (* :Context: Geometry`Rotations` *)
  9.  
  10. (* :Package Version: 1.1 *)
  11.  
  12. (* :Copyright: Copyright 1987,1990 Wolfram Research,Inc. *)
  13.  
  14. (* :History: *)
  15.  
  16. (* :Keywords: *)
  17.  
  18. (* :Source: *)
  19.  
  20. (* :Warning: *)
  21.  
  22. (* :Mathematica Version: 2.0 *)
  23.  
  24. (* :Limitation: *)
  25.  
  26. (* :Discussion: *)
  27.  
  28. BeginPackage["Geometry`Rotations`"]
  29.  
  30. (** Two dimensions **)
  31.  
  32. RotationMatrix2D::usage = 
  33.     "RotationMatrix2D[theta] gives the matrix for rotation by angle theta 
  34.     in two dimensions."
  35.  
  36. Rotate2D::usage =
  37.         "Rotate2D[vec,theta,(pt:{0,0})] rotates the vector vec by angle
  38.         theta about point pt."
  39.  
  40. (** Three dimensions **)
  41.  
  42. RotationMatrix3D::usage =
  43.         "RotationMatrix3D[phi,theta,psi] gives the matrix for rotation by the
  44.         specified Euler angles in three dimensions."
  45.  
  46. Rotate3D::usage =
  47.         "Rotate3D[vec,phi,theta,psi,(pt:{0,0,0})] rotates the vector vec
  48.         by specified Euler angles about point pt."
  49.  
  50. Begin["`private`"]
  51.  
  52. RotationMatrix2D[theta_] :=
  53.     {{Cos[theta], Sin[theta]}, {-Sin[theta], Cos[theta]}}
  54.  
  55. Rotate2D[vec:{_,_}, theta_] :=
  56.     RotationMatrix2D[theta] . vec
  57.  
  58. Rotate2D[vec:{_,_}, theta_, pt:{_,_}] :=
  59.     pt + RotationMatrix2D[theta] . (vec - pt)
  60.  
  61. RotationMatrix3D[phi_,theta_,psi_] := 
  62.     { { Cos[psi] Cos[phi] - Cos[theta] Sin[phi] Sin[psi],
  63.         Cos[psi] Sin[phi] + Cos[theta] Cos[phi] Sin[psi],
  64.         Sin[psi] Sin[theta] } , 
  65.       { -Sin[psi] Cos[phi] - Cos[theta] Sin[phi] Cos[psi],
  66.         -Sin[psi] Sin[phi] + Cos[theta] Cos[phi] Cos[psi],
  67.         Cos[psi] Sin[theta] } ,
  68.       { Sin[theta] Sin[phi],
  69.         -Sin[theta] Cos[phi],
  70.         Cos[theta] } }
  71.  
  72. Rotate3D[vec:{_,_,_}, theta_, phi_, psi_] :=
  73.     RotationMatrix3D[theta,phi,psi] . vec
  74.  
  75. Rotate3D[vec:{_,_,_}, theta_, phi_, psi_, pt:{_,_,_}] :=
  76.     pt + RotationMatrix3D[theta,phi,psi] . (vec - pt)
  77.  
  78. End[]
  79.  
  80. EndPackage[ ]
  81.  
  82. Null
  83.