\chapter{Viewing limit calculation}
\label{viewing-limit}

\begin{figure}
\begin{center}
\begin{picture}(292,218)
\psfig{figure=visibility.eps,width=292pt,height=218pt}
\end{picture}
\end{center}
\caption{
\label{visibility}}
\end{figure}

In chapter~\ref{VRML_terrain}, the information of viewing distance vs. altitude
 is used to determine the size of the terrain grid that needed for the VRML 2.0
terrain rendering system.  The viewing distance is computed with the following
two assumptions:

\begin{enumerate}
\item skyline is not obscured by any terrain feature.
\item The earth is a perfect spherical body.
\end{enumerate}

Although these assumptions only hold true in an idealistic world, their failure
do not have significant impact on the quality of the presentation of the terrain
data.  The assumption of non-obscured skyline allows the calculation of the
maximum viewing distance.  During the rendering of the terrain data, the
skyline will be correctly rendered by using the depth information of the
terrain data.  Because the viewing distance at specific altitude is related
to the curvature  of the planet, the assumed shape of the planet affects
the accuracy of the result.  However, the variation of the earth surface is
not observable by human eye as shown in figure~\ref{earth}.   As a result,
the information of viewing distance vs. Altitude computed with the
assumptions is sufficiently accurate to use for designing the VRML 2.0
terrain rendering system.


%Angle C is alway $90^{\circ}$ because line BC is tangential to the sphere.
 
Figure~\ref{visibility}, where $h$ is the altitude and $r$ is the radius of the
earth (6371 Km), shows the geometry that used in the viewing distance
calculation.  The point $C$ is the figure is the furthest visible point, which
is limited by the
plantery curvature, at altitude $h$.  The line $BC$ is tangential to the sphere
and forms an $90^{\circ}$ with the line $AC$.  Hence, the triangle $ABC$ is
an right angle triangle.  Using the properties of an right angle triangle, two
equations ~\ref{viewing-sin-1} and~\ref{viewing-pry-1} is derived.  By
substitute~\ref{viewing-sin-2} into equation~\ref{viewing-pry-1}, the angle at
point $A$ can be computed by formula~\ref{viewing-pry-2}.
\begin{eqnarray}
\frac{d}{r + h} & = & \sin \beta \label{viewing-sin-1} \\
d & = & \sin \beta (r + h) \label{viewing-sin-2}
\end{eqnarray}

\begin{eqnarray}
(r + h)^{2} & = & r^{2} + d^{2} \label{viewing-pry-1}\\
r^{2} + 2 hr + h^{2} & = & r^{2} + (\sin \beta (r + h))^{2} \nonumber \\
2 hr + h^{2} & = & (\sin \beta  (r + h))^{2} \nonumber \\
\pm \sqrt{2 hr + h^{2}} & = & \sin \beta  (r + h) \nonumber \\
\frac{\pm \sqrt{2 hr + h^{2}}}{r + h} & = & \sin(\beta) \nonumber \\ 
\beta & = & \sin^{-1} \frac{\pm \sqrt{2 hr + h^{2}}}{r + h} \label{viewing-pry-2}
\end{eqnarray}
Finally, the viewing distance is calculated by formula~\ref{viewing-dis-1}.

\begin{eqnarray}
\mbox{Viewing distance at height } h & = & \beta r \label{viewing-dis-1}
\end{eqnarray}

