(* :Title: Rotations *)

(* :Author: Stephen Wolfram *)

(* :Summary:
This package provides functions for rotating points
in 2 and 3 dimensions.
*)

(* :Context: Geometry`Rotations` *)

(* :Package Version: 1.1 *)

(* :Copyright: Copyright 1987-1999, Wolfram Research,Inc. *)

(* :History: *)

(* :Keywords: *)

(* :Source: *)

(* :Warning: *)

(* :Mathematica Version: 2.0 *)

(* :Limitation: *)

(* :Discussion: *)

BeginPackage["Geometry`Rotations`"]

(** Two dimensions **)

RotationMatrix2D::usage = 
"RotationMatrix2D[theta] gives the matrix for rotation by angle
theta in two dimensions."

Rotate2D::usage =
"Rotate2D[vec,theta,(pt:{0,0})] rotates the vector vec by angle
theta about point pt."

(** Three dimensions **)
 
RotationMatrix3D::usage =
"RotationMatrix3D[psi,theta,phi] gives the matrix for rotation by
the specified Euler angles in three dimensions."

Rotate3D::usage =
"Rotate3D[vec,psi,theta,phi,(pt:{0,0,0})] rotates the vector vec
by specified Euler angles about point pt."

Begin["`Private`"]

RotationMatrix2D[theta_] :=
	{{Cos[theta], Sin[theta]}, {-Sin[theta], Cos[theta]}}

Rotate2D[vec:{_,_}, theta_] :=
	RotationMatrix2D[theta] . vec

Rotate2D[vec:{_,_}, theta_, pt:{_,_}] :=
	pt + RotationMatrix2D[theta] . (vec - pt)

RotationMatrix3D[phi_,theta_,psi_] := 
	{ { Cos[psi] Cos[phi] - Cos[theta] Sin[phi] Sin[psi],
	    Cos[psi] Sin[phi] + Cos[theta] Cos[phi] Sin[psi],
	    Sin[psi] Sin[theta] } , 
	  { -Sin[psi] Cos[phi] - Cos[theta] Sin[phi] Cos[psi],
	    -Sin[psi] Sin[phi] + Cos[theta] Cos[phi] Cos[psi],
	    Cos[psi] Sin[theta] } ,
	  { Sin[theta] Sin[phi],
	    -Sin[theta] Cos[phi],
	    Cos[theta] } }

Rotate3D[vec:{_,_,_}, theta_, phi_, psi_] :=
	RotationMatrix3D[theta,phi,psi] . vec

Rotate3D[vec:{_,_,_}, theta_, phi_, psi_, pt:{_,_,_}] :=
	pt + RotationMatrix3D[theta,phi,psi] . (vec - pt)

End[]

EndPackage[ ]

Null
