From celestial to projection plane coordinates

For each point, the 3 quantities of Eqs. [*] to [*] are computed (variables cosr, sinrsinp, and sinrcosp):

$\displaystyle c$ $\displaystyle =$ $\displaystyle \sin\delta\sin\delta_0 + \cos\delta\cos\delta_0\cos\Delta\alpha \quad (=\cos\theta)$ (52)
$\displaystyle S$ $\displaystyle =$ $\displaystyle \cos\delta\sin\Delta\alpha \quad (=\sin\theta\sin p)$ (53)
$\displaystyle C$ $\displaystyle =$ $\displaystyle \sin\delta\cos\delta_0 - \cos\delta\sin\delta_0\cos\Delta\alpha \quad (=\sin\theta\cos p)$ (54)

Neither $\theta$ nor $p$ are computed. Instead, the scaling factor $k =
r/\sin\theta = 2\tan(\theta/2)/\sin\theta$ (variable expr) is computed from Eq. [*] as:

\begin{displaymath}k =
\begin{cases}
\dfrac{2}{1+c} & \text{if } c \ge 0 \text{ ...
...^2+C^2} & \text{if } c < 0 \text{ (far hemisphere)}
\end{cases}\end{displaymath} (55)

and the projection plane coordinates are obtained by applying the rotation by the projection angle to $(kS,kC) = (r\sin p,r\cos p)$:
$\displaystyle x$ $\displaystyle =$ $\displaystyle kS\cos\psi + kC\sin\psi$ (56)
$\displaystyle y$ $\displaystyle =$ $\displaystyle kC\cos\psi - kS\sin\psi$ (57)

which is equivalent to Eqs. [*] and [*]. The cosine and sine of the projection angle (variables cpang and spang) are computed once before the loop on the points. The reasons for this formulation are: