Index: /trunk/doc/pslib/psLibADD.tex
===================================================================
--- /trunk/doc/pslib/psLibADD.tex	(revision 4511)
+++ /trunk/doc/pslib/psLibADD.tex	(revision 4512)
@@ -1,3 +1,3 @@
-%%% $Id: psLibADD.tex,v 1.76 2005-06-10 03:25:46 eugene Exp $
+%%% $Id: psLibADD.tex,v 1.77 2005-07-08 03:55:45 price Exp $
 \documentclass[panstarrs]{panstarrs}
 
@@ -1483,40 +1483,69 @@
 \begin{center}
 \psfig{file=rotations.ps}
-\caption{Definition of the rotation angles\label{rotations}}
+\caption{Definition of the rotation angles\label{rotations}.  Three
+rotations are performed in series: first, a rotation of $\alpha_p$ is
+made about the $z$ axis; second, a rotation of $\delta_p$ (not $90 -
+\delta_p$ as shown) is made about the modified $y$ axis, $y'$;
+finally, a rotation of $\phi_p$ is made about the modified $z$ axis,
+$z''$.  Note that it is the coordinate system that rotates, not the
+position of interest.}
 \end{center}
 \end{figure}
 
-\subsubsection{Quaternion Construction}
-
-The following describes the algorithms needed to implement 3-D
-rotations in terms of quaternions. A quaternion is an ordered set of
-four numbers, $\bar{q} = (q_0, q_1, q_2, q_3)$. A rotation of angle
-$\theta$ about the axis defined by the unit vector $(v_x, v_y, v_z)$
-has quaternion components:
-\begin{eqnarray}
-q_0 & = & v_x sin(\theta/2), \\
-q_1 & = & v_y sin(\theta/2), \\
-q_2 & = & v_z sin(\theta/2), and \\
-q_3 & = & cos(\theta/2). \\
-\end{eqnarray}
-Note that the sine and cosine are taken of the half angle of the
+
+\subsubsection{Quaternions}
+
+A quaternion is an ordered set of four numbers, $q = (q_0, q_1, q_2,
+q_3)$, which is useful for specifying rotations.  A quaternion is made
+up of a three-vector which specifies an axis about which to rotate,
+and a scalar which specifies the amount of rotation.  In the
+following, we call the final value, $q_3$, the scalar value; note that
+other sources (e.g., MathWorld) may choose to call the first value the
+scalar value.
+
+The conjugate of a quaterion, $q = (q_0, q_1, q_2, q_3)$, is $\bar{q}
+= (-q_0, -q_1, -q_2, q3)$.  Note that the vector components are
+negated, but not the scalar component.
+
+\subsubsection{Quaternion for a position}
+
+Given an angular position on the sky, $(\alpha, \delta)$, we can
+construct a quaternion by treating it as a unit vector in cartesian
+space:
+\begin{eqnarray}
+p_0 & = & \cos \delta \cos \alpha \\
+p_1 & = & \cos \delta \sin \alpha \\
+p_2 & = & \sin \delta \\
+\end{eqnarray}
+and we set the scalar value to zero, $p_3 = 0$.
+
+Given a quaternion, $p$, we can calculate the position using the
+inverse of the above equations:
+\begin{eqnarray}
+\phi & = & \atan(p_1, p_0) \\
+\theta & = & \asin(p_2) \\
+\end{eqnarray}
+Note that in this case, we neglect the scalar component of the
+quaternion --- it should be zero.
+
+\subsubsection{Quaternion for a rotation}
+
+A rotation of angle $\theta$ about the axis defined by the unit vector
+$(v_x, v_y, v_z)$ is specified by a quaternion with components:
+\begin{eqnarray}
+r_0 & = & v_x \sin(\theta/2) \\
+r_1 & = & v_y \sin(\theta/2) \\
+r_2 & = & v_z \sin(\theta/2) \\
+r_3 & = & \cos(\theta/2) \\
+\end{eqnarray}
+Note that the sine and cosine are taken of the half-angle of the
 rotation.  Note also that this implies that the quaternion components
-are normalized such that $|\bar{q}| \equiv q_0^2 + q_1^2 + q_2^2 + q_3^2
+are normalized such that $|q| \equiv q_0^2 + q_1^2 + q_2^2 + q_3^2
 = 1$.
 
-The 3-vector representation of the angle of the pole is determined
-from the coordinate of the pole ($\alpha_p, \delta_p$) by:
-\begin{eqnarray}
-v_x & = & \cos \delta_p \cos \alpha_p \\
-v_y & = & \cos \delta_p \sin \alpha_p \\
-v_x & = & \sin \delta_p \\
-\end{eqnarray}
-
-\subsubsection{Combining Two Rotations}
-
-Given two quaternions $\bar{a}$ and $\bar{b}$, there is a third
-quaternion, $\bar{p}$, which represents the result of first applying
-$\bar{a}$, and then $\bar{b}$. The components of $\bar{p}$ are given
-by:
+\subsubsection{Multiplication of quaternions}
+
+Given two quaternions $a$ and $b$, there is a third quaternion, $p =
+ab$.  The components of $p$ are given by:
 
 \begin{eqnarray}
@@ -1527,12 +1556,59 @@
 \end{eqnarray}
 
+Note that quaternion multiplication is associative (whether you do the
+left pair or the right pair first doesn't matter):
+\begin{equation}
+(ab)c = a(bc)
+\end{equation}
+but not commutative (you can't switch the order of the operands):
+\begin{equation}
+abc \ne acb
+\end{equation}
+
 \subsubsection{Rotating a Vector}
 
-You may rotate a unit vector by first constructing a quaternion
-$\bar{b}$, whose first three components are the components of the
-unit vector, and whose fourth component is zero. To rotate this vector
-by a quaternion $\bar{a}$, you apply the formula above for combining
-two quaternions. The rotated vector is found in the first three
-components of the resulting quaternion, $\bar{p}$.
+Rotation of a position is performed by constructing the quaternion for
+the position, $p$, and the rotation, $r$, according to the above
+equations, and calculating the product:
+\begin{equation}
+q = r p \bar{r}
+\end{equation}
+$q$ is the quaternion of the result.  Note the use of the conjugate of
+the rotation quaternion.
+
+A general rotation may be specified by three individual rotations
+about a predefined set of axes.  We choose to specify rotations around
+the $z$, $y$ and $z$ axes, in that order.  The amount of rotation
+around each of these axes are known as Euler angles.  Given the Euler
+angles of a rotation, the rotation may be performed by rotating in
+turn about the designated axes.  Euler angles are specified below for
+the various rotations required.  To use them, the following rotation
+quaternions are used:
+
+\begin{itemize}
+\item First, about the Z axis:
+\begin{eqnarray}
+r_0 & = & 0 \\
+r_1 & = & 0 \\
+r_2 & = & \sin(\alpha_p/2) \\
+r_3 & = & \cos(\alpha_p/2) \\
+\end{eqnarray}
+\item Second, about the Y axis:
+s_0 & = & 0 \\
+s_1 & = & \sin(\delta_p/2) \\
+s_2 & = & 0 \\
+s_3 & = & \cos(\delta_p/2) \\
+\end{eqnarray}
+\item Finally, about the Z axis again:
+\begin{eqnarray}
+t_0 & = & 0 \\
+t_1 & = & 0 \\
+t_2 & = & \sin(\phi_p/2) \\
+t_3 & = & \cos(\phi_p/2) \\
+\end{eqnarray}
+
+These three quaternions may be multiplied together to yield the
+quaternion of the combined rotation: $tsr$ (note the order --- $r$ is
+done first, so it is nearest the position quaternion, etc.).
 
 \subsubsection{Rotation Matrix}
@@ -1653,7 +1729,7 @@
 The appropriate values, from the Hipparcos and Tycho Catalogues are:
 \begin{eqnarray}
-\alpha_p & = & 282.85948^\circ \\
-\delta_p & = & 62.87175^\circ \\
-\phi_p & = & 32.93192^\circ \\
+\alpha_p & = & 180^\circ - 192.85948^\circ \\
+\delta_p & = & 90^\circ - 62.87175^\circ \\
+\phi_p & = & 90^\circ + 32.93192^\circ \\
 \end{eqnarray}
 
@@ -1662,7 +1738,7 @@
 The appropriate values, from Zombeck, are:
 \begin{eqnarray}
-\alpha_p & = & 0^\circ \\
+\alpha_p & = & 270^\circ \\
 \delta_p & = & 23^\circ27'8''.26 - 46''.845\, T - 0''.0059\, T^2 + 0''.00181\, T^3 \\
-\phi_p & = & 0^\circ
+\phi_p & = & 90^\circ
 \end{eqnarray}
 where $T$ is the time in Julian centuries since 1900.
@@ -1673,7 +1749,7 @@
 be rapidly calculated using the following rotation angles:
 \begin{eqnarray}
-\alpha_p & = & 90^\circ - (0^\circ.6406161\, T + 0^\circ.0000839\, T^2 + 0^\circ.0000050\, T^3) \\
+\alpha_p & = & 180^\circ + (0^\circ.6406161\, T + 0^\circ.0000839\, T^2 + 0^\circ.0000050\, T^3) \\
 \delta_p & = & 0^\circ .5567530\, T - 0^\circ.0001185\, T^2 - 0^\circ.0000116\, T^3 \\
-\phi_p & = & 90^\circ + 0^\circ.6406161\, T + 0^\circ.0003041\, T^2 + 0^\circ.0000051\, T^3
+\phi_p & = & 180^\circ + 0^\circ.6406161\, T + 0^\circ.0003041\, T^2 + 0^\circ.0000051\, T^3
 \end{eqnarray}
 where $T$ is $($MJD$_{\rm out} -$ MJD$_{\rm in})/36525$ is the
