Celeritas
0.5.0-56+6b053cd
|
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. More... | |
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 squared is
\[ m^2 = (v + \epsilon e) \cdot (v + \epsilon e) = v \cdot v + 2 \epsilon v \cdot e + \epsilon^2 e \cdot e = 1 + 2 \epsilon v \cdot e + \epsilon^2 \]
Since
\[ |v \cdot e| <= |v||e| = 1 \]
by the triangle inequality, 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 loosely bound with another 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
.