\section{Two-Dimensional Reduction}

\begin{comment}
Adequately sampling the planet with respect to a viewpoint and a
reference sphere is a difficult three-dimensional problem; therefore,
it is helpful to work in two dimensions. For this we refer to Fourquet
{\em et al.}~\cite{FCM08} who show that ray-terrain intersection
with a spherical underlying surface can be reduced to two-dimensional
cross sections consisting of a ray and a circle, as demonstrated in
\Figure{fourquet}.  The cross section is formed by the plane containing
the ray and a special ray called the {\em nadir}, the unit vector that
points toward the center of the sphere. In the figure, the nadir is the
ray that goes through the point $\text{CoP}_v$.

	\pngFigure{fourquet}{h!}{6cm}
	{The two-dimensional reduction.~\cite{FCM08}}

Although Fourquet {\em et al.}~\cite{FCM08} give equations to map
points on the view plane to geographic coordinates, we elect to derive
a trigonometry-based equation that results in less function calls when
implemented on the GPU.
\end{comment}

Inspired by the work of Fourquet\ea{FCM08} in displacement mapping a
spherical underlying surface, we simplify ray-sphere intersection in
three dimensions to ray-circle intersection in two dimensions. Not only
does this simplify GPU implementation, but also provides a mathematical
framework to solve the sampling issues (\Section{refSpheres} and
\Section{sampCam}).

We derive the trigonometric equation that maps the elevation $\omega$
of an eye ray to the elevation $\gamma$ of the sphere normal at the
ray-sphere intersection point, as shown in \Figure{rayNormalAngles}. The
angle $\omega$ is the angle between the eye ray $\unit{r}$ and the nadir
$\unit{n}$, and the angle $\gamma$ is the angle between the sphere normal
$\unit{s}$ and the antinadir $\unit{a}$, the opposite of the nadir.

	\texFigure{rayNormalAngles}{h!}
	{Rays and angles in the ray-circle intersection problem.}

Given the ray angle $\omega$, we will now show how to calculate
the normal angle $\gamma$ at the ray-circle intersection point. In
\Figure{rayCircleIntersection}, the length $r$ is the radius of the
circle, and $d$ is the distance between the ray's origin $O$ and the
circle's center $C$. The intersection problem produces $\triangle OCI$
for which we know the length of two sides ($d$ and $r$) and an angle
($\omega$).  Therefore, the law of sines can be used to obtain an equation
for a second angle $\epsilon$ in the triangle, written as
\equation
{
	\frac{r}{\sin \omega} = \frac{d}{\sin \epsilon}.
}
Solving this equation for $\epsilon$ results in
\equationL{firstEpsilon}
{
	\epsilon = \asin (\fracS{d}{r} \, \sin \, \omega).
}
With two angles of $\triangle OCI$, the third angle is
\equation
{
	\gamma = \pi - \omega - \epsilon,
}
which is the normal angle.

	\texFigure{rayCircleIntersection}{ht!}
	{The ray-circle intersection problem.}

However this is, in fact, not the angle we set out to find. An ambiguity
with respect to the law of sines leads to two possibilities, as shown in
\Figure{lawOfSinesAmbiguity}. Unless the ray is tangent to the circle,
it intersects the circle twice: once as it enters and again as it exits,
corresponding to the front facing and the back facing intersection points
respectively. The ambiguity results in two triangles $\triangle OCI_1$
and $\triangle OCI_2$. These triangles share two side lengths $r$ and
$d$ and an angle $\omega$. Conversely, the triangles differ by two
angles and a side, the first angles being $\epsilon_1$ and $\epsilon_2$
in each triangle and the second angles being $\gamma_1$ and $\gamma_2$
in each triangle.

	\texFigure{lawOfSinesAmbiguity}{h!}
	{Ambiguous solutions using the law of sines.}

This ambiguity is resolved using the observation that $\epsilon_2$ in
$\triangle OCI_2$ is acute and $\epsilon_1$ in $\triangle OCI_1$ is obtuse
and their sum is $\pi$. The acute angle $\epsilon_2$ is
a direct result of \Equation{firstEpsilon} given previously. The obtuse
angle $\epsilon_1$ and is found using
\equationL{epsilon1}
{
	\epsilon_1 = \pi - \epsilon_2.
}

Finally, we use substitution to find equations for the normal angle as a
function of the ray angle. The equation for $\gamma_1$ can be simplified
by substituting $\epsilon_1$ for \Equation{epsilon1} to get
\equation
{
	\gamma_1 = \epsilon_2 - \omega.
}
Substituting $\epsilon_2$ with \Equation{firstEpsilon}, we obtain
the direct equation for the front facing intersection.  Similarly,
we substitute \Equation{firstEpsilon} into $\gamma_2 = \pi - \omega
- \epsilon_2$ to obtain the direct equation for the back facing
intersection.  Together, the front facing and back facing equations are:
\equationLL{rayCircle1}{rayCircle2}
{
	\gamma_1 &= \asin (\fracS{d}{r} \, \sin \, \omega) - \omega,
}
{
	\gamma_2 &= -\asin (\fracS{d}{r} \, \sin \, \omega) - \omega + \pi.
}
