Index: trunk/doc/pslib/psLibADD.tex
===================================================================
--- trunk/doc/pslib/psLibADD.tex	(revision 1560)
+++ trunk/doc/pslib/psLibADD.tex	(revision 1583)
@@ -1,3 +1,3 @@
-%%% $Id: psLibADD.tex,v 1.28 2004-08-17 03:30:07 eugene Exp $
+%%% $Id: psLibADD.tex,v 1.29 2004-08-19 02:45:14 eugene Exp $
 \documentclass[panstarrs]{panstarrs}
 
@@ -897,4 +897,60 @@
 \subsubsection{Celestial Coordinate Conversions}
 
+Changes between spherical coordinate systems (ie, Ecliptic, Galactic,
+and ICRS, or Celestial, coordinates) is equivalent to a rotation in
+3D.  Given two coordinate system, $\alpha,\delta$ and $\phi,\theta$
+which differ by only a rotation, the transformation between these two
+systems are defined by the following three parameters:
+\begin{itemize}
+\item $\alpha_p$ : the longitude of the target system pole in the
+  source system
+\item $\delta_p$ : the latitutde of the target system pole in the
+  source system.  
+\item $\phi_p$ : the longitude of the ascending node in the target system
+\end{itemize}
+Note that $\theta_p$, the latitude of the source system pole in the
+target system, is equal to $\delta_p$ by symmetry.
+
+The relevant trigonometric relationships are:
+\begin{eqnarray}
+\sin \theta                        = \cos \delta \sin \delta_p \sin (\alpha - \alpha_p) + \sin \delta \cos \delta_p
+\cos \theta \sin (\phi - \phi_p)   = \cos \delta \cos \delta_p \sin (\alpha - \alpha_p) - \sin \delta \sin \delta_p
+\cos \theta \cos (\phi - \phi_p)   = \cos \delta \cos (\alpha - \alpha_p)
+\end{eqnarray}
+%
+and for the inverse transformations, the equivalent relationships are:
+%
+\begin{eqnarray}
+\sin \delta                          & = & \cos \theta \sin \delta_p \sin (\phi - \phi_p) + \sin \theta \cos \delta_p \\
+\cos \delta \sin (\alpha - \alpha_p) & = & \cos \theta \cos \delta_p \sin (\phi - \phi_p) - \sin \theta \sin \delta_p \\
+\cos \delta \cos (\alpha - \alpha_p) & = & \cos \theta \cos (\phi - \phi_p)
+\end{eqnarray}
+%
+Since $\theta$ and $\delta$ have domains of $-\pi/2, \pi/2$, the value
+of these angles are found by applying the arcsin to the sine of these
+angles ($\theta = \arcsin \sin \theta$) which is always single-valued
+and defined.  The value of $\alpha$ (or $\phi$) is found from
+\code{atan2(y,x)}, where $y = \cos \delta \sin (\alpha - \alpha_p)$ and
+$x = \cos \delta \cos (\alpha - \alpha_p)$.   
+
+\paragraph{Galactic to ICRS}
+
+\tbd{clean up these values - the transformations above need to be
+  checked for pole vs node coords}
+
+\begin{verbatim}
+*  P = 192.25       RA of galactic north pole (mean B1950.0)
+*  Q =  62.6        inclination of galactic to mean B1950.0 equator
+*  R =  33          longitude of ascending node
+
+We should precess L2,B2 coords from B1950 to epoch of interest 
+
+265.600000 -28.916667 (B1950)
+192.250000  27.400000 (B1950)
+
+266.394165 -28.936098 (J2000)
+192.859536  27.128309 (J2000)
+\end{verbatim}
+
 These will be implemented using the corresponding SLALIB functions:
 
@@ -912,47 +968,138 @@
 \subsubsection{Projections}
 
-The following information is from
+We implement three types of projections: {\em zenithal}, {\em
+cylindrical} and {\em pseudocylindrical}, each requiring slightly
+different handling.  Our representations are based on the treatment of
+projections presented by
 \href{http://www.cv.nrao.edu/fits/documents/wcs/wcs.all.ps}{Greisen \&
-Calabretta (1995, ADASS, 4, 233)}.
-
-Let the latitude be $\phi$ and the longitude $\theta$.  The domains of
-these are $-\pi < \phi \le \pi$ and $-\pi/2 \le \theta \le \pi/2$.
-
-For zenithal projections (e.g.\ Gnomonic and Orthographic) the
-following hold:
-
-\begin{eqnarray}
-x & = & R \sin (\phi) \\
-y & = & -R \cos (\phi)
-\end{eqnarray}
-
-and
-
-\begin{eqnarray}
-R & = & \sqrt{x^2 + y^2} \\
-\phi & = & {\rm arg} (-y,x)
-\end{eqnarray}
-
-\paragraph{Gnomonic}
-
-The Gnomonic projection (``TAN'') is a zenithal projection.
-
-\begin{eqnarray}
-R & = & \cot (\theta) 180^\circ/\pi \\
-\theta & = & \arctan (180^\circ/(\pi R))
-\end{eqnarray}
-
-\paragraph{Orthographic}
-
-The Orthographic projection (``SIN'') is a zenithal projection.
-
-\begin{eqnarray}
-R & = & \cos (\theta) 180^\circ/\pi \\
-\theta & = & \arccos (\pi R / 180^\circ)
-\end{eqnarray}
-
-\paragraph{Cartesian}
-
-The Cartesian projection (``CAR'') is a very simple cylindrical projection.
+Calabretta (1995, ADASS, 4, 233)}.  In all of these projections, we
+are converting from a spherical coordinate $\alpha,\delta$ to a linear
+(2-D) coordinate $x_p,y_p$.  The projection is defined by the
+projection type, the projection center ($\alpha_p, \delta_p$) and the
+the plate scales in the $x_p$ and $y_p$ directions ($\rho_x,\rho_y$).
+
+In the structure, \code{psProjection}, the projection type is defined
+by the element \code{type}, the projection center $\alpha_p,\delta_p$
+is defined by the elements \code{R,D}, and the plate scales,
+$\rho_x,\rho_y$, are defined by the elements \code{Xs,Ys}.  The plate
+scales are applied independently to the $x$ and $y$ coordinates to
+convert them to the corresponding linear units (ie, pixels):
+%
+\begin{eqnarray}
+x_p & = & \rho_x x \\
+y_p & = & \rho_y y \\
+\end{eqnarray}
+% 
+In the discussions below, we ignore this last step (or first step,
+depending on the direction of the conversion).
+
+\paragraph{Zenithal Projections}
+
+The {\em zenithal} projections are defined relative to a set of
+spherical coordinates with pole at the center of the projection
+($\alpha_p, \delta_p$), and which thus represents a coordinate system
+rotated relative to the coordinate system of $\alpha, \delta$.  In
+this spherical coordinate system, the coordinate of longitude is
+labeled $\phi$, and has domain of $-\pi < \phi \le \pi$, while the
+latitude, measured from the pole, is labeled $\theta$ and has domain
+$0 \le \theta \le \pi$.  The coordinate frame of $\phi,\theta$ is
+defined so that $\phi_p$, the longitude of the target system pole, is
+0.0.
+
+For an arbitrary projection center, it is necessary to convert the
+spherical coordinates to be projected ($\alpha,\delta$) to the
+projection spherical coordinate system coordinates ($\phi, \theta$).
+In practice, we construct the following useful trigonometric
+relationships between $\phi$ and $\theta$ which may be employed in the
+equations of $x,y$ below:
+%
+\begin{eqnarray}
+\sin \theta           & = & \sin \delta \sin \delta_p + \cos \delta \cos \delta_p \cos (\alpha - \alpha_p) \\
+\cos \theta \cos \phi & = & \sin \delta \cos \delta_p - \cos \delta \sin \delta_p \cos (\alpha - \alpha_p) \\
+\cos \theta \sin \phi & = & - \cos \delta \sin (\alpha - \alpha_p)
+\end{eqnarray}
+%
+For the inverse transformations, the equivalent relationships are:
+%
+\begin{eqnarray}
+\sin \delta                          & = & \sin \theta \sin \delta_p + \cos \theta \cos \delta_p \cos \phi \\
+\cos \delta \cos (\alpha - \alpha_p) & = & \sin \theta \cos \delta_p - \cos \theta \sin \delta_p \cos \phi \\
+\cos \delta \sin (\alpha - \alpha_p) & = & - \cos \theta \sin \phi
+\end{eqnarray}
+%
+For zenithal projections, the linear coordinates are related to
+$\phi,\theta$ by:
+%
+\begin{eqnarray}
+x & = & R_\theta \sin \phi \\
+y & = & -R_\theta \cos \phi
+\end{eqnarray}
+%
+and the inverse:
+%
+\begin{eqnarray}
+R_\theta & = & \sqrt{x^2 + y^2} \\
+\phi     & = & {\rm arg} (-y,x)
+\end{eqnarray}
+%
+The coordinates $x,y$ above are defined to be in angular units (ie,
+radians).  
+
+From these relationships, we can calculate $\alpha, \delta$ as:
+%
+\begin{eqnarray}
+\alpha - \alpha_p & = & \arctan (\sin \alpha, \cos \alpha) \\
+\delta            & = & \arcsin (\sin \delta) \\
+\end{eqnarray}
+%
+Note that if $(x,y) = (0,0)$, then $\alpha = \alpha_p, \delta = \delta_p$.
+
+\subparagraph{Gnomonic}
+
+The Gnomonic projection (``TAN'') is a zenithal projection with
+$R_\theta = \cot \theta$.  The resulting relationships for $(x,y)$ and
+for $\sin \theta, \cos \theta$ are:
+
+\begin{eqnarray}
+x           & = & \frac{\cos \theta \sin \phi}{\sin \theta} \\
+y           & = & \frac{-\cos \theta \cos \phi}{\sin \theta} \\
+\sin \theta & = & \zeta / \sqrt{1 + \zeta^2} \\
+\cos \theta & = & 1 / \sqrt{1 + \zeta^2} \\
+\end{eqnarray}
+
+where $\zeta = 1 / R_\theta$.
+
+\subparagraph{Orthographic}
+
+The Orthographic projection (``SIN'') is a zenithal projection with
+$R_\theta = \cos \theta$.  The resulting relationships for $(x,y)$ and
+for $\sin \theta, \cos \theta$ are:
+
+\begin{eqnarray}
+x           & = & \cos \theta \sin \phi \\
+y           & = & -\cos \theta \cos \phi \\
+\sin \theta & = & \sqrt{1 - R_\theta^2} \\
+\cos \theta & = & R_\theta \\
+\end{eqnarray}
+
+\paragraph{Cylindrical and Pseudocylindrical Projections}
+
+The {\em cylindrical} and {\em pseudocylindrical} projections are
+defined relative to a set of cylindrical coordinates whose pole is
+coincident with the pole of the spherical coordinates.  These
+projections are particularly used for full-sky representations, and
+are only defined for projection centers with $\delta_p = 0$.  In this
+spherical coordinate system, the coordinate of longitude is labeled
+$\phi$, and has domain of $-\pi < \phi \le \pi$, while the latitude,
+measured from the pole, is labeled $\theta$ and has domain $0 \le
+\theta \le \pi$.  The projection center longitude, $\alpha_p$
+corresponds to $\phi = 0$, thus the value of $\phi$ is determined as
+$\alpha - \alpha_p$ for all such projections.
+
+\subparagraph{Cartesian}
+
+The Cartesian projection (``CAR'') is a very simple cylindrical
+projection with the following relationships between $x,y$ and
+$\phi,\theta$:
 
 \begin{eqnarray}
@@ -961,5 +1108,5 @@
 \end{eqnarray}
 
-\paragraph{Mercator}
+\subparagraph{Mercator}
 
 The Mercator projection (``MER'') is a cylindrical projection.
@@ -967,16 +1114,16 @@
 \begin{eqnarray}
 x & = & \phi \\
-y & = & \ln \left( \tan (45^\circ + \theta/2) \right) 180^\circ/\pi \\
-{\rm and}\hspace{1cm} \theta & = & 2 \arctan \left( e^{y\pi/180^\circ} \right) - 90^\circ
-\end{eqnarray}
-
-\paragraph{Hammer-Aitoff}
-
-The Hammer-Aitoff projection is a general projection, and is defined:
-
-\begin{eqnarray}
-x & = & 2 \alpha \cos (\theta) \sin (\phi/2) \\
-y & = & \alpha \sin \theta \\
-{\rm where}\hspace{1cm} \alpha^{-1} & \equiv & (180^\circ/\pi) \sqrt{\left(1 + \cos (\theta) \cos (\phi/2) \right) / 2}
+y & = & \ln \left( \tan (\pi/4 + \theta/2) \right) \\
+{\rm and}\hspace{1cm} \theta & = & 2 \arctan \left( e^y \right) - \pi/2
+\end{eqnarray}
+
+\subparagraph{Hammer-Aitoff}
+
+The Hammer-Aitoff projection(``AIT'') is a pseudocylindrical projection, and is defined:
+
+\begin{eqnarray}
+x & = & 2 \zeta \cos \theta \sin \frac{\phi}{2} \\
+y & = & \zeta \sin \theta \\
+{\rm where}\hspace{1cm} \zeta^{-1} & \equiv & \sqrt{\frac{1}{2}\left(1 + \cos \theta \cos \frac{\phi}{2} \right)}
 \end{eqnarray}
 
@@ -984,7 +1131,24 @@
 
 \begin{eqnarray}
-\phi & = & 2 {\rm arg} (2z^2 - 1, xz \pi/360^\circ) \\
-\theta & = & \arcsin (yz\pi/180^\circ) \\
-{\rm where}\hspace{1cm} z & \equiv & \sqrt{1 - (x\pi/720^\circ)^2 - (y\pi/360^\circ)^2}
+\phi & = & 2 {\rm \arctan} (2z^2 - 1, x z) \\
+\theta & = & \arcsin (yz) \\
+{\rm where}\hspace{1cm} z & \equiv & \sqrt{1 - (x/2)^2 - y^2}
+\end{eqnarray}
+
+\subparagraph{Parabolic}
+
+The Parabolic projection (``PAR'') is a pseudocylindrical projection, and is defined:
+
+\begin{eqnarray}
+x & = & \phi \left( 2 \cos \frac{2 \theta}{3} - 1 \right) \\
+y & = & \pi \sin \frac{\theta}{3} \\
+\end{eqnarray}
+
+And in reverse:
+
+\begin{eqnarray}
+\theta & = & 3 \sin^{-1} \rho \\
+\phi   & = & \frac{x}{1 - 4\rho^2} \\
+{\rm where}\hspace{1cm} \rho & \equiv & y/\pi \\
 \end{eqnarray}
 
