pbpt
Loading...
Searching...
No Matches
pbpt::math::Ray< T, N > Class Template Reference

A template class for an N-dimensional geometric ray. More...

#include <ray.hpp>

Public Member Functions

constexpr Ray () noexcept
 Default constructor.
constexpr Ray (const Point< T, N > &origin, const Vector< T, N > &direction)
 Constructs a ray from an origin point and a direction vector.
constexpr Ray (const Point< T, N > &origin, const Point< T, N > &target)
 Constructs a ray from a starting point to a target point.
constexpr const Point< T, N > & origin () const noexcept
 Gets the origin point of the ray.
constexpr const Vector< T, N > & direction () const noexcept
 Gets the direction vector of the ray.
constexpr Point< T, N > at (T t) const noexcept
 Calculates a point along the ray using the parametric equation.

Detailed Description

template<typename T, int N>
class pbpt::math::Ray< T, N >

A template class for an N-dimensional geometric ray.

This class represents a ray in N-dimensional space, defined by a starting point (origin) and a direction vector. A key design feature of this class is that the direction vector is always stored as a normalized (unit) vector. This invariant is enforced by the constructors, simplifying calculations and ensuring consistent behavior.

The ray is described by the parametric equation P(t) = origin + t * direction.

Template Parameters
TThe underlying floating-point type of the ray's components.
NThe number of dimensions.
See also
Point
Vec

Constructor & Destructor Documentation

◆ Ray() [1/3]

template<typename T, int N>
pbpt::math::Ray< T, N >::Ray ( )
inlineconstexprnoexcept

Default constructor.

Creates a ray starting at the origin (0,0,...) and pointing along the positive x-axis (1,0,...).

◆ Ray() [2/3]

template<typename T, int N>
pbpt::math::Ray< T, N >::Ray ( const Point< T, N > & origin,
const Vector< T, N > & direction )
inlineconstexpr

Constructs a ray from an origin point and a direction vector.

Parameters
originThe starting point of the ray.
directionThe direction vector of the ray.
Note
The provided direction vector will be normalized upon construction to ensure the internal direction is always a unit vector.

◆ Ray() [3/3]

template<typename T, int N>
pbpt::math::Ray< T, N >::Ray ( const Point< T, N > & origin,
const Point< T, N > & target )
inlineconstexpr

Constructs a ray from a starting point to a target point.

This creates a ray that starts at origin and points towards target. The direction is calculated as (target - origin) and then normalized.

Parameters
originThe starting point of the ray.
targetThe point the ray will travel towards.

Member Function Documentation

◆ at()

template<typename T, int N>
Point< T, N > pbpt::math::Ray< T, N >::at ( T t) const
inlineconstexprnoexcept

Calculates a point along the ray using the parametric equation.

This method evaluates P(t) = origin + t * direction to find a point at a specific distance along the ray.

Parameters
tThe distance parameter. t can be thought of as the distance from the origin in units of the direction vector's length (which is 1). Negative values of t will yield points "behind" the ray's origin.
Returns
The Point<T, N> at the specified parameter t.

◆ direction()

template<typename T, int N>
const Vector< T, N > & pbpt::math::Ray< T, N >::direction ( ) const
inlineconstexprnoexcept

Gets the direction vector of the ray.

Returns
A const reference to the ray's direction vector.
Note
The returned vector is guaranteed to be a unit vector.

◆ origin()

template<typename T, int N>
const Point< T, N > & pbpt::math::Ray< T, N >::origin ( ) const
inlineconstexprnoexcept

Gets the origin point of the ray.

Returns
A const reference to the ray's origin.

The documentation for this class was generated from the following file:
  • /Users/jinceyang/Desktop/codebase/pbpt/engine/math/ray.hpp