Celeritas  0.5.0-56+6b053cd
Public Member Functions | List of all members
celeritas::SoftSurfaceEqual Class Reference

Compare two surfaces for soft equality. More...

#include <SoftSurfaceEqual.hh>

Public Member Functions

 SoftSurfaceEqual (Tolerance<> const &tol)
 Construct with tolerance.
 
 SoftSurfaceEqual (real_type rel)
 Construct with relative tolerance only.
 
 SoftSurfaceEqual ()
 Construct with default tolerance.
 
template<Axis T>
bool operator() (PlaneAligned< T > const &, PlaneAligned< T > const &) const
 Compare two aligned planes for near equality.
 
template<Axis T>
bool operator() (CylCentered< T > const &, CylCentered< T > const &) const
 Compare two centered axis-aligned cylinders for near equality.
 
bool operator() (SphereCentered const &, SphereCentered const &) const
 Compare two centered spheres for near equality.
 
template<Axis T>
bool operator() (CylAligned< T > const &, CylAligned< T > const &) const
 Compare two aligned cylinders for near equality.
 
bool operator() (Plane const &, Plane const &) const
 Compare two planes for near equality. More...
 
bool operator() (Sphere const &, Sphere const &) const
 Compare two spheres for near equality.
 
template<Axis T>
bool operator() (ConeAligned< T > const &, ConeAligned< T > const &) const
 Compare two cones for near equality.
 
bool operator() (SimpleQuadric const &, SimpleQuadric const &) const
 Compare two simple quadrics for near equality. More...
 
bool operator() (GeneralQuadric const &, GeneralQuadric const &) const
 Compare two general quadrics for near equality. More...
 
bool operator() (Involute const &, Involute const &) const
 Compare two centered involutes for near equality.
 

Detailed Description

Compare two surfaces for soft equality.

Member Function Documentation

◆ operator()() [1/3]

bool celeritas::SoftSurfaceEqual::operator() ( GeneralQuadric const &  a,
GeneralQuadric const &  b 
) const

Compare two general quadrics for near equality.

Note
This is an ad hoc comparison.

◆ operator()() [2/3]

bool celeritas::SoftSurfaceEqual::operator() ( Plane const &  a,
Plane const &  b 
) const

Compare two planes for near equality.

Consider two planes with normals a and b , without loss of generality where a is at \(x=0\) and b is in the xy plane. Suppose that to be equal, we want a intercept error of no more than \(\delta\) at a unit distance from the normal (since we're assuming the error is based on the length scale of the problem). Taking a ray from (1, 1) along (-1, 0), the distance to the plane with normal a is 1, and the distance to plane b is then \( 1 \pm \delta \). This results in a right triangle with legs of 1 and \( \delta \) and opening angle from the origin of \( \theta \), which is equal to the angle between the normals of the two planes. Thus we have:

\[ \tan \theta = \frac{\delta}{1} \]

and

\[ \cos \theta = a \cdot b \equiv \mu \;. \]

thus

\[ \mu = \frac{1}{\sqrt{1 + \delta^2}} \to \delta = \sqrt{\frac{1}{\mu^2} - 1} \]

so if we want to limit the intercept error to \( \epsilon \), then

\[ \sqrt{\frac{1}{\mu^2} - 1} < \epsilon \;. \]

and we also have to make sure the two planes are pointed into the same half-space by checking for \( \mu > 0 \).

Since this derivation is based on an absolute length scale of 1, the relative tolerance should be used.

Due to floating point arithmetic, \(mu\) can be slightly greater than unity, and since epsilon is often smaller than \(\sqrt{\epsilon_\mathrm{mach}}\) for single precision arithmetic, the comparison here adds an extra bump to account for the precision loss.

◆ operator()() [3/3]

bool celeritas::SoftSurfaceEqual::operator() ( SimpleQuadric const &  a,
SimpleQuadric const &  b 
) const

Compare two simple quadrics for near equality.

Note
This is an ad hoc comparison.

The documentation for this class was generated from the following files: