\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 in several graphical ways, such as hedgehogs or arrows."} \\

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

The smoke in the 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 this vector is drawn for each vertex a vector field that shows the direction and speed of the fluid at each vertex then becomes visible. \\

In the figure above (figure 4) a triangle glyph with a grey scaled colormap is visible. In the lower right region the fluid is moving upwards where as the rest of the simulation the fluid is trying to get to the bottom of the screen. \\

\section{Implementation}

Four additional glyphs where implemented besides the already implemented hedgehogs. Triangles (see figure 4), 3D cones, and 2 bitmap image glyphs (see figure 5). Every glyph has to go through a certain few steps explained below.

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

The length is calculated using the equation of Pythagoras:

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

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

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

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

Additionally it was required for this assignment to allow the user to choose an alternative resolution for the sample grid. The default grid resolution is 50x50. To visualize this grid, the value of the nearest-neighbor for the glyph is used. \\

\section{Difficulties}

Troubles began with calculating the angle of the glyph. For some reason the calculation checks the smallest angle which is between $ 0^\circ $ and $ 180^\circ$. After locating this irregularity the problem it was easily fixed. \\

\section{Quake root}

A nice side note to this chapter is that the default $ sqrt(float) $ function that the C-library offers, to determine the length of a vector for example, is not used. A function that will be called "Quake Root" from the game Quake 3 is used in it's place. \\

The code implements the Newton Approximation of roots, which is supposed to be ran in iterations; each iteration enhances the accuracy until enough iterations have been made for reaching the desired accuracy. Interestingly this function features 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 is usually implemented using the FSQRT assembly instruction! \\

More information about the magical square root can be found online at: \\
\textcolor[rgb]{0.00,0.00,1.00}{\underline{http://www.codemaestro.com/reviews/9}}
