AABBtree  0.0.0
A C++ non-recursive ND AABB tree
Loading...
Searching...
No Matches
AABBtree::Ray< Real, N > Class Template Reference

A mathematical ray in N-dimensional space. More...

#include <Ray.hxx>

Public Member Functions

 ~Ray ()=default
 
 Ray ()=default
 
 Ray (Ray const &r)
 
 Ray (Point const &o, Vector const &d)
 
template<typename = std::enable_if<N == 1>>
 Ray (Real const o, Real const d)
 
template<typename = std::enable_if<N == 2>>
 Ray (Real const o_x, Real const o_y, Real const d_x, Real const d_y)
 
template<typename = std::enable_if<N == 3>>
 Ray (Real const o_x, Real const o_y, Real const o_z, Real const d_x, Real const d_y, Real const d_z)
 
template<typename OtherReal>
 Ray (Ray< OtherReal, N > const &r)
 
template<typename NewReal>
Ray< NewReal, N > cast () const
 
Pointorigin ()
 
Point const & origin () const
 
Vectordirection ()
 
Vector const & direction () const
 
Raynormalize ()
 
Ray normalized () const
 
bool is_approx (Ray const &r, Real const tol=DUMMY_TOL) const
 
Raytranslate (Vector const &t)
 
Ray translated (Vector const &t) const
 
template<typename Transform>
Ray transformed (Transform const &t) const
 
template<typename Transform>
Raytransform (Transform const &t)
 
bool contains (Point const &p, Real tol=DUMMY_TOL) const
 
bool intersects (Box< Real, N > const &b, Real tol=DUMMY_TOL) const
 
bool intersect (Box< Real, N > const &b, Point &c, Point &f, Real tol=DUMMY_TOL) const
 
Real squared_distance (Point const &p, Real tol=DUMMY_TOL) const
 
Real squared_distance (Point const &p, Point &c, Real tol=DUMMY_TOL) const
 
Real distance (Point const &p, Real tol=DUMMY_TOL) const
 
Real distance (Point const &p, Point &c, Real tol=DUMMY_TOL) const
 
Real squared_interior_distance (Box< Real, N > const &b, Real tol=DUMMY_TOL) const
 
Real squared_interior_distance (Box< Real, N > const &b, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
 
Real interior_distance (Box< Real, N > const &b, Real tol=DUMMY_TOL) const
 
Real interior_distance (Box< Real, N > const &b, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
 
Real squared_exterior_distance (Box< Real, N > const &b, Real tol=DUMMY_TOL) const
 
Real squared_exterior_distance (Box< Real, N > const &b, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
 
Real exterior_distance (Box< Real, N > const &b, Real tol=DUMMY_TOL) const
 
Real exterior_distance (Box< Real, N > const &b, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
 
void print (std::ostream &os) const
 

Private Types

using Point = AABBtree::Point<Real, N>
 
using Vector = AABBtree::Vector<Real, N>
 

Private Attributes

Point m_origin
 
Vector m_direction
 

Static Private Attributes

static constexpr Real EPS {std::numeric_limits<Real>::epsilon()}
 
static constexpr Real INF {std::numeric_limits<Real>::infinity()}
 
static constexpr Real DUMMY_TOL {EPS*static_cast<Real>(100.0)}
 

Detailed Description

template<typename Real, Integer N>
class AABBtree::Ray< Real, N >

Forward declaration of the Ray class template.

Template Parameters
RealType of the scalar coefficients.
NDimension of the ambient space.

This class represents a ray defined by an origin point and a direction vector. The ray extends infinitely in the direction of the vector from the origin point. The class provides functionality for:

  • Ray transformations (translation, rotation, scaling);
  • Distance computations to points and boxes;
  • Intersection tests with axis-aligned bounding boxes;
  • Normalization and comparison operations.
Template Parameters
RealFloating-point scalar type (must be float or double).
NDimension of the ambient space.
Note
The direction vector is not required to be normalized, but some operations (like distance calculations) may internally normalize it.

Member Typedef Documentation

◆ Point

template<typename Real, Integer N>
using AABBtree::Ray< Real, N >::Point = AABBtree::Point<Real, N>
private

◆ Vector

template<typename Real, Integer N>
using AABBtree::Ray< Real, N >::Vector = AABBtree::Vector<Real, N>
private

Constructor & Destructor Documentation

◆ ~Ray()

template<typename Real, Integer N>
AABBtree::Ray< Real, N >::~Ray ( )
default

Default class destructor.

Note
This destructor is trivial and does not perform any special actions.

◆ Ray() [1/7]

template<typename Real, Integer N>
AABBtree::Ray< Real, N >::Ray ( )
default

Default class constructor.

Default class constructor that creates a ray with null origin and direction.

◆ Ray() [2/7]

template<typename Real, Integer N>
AABBtree::Ray< Real, N >::Ray ( Ray< Real, N > const & r)
inline

Copy constructor

Parameters
[in]rRay to copy

◆ Ray() [3/7]

template<typename Real, Integer N>
AABBtree::Ray< Real, N >::Ray ( Point const & o,
Vector const & d )
inline

Class constructor for a ray given an origin and a direction.

Parameters
[in]oOrigin of the ray.
[in]dDirection of the ray.

◆ Ray() [4/7]

template<typename Real, Integer N>
template<typename = std::enable_if<N == 1>>
AABBtree::Ray< Real, N >::Ray ( Real const o,
Real const d )
inline

Class constructor for the 1D ray.

Parameters
[in]oOrigin of the ray.
[in]dDirection of the ray.
Template Parameters
TType of the scalar coefficients.
Note
This constructor is only available for 1D rays.

◆ Ray() [5/7]

template<typename Real, Integer N>
template<typename = std::enable_if<N == 2>>
AABBtree::Ray< Real, N >::Ray ( Real const o_x,
Real const o_y,
Real const d_x,
Real const d_y )
inline

Class constructor for the 2D ray.

Parameters
[in]o_xOrigin \( x \)-axis component.
[in]o_yOrigin \( y \)-axis component.
[in]d_xDirection \( x \)-axis component.
[in]d_yDirection \( y \)-axis component.
Template Parameters
TType of the scalar coefficients.
Note
This constructor is only available for 2D rays.

◆ Ray() [6/7]

template<typename Real, Integer N>
template<typename = std::enable_if<N == 3>>
AABBtree::Ray< Real, N >::Ray ( Real const o_x,
Real const o_y,
Real const o_z,
Real const d_x,
Real const d_y,
Real const d_z )
inline

Class constructor for the 3D ray.

Parameters
[in]o_xOrigin \( x \)-axis component.
[in]o_yOrigin \( y \)-axis component.
[in]o_zOrigin \( z \)-axis component.
[in]d_xDirection \( x \)-axis component.
[in]d_yDirection \( y \)-axis component.
[in]d_zDirection \( z \)-axis component.
Template Parameters
TType of the scalar coefficients.
Note
This constructor is only available for 3D rays.

◆ Ray() [7/7]

template<typename Real, Integer N>
template<typename OtherReal>
AABBtree::Ray< Real, N >::Ray ( Ray< OtherReal, N > const & r)
inlineexplicit

Copy constructor for a ray given another ray with a different scalar type.

Parameters
[in]rRay to copy.
Template Parameters
OtherRealType of the scalar coefficients of the ray to copy.

Member Function Documentation

◆ cast()

template<typename Real, Integer N>
template<typename NewReal>
Ray< NewReal, N > AABBtree::Ray< Real, N >::cast ( ) const
inline

Cast the current object to a new scalar type.

Template Parameters
NewRealthe new scalar type
Note
If the new real type is equal to the current scalar type currently used, then this function returns a const reference to the current object.

◆ contains()

template<typename Real, Integer N>
bool AABBtree::Ray< Real, N >::contains ( Point const & p,
Real tol = DUMMY_TOL ) const
inline

Check if the point is inside the ray.

Parameters
[in]pPoint to check.
[in]tolTolerance to use for the containment.
Returns
True if the point is inside the ray, false otherwise.

◆ direction() [1/2]

template<typename Real, Integer N>
Vector & AABBtree::Ray< Real, N >::direction ( )
inline

Get the reference to the ray direction.

Returns
The reference to the ray direction.

◆ direction() [2/2]

template<typename Real, Integer N>
Vector const & AABBtree::Ray< Real, N >::direction ( ) const
inline

Get the const reference to the ray direction.

Returns
The const reference to the ray direction.

◆ distance() [1/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::distance ( Point const & p,
Point & c,
Real tol = DUMMY_TOL ) const
inline

Compute the distance between the current ray a given point, returning a point at the given distance.

Parameters
[in]pPoint to compute the distance to.
[out]cClosest point on the ray.
[in]tolTolerance to use for the intersection.
Returns
The distance between the ray and the point.

◆ distance() [2/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::distance ( Point const & p,
Real tol = DUMMY_TOL ) const
inline

Compute the distance between the current ray a given point.

Parameters
[in]pPoint to compute the distance to.
[in]tolTolerance to use for the intersection.
Returns
The distance between the ray and the point.

◆ exterior_distance() [1/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::exterior_distance ( Box< Real, N > const & b,
Point & p1,
Point & p2,
Real tol = DUMMY_TOL ) const
inline

Compute the exterior (or maximum) distance between the current ray a given box, and return two points at the maximum distance.

Parameters
[in]bBox to compute the distance to.
[out]p1First point at the maximum distance (on the current ray).
[out]p2Second point at the maximum distance (on the box).
[in]tolTolerance to use for the distance computation.
Returns
The distance between the ray and the box.
Note
The distance is positive if the ray and the box do not intersect, zero otherwise.

◆ exterior_distance() [2/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::exterior_distance ( Box< Real, N > const & b,
Real tol = DUMMY_TOL ) const
inline

Compute the exterior (or maximum) distance between the current ray a given box.

Parameters
[in]bBox to compute the distance to.
[in]tolTolerance to use for the distance computation.
Returns
The distance between the ray and the box.
Note
The distance is positive if the ray and the box do not intersect, zero otherwise.

◆ interior_distance() [1/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::interior_distance ( Box< Real, N > const & b,
Point & p1,
Point & p2,
Real tol = DUMMY_TOL ) const
inline

Compute the interior (or minimum) distance between the current ray a given box, returning two points at the minimum distance.

Parameters
[in]bBox to compute the distance to.
[out]p1First point at the minimum distance (on the current ray).
[out]p2Second point at the minimum distance (on the box).
[in]tolTolerance to use for the distance computation.
Returns
The distance between the ray and the box.
Note
The distance is positive if the ray and the box do not intersect, zero otherwise.

◆ interior_distance() [2/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::interior_distance ( Box< Real, N > const & b,
Real tol = DUMMY_TOL ) const
inline

Compute the interior (or minimum) distance between the current ray a given box.

Parameters
[in]bBox to compute the distance to.
[in]tolTolerance to use for the distance computation.
Returns
The distance between the ray and the box.
Note
The distance is positive if the ray and the box do not intersect, zero otherwise.

◆ intersect()

template<typename Real, Integer N>
bool AABBtree::Ray< Real, N >::intersect ( Box< Real, N > const & b,
Point & c,
Point & f,
Real tol = DUMMY_TOL ) const
inline

Check if the current ray intersects a given axis-aligned box.

Parameters
[in]bBox to check.
[out]cClosest intersection point.
[out]fFarthest intersection point.
[in]tolTolerance to use for the intersection.
Returns
True if the current ray intersects the given box, false otherwise.

◆ intersects()

template<typename Real, Integer N>
bool AABBtree::Ray< Real, N >::intersects ( Box< Real, N > const & b,
Real tol = DUMMY_TOL ) const
inline

Check if the current ray intersects a given axis-aligned box.

Parameters
[in]bBox to check.
[in]tolTolerance to use for the intersection.
Returns
True if the current ray intersects the given box, false otherwise.

◆ is_approx()

template<typename Real, Integer N>
bool AABBtree::Ray< Real, N >::is_approx ( Ray< Real, N > const & r,
Real const tol = DUMMY_TOL ) const
inline

Check if the current ray is approximately equal to another ray.

Parameters
[in]rRay to compare with.
[in]tolTolerance to use for the comparison.

◆ normalize()

template<typename Real, Integer N>
Ray & AABBtree::Ray< Real, N >::normalize ( )
inline

Normalize the direction of the ray.

Returns
A reference to the current ray.

◆ normalized()

template<typename Real, Integer N>
Ray AABBtree::Ray< Real, N >::normalized ( ) const
inline

Normalize the direction of the ray.

Returns
A copy of the current normalized ray.

◆ origin() [1/2]

template<typename Real, Integer N>
Point & AABBtree::Ray< Real, N >::origin ( )
inline

Get the reference to the ray origin.

Returns
The reference to the ray origin.

◆ origin() [2/2]

template<typename Real, Integer N>
Point const & AABBtree::Ray< Real, N >::origin ( ) const
inline

Get the const reference to the ray origin.

Returns
The const reference to the ray origin.

◆ print()

template<typename Real, Integer N>
void AABBtree::Ray< Real, N >::print ( std::ostream & os) const
inline

Print the ray info to an output stream.

Parameters
[in]osOutput stream to print the ray info to.

◆ squared_distance() [1/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::squared_distance ( Point const & p,
Point & c,
Real tol = DUMMY_TOL ) const
inline

Compute the squared distance between the current ray a given point, returning a point at the given distance.

Parameters
[in]pPoint to compute the distance to.
[out]cClosest point on the ray.
[in]tolTolerance to use for the intersection.
Returns
The squared distance between the ray and the point.

◆ squared_distance() [2/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::squared_distance ( Point const & p,
Real tol = DUMMY_TOL ) const
inline

Compute the squared distance between the current ray a given point.

Parameters
[in]pPoint to compute the squared distance to.
[in]tolTolerance to use for the intersection.
Returns
The squared distance between the ray and the point.

◆ squared_exterior_distance() [1/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::squared_exterior_distance ( Box< Real, N > const & b,
Point & p1,
Point & p2,
Real tol = DUMMY_TOL ) const
inline

Compute the squared exterior (or maximum) distance between the current ray a given box, returning two points at the maximum distance.

Parameters
[in]bBox to compute the squared distance to.
[out]p1First point at the maximum distance (on the current ray).
[out]p2Second point at the maximum distance (on the box).
[in]tolTolerance to use for the distance computation.
Returns
The squared distance between the ray and the box.

◆ squared_exterior_distance() [2/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::squared_exterior_distance ( Box< Real, N > const & b,
Real tol = DUMMY_TOL ) const
inline

Compute the squared exterior (or maximum) distance between the current ray a given box.

Parameters
[in]bBox to compute the squared distance to.
[in]tolTolerance to use for the distance computation.
Returns
The squared distance between the ray and the box.
Note
The squared distance is positive if one box is not contained in the other, zero otherwise.

◆ squared_interior_distance() [1/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::squared_interior_distance ( Box< Real, N > const & b,
Point & p1,
Point & p2,
Real tol = DUMMY_TOL ) const
inline

Compute the squared interior (or minimum) distance between the current ray a given box, returning two points at the minimum distance.

Parameters
[in]bBox to compute the squared distance to.
[out]p1First point at the minimum distance (on the current ray).
[out]p2Second point at the minimum distance (on the box).
[in]tolTolerance to use for the distance computation.
Returns
The squared distance between the ray and the box.
Note
The squared distance is positive if the ray and the box do not intersect, zero otherwise.

◆ squared_interior_distance() [2/2]

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::squared_interior_distance ( Box< Real, N > const & b,
Real tol = DUMMY_TOL ) const
inline

Compute the squared interior (or minimum) distance between the current ray a given box.

Parameters
[in]bBox to compute the squared distance to.
[in]tolTolerance to use for the distance computation.
Returns
The squared distance between the ray and the box.
Note
The squared distance is positive if the ray and the box do not intersect, zero otherwise.

◆ transform()

template<typename Real, Integer N>
template<typename Transform>
Ray & AABBtree::Ray< Real, N >::transform ( Transform const & t)
inline

Transform the current ray by a given vector.

Parameters
[in]tTransformation to apply to the ray.
Returns
A reference to the current ray.
Template Parameters
TransformType of the transformation.

◆ transformed()

template<typename Real, Integer N>
template<typename Transform>
Ray AABBtree::Ray< Real, N >::transformed ( Transform const & t) const
inline

Transform the current ray by a given vector.

Parameters
[in]tTransformation to apply to the ray.
Returns
A copy of the current transformed ray.
Template Parameters
TransformType of the transformation.

◆ translate()

template<typename Real, Integer N>
Ray & AABBtree::Ray< Real, N >::translate ( Vector const & t)
inline

Translate the current ray by a given vector.

Parameters
[in]tVector to translate the ray by.
Returns
A reference to the current ray.

◆ translated()

template<typename Real, Integer N>
Ray AABBtree::Ray< Real, N >::translated ( Vector const & t) const
inline

Translate the current ray by a given vector.

Parameters
[in]tVector to translate the ray by.
Returns
A copy of the current translated ray.

Member Data Documentation

◆ DUMMY_TOL

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::DUMMY_TOL {EPS*static_cast<Real>(100.0)}
staticconstexprprivate

Default tolerance for the scalar type

◆ EPS

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::EPS {std::numeric_limits<Real>::epsilon()}
staticconstexprprivate

Machine epsilon for the scalar type.

◆ INF

template<typename Real, Integer N>
Real AABBtree::Ray< Real, N >::INF {std::numeric_limits<Real>::infinity()}
staticconstexprprivate

Infinity value for the scalar type.

◆ m_direction

template<typename Real, Integer N>
Vector AABBtree::Ray< Real, N >::m_direction
private

Direction vector of the ray (not necessarily normalized).

◆ m_origin

template<typename Real, Integer N>
Point AABBtree::Ray< Real, N >::m_origin
private

Origin point of the ray.


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