Celeritas 0.6.0-dev.115+3b60a5fd
|
Test for being approximately a unit vector. More...
#include <ArraySoftUnit.hh>
Public Types | |
Type aliases | |
using | value_type = T |
Public Member Functions | |
CELER_FUNCTION | ArraySoftUnit (value_type tol) |
Construct with explicit tolereance. | |
CELER_CONSTEXPR_FUNCTION | ArraySoftUnit () |
Construct with default tolereance. | |
template<::celeritas::size_type N> | |
CELER_CONSTEXPR_FUNCTION bool | operator() (Array< T, N > const &arr) const |
Calculate whether the array is nearly a unit vector. | |
Test for being approximately a unit vector.
Consider a unit vector v with a small perturbation along a unit vector e :
\[ \vec v + \epsilon \vec e \]
The magnitude of this "nearly unit" is
\[ m^2 = (v + \epsilon e) \cdot (v + \epsilon e) = 1 + 2 (v \cdot e) \epsilon + \epsilon^2 \]
Since by the triangle inequality
\[ |v \cdot e| <= |v||e| = 1 \]
, then the magnitude squared of a perturbed unit vector is bounded
\[ m^2 = 1 \pm 2 \epsilon + \epsilon^2 \]
Instead of calculating the square of the tolerance we use \( \epsilon^2 < \epsilon \) to make the "soft unit vector" condition
\[ | \vec v \vd \vec v - 1 | < 3 \epsilon . \]
CELER_CONSTEXPR_FUNCTION bool celeritas::ArraySoftUnit< T >::operator() | ( | Array< T, N > const & | arr | ) | const |
Calculate whether the array is nearly a unit vector.
The calculation below is equivalent to
.