\chapter{Glyphs}

When taking a snapshot of the moving fluid a lot of information about the simulation is lost. The direction the fluid was heading for instance. Glyphs are used to
take care of such problems. \\

\section{Description}

\textit{"Glyphs are icons that convey the value (orientation, magnitude) of a vector field by means of several graphical icons, such as arrows."} \\

\begin {center}
  \includegraphics[width=100mm]{glyphs.png} \\
  Figure 4: Triangle glyphs with a grey scaled colormap\\
\end {center}

What does it mean? The smoke in our fluid simulation has a direction and speed. These two values can be represented by a vector encoding the direction as the
orientation and the speed as the magnitude. If you draw this vector for each vertex you get a vector field that shows the direction and speed of the fluid at each
vertex. \\

In the figure above (figure 4) you see triangle glyphs with a grey scaled colormap. In the lower right region you can see that the fluid is moving upwards where at
the rest of the simulation the fluid is trying to get to the bottom of the screen. \\

\section{Implementation}

We implemented four additional glyphs besides the already implemented hedgehogs. We implemented triangles (see figure 4), 3D cones, 32x32 bitmap image glyphs (see
figure 5) and s second image glyphs. For every glyph we go through a set of steps.

\begin{itemize}
  \item calculate size (length)
  \item calculate angle (rotation)
  \item rotate and render object \\
\end{itemize}

The length is calculated using the following equation of Pythagoras:

$$ length = \sqrt{x^3 + y^3 + z^3}  $$

The angle $ \Theta $ of the glyph is calculated using the inner product ($ inprod $). The inner product is used to calculate the glyphs angle:

$$ \Theta = acos(inprod) * (180^\circ / \Pi) $$ \\

\begin {center}
  \includegraphics[width=100mm]{glyphs2.png} \\
  Figure 5: Image glyphs colored with a rainbow colormap \\
\end {center}

The second part of this assignment was to let the user be able to choose an alternative resolution for the sample grid. The default grid resolution is 50x50. The
user is now able to alter that resolution. We use the value of the nearest-neighbor for the glyph to visualize it. \\

\section{Difficulties}

We had some troubles with calculating the angle of the glyph. For some reason the calculation checks the smallest angle which is between $ 0^\circ $ and $ 180^\circ
$. When we located this irregularity it was easily fixed. \\

\section{Quake root}

A nice side note to this chapter is that we don't use the default $ sqrt(float) $ function that the C-library offers to determine the length of a vector for
instance. We use a function that we like to call the "Quake Root" from the game Quake 3. \\

The code implements the Newton Approximation of roots. The Newton approximation is supposed to be ran in iterations; each iteration enhances the accuracy until
enough iterations have been made for reaching the desired accuracy. The really interesting aspect of this function is a magic constant, used to calculate the
initial guess. Only one Newton approximation iteration is required for a low relative error of $ 10^{-3} $. \\

The function runs up to 4 times faster than the $ sqrt(float) $ function, even though it's usually implemented using the FSQRT assembly instruction! \\

You can read more about the magical square root at: \\
\textcolor[rgb]{0.00,0.00,1.00}{\underline{http://www.codemaestro.com/reviews/9}}
