next up previous contents
Next: 5.3.4 Cosine Distribution Up: 5.3 Generation of Random Previous: 5.3.2 Coned Cosine Distribution

5.3.3 Direction Vector Calculation

Ray tracing usually requires a normalized direction vector. Therefore, once random polar and azimuthal angles with respect to the given unit vector $ {\vec{v}}$ are determined, the direction vector $ {\vec{\omega}}$ can be obtained by

$\displaystyle {\vec{\omega}}={\vec{v}}\cos{\theta}+\left({\vec{v}}'\cos{\phi}+{\vec{v}}\times{\vec{v}}'\sin{\phi}\right)\sin{\theta},$ (5.49)

where $ {\vec{v}}'$ is a normal vector with respect to $ {\vec{v}}$ , thus satisfying $ {\vec{v}}'\cdot{\vec{v}}=0$ . The rotational symmetry of the random direction distribution allows an arbitrary choice of $ {\vec{v}}'$ , which can be defined as follows

$\displaystyle {\vec{v}}':= \begin{cases}\frac{1}{\sqrt{1-{v}_{1}^2}}\cdot \left...
...{3}, 0, -{v}_{1} \right) & \lvert{v}_{1}\rvert>\lvert{v}_{2}\rvert. \end{cases}$ (5.50)

The case differentiation avoids problematic cases, where $ {\vec{v}}'$ vanishes. In the following, only the first case is considered. The second case can be converted to the first case by exchanging the first two components of $ {\vec{v}}$ , $ {v}_1$ and $ {v}_2$ , before calculating $ {\vec{\omega}}$ . A final exchange of the corresponding components of $ {\vec{\omega}}$ , $ {\omega}_1$ and $ {\omega}_2$ , leads to the correct direction vector.

The condition $ \lvert{v}_{1}\rvert\leq\lvert{v}_{2}\rvert$ together with $ \lVert{\vec{v}}\rVert=1$ implies $ \lvert{v}_{1}\rvert\leq\frac{1}{\sqrt{2}}$ and $ \lvert{v}_{2}\rvert\geq\frac{1}{\sqrt{3}}\ \vee\ \lvert{v}_{3}\rvert\geq\frac{1}{\sqrt{3}}$ . Therefore, $ {\vec{v}}'$ is always well-defined. Insertion into (5.49) gives

\begin{equation*}\begin{aligned}{\omega}_{1} &= {v}_{1}\cos{\theta}- f \left(1-{...
...{v}_{1} \sin{\phi} \right) - f\, {v}_{2} \cos{\phi} \end{aligned}\end{equation*}

with $ f:=\frac{\sin{\theta}}{\sqrt{1-{v}_{1}^2}}=\sqrt{\frac{1-\left(\cos{\theta}\right)^2}{1-{v}_{1}^2}}$ . Using the second notation of $ f$ , $ {\vec{\omega}}$ can be calculated without knowledge of $ \sin{\theta}$ at the expense of one additional multiplication. Some distributions, such as the previously discussed power cosine distribution, enable the direct calculation of $ \cos{\theta}$ , avoiding the costly evaluation of trigonometric functions for the polar angle entirely (see the last note in Algorithm 5.2).

The evaluation of the other trigonometric functions in (5.51) can also be avoided. The point $ (\sin{\phi},\cos{\phi})$ is uniformly distributed on the unit circle. An alternative way for picking a point on the unit circle is to randomly choose a point $ (a_1,a_2)$ on a disk and to calculate the normalized vector $ (a_1,a_2)/\sqrt{a_1^2+a_2^2}$ [25]. The radicand can be combined with that for the calculation of $ f$ obviating the extra evaluation of the root. Algorithm 5.4 describes the determination of a random unit vector $ {\vec{\omega}}$ around $ {\vec{v}}$ with given polar angle $ {\theta}$ , which is equivalent to $ {\vec{\omega}}\cdot{\vec{v}}=\cos{\theta}$ .


\begin{algorithm}
% latex2html id marker 9562\caption{Sampling a random vector...
...f
\State\Return ${\vec{\omega}}$
\EndFunction
\end{algorithmic}}
\end{algorithm}


next up previous contents
Next: 5.3.4 Cosine Distribution Up: 5.3 Generation of Random Previous: 5.3.2 Coned Cosine Distribution

Otmar Ertl: Numerical Methods for Topography Simulation