15#ifndef AABBTREE_RAY_HXX
16#define AABBTREE_RAY_HXX
38 template <
typename Real, Integer N>
40 static_assert(std::is_floating_point<Real>::value,
"Ray Real type must be a floating-point type.");
41 static_assert(N > 0,
"Ray dimension must be positive.");
44 constexpr static Real
EPS{std::numeric_limits<Real>::epsilon()};
45 constexpr static Real
INF{std::numeric_limits<Real>::infinity()};
89 template <
typename = std::enable_if<N == 1>>
101 template <
typename = std::enable_if<N == 2>>
102 Ray(Real
const o_x, Real
const o_y, Real
const d_x, Real
const d_y)
116 template <
typename = std::enable_if<N == 3>>
117 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)
125 template<
typename OtherReal>
135 template<
typename NewReal>
137 if constexpr (std::is_same<Real, NewReal>::value) {
return *
this;}
205 template <
typename Transform>
215 template <
typename Transform>
243 Vector t_min, t_max; t_min.setConstant(-
INF), t_max.setConstant(
INF);
244 for (
Integer i{0}; i < N; ++i) {
248 if (t_min[i] > t_max[i]) {std::swap(t_min[i], t_max[i]);}
253 Real t_entry{t_min.maxCoeff()};
254 Real t_exit{t_max.minCoeff()};
255 return t_entry <= t_exit && t_exit >= -tol;
270 Vector t_min, t_max; t_min.setConstant(-
INF), t_max.setConstant(
INF);
271 for (
Integer i{0}; i < N; ++i) {
275 if (t_min[i] > t_max[i]) {std::swap(t_min[i], t_max[i]);}
280 Real t_entry{t_min.maxCoeff()};
281 Real t_exit{t_max.minCoeff()};
282 if (t_entry > t_exit && t_exit < -tol) {
return false;}
310 return (c - p).squaredNorm();
359 Vector t_min, t_max; t_min.setConstant(-
INF); t_max.setConstant(
INF);
360 for (
Integer i{0}; i < N; ++i) {
364 if (t_min[i] > t_max[i]) {std::swap(t_min[i], t_max[i]);}
368 Vector sides{b_max - b_min};
370 for (
Integer j{0}; j < N; ++j){
371 if (j == i) {
continue;}
372 if (
m_direction[j] > 0.0) {p1[j] += 0.5*sides[j]; p2[j] += 0.5*sides[j];}
373 else {p1[j] -= 0.5*sides[j]; p2[j] -= 0.5*sides[j];}
380 Real t_entry{t_min.maxCoeff()}, t_exit{t_max.minCoeff()};
381 if (t_entry <= t_exit && t_exit >= 0.0) {
return 0.0;}
384 for (
Integer i{0}; i < N; ++i) {
385 if (
m_origin[i] < b_min[i]) {p2[i] = b_min[i];}
386 else if (
m_origin[i] > b_max[i]) {p2[i] = b_max[i];}
393 if (t_proj < 0.0) {p1 =
m_origin;
return v.norm();}
396 return (p2 - p1).squaredNorm();
448 Vector t_min, t_max; t_min.setConstant(-
INF); t_max.setConstant(
INF);
449 for (
Integer i{0}; i < N; ++i) {
453 if (t_min[i] > t_max[i]) {std::swap(t_min[i], t_max[i]);}
457 Vector sides{b_max - b_min};
459 for (
Integer j{0}; j < N; ++j){
460 if (j == i) {
continue;}
461 if (
m_direction[j] > 0.0) {p1[j] -= 0.5*sides[j]; p2[j] -= 0.5*sides[j];}
462 else {p1[j] += 0.5*sides[j]; p2[j] += 0.5*sides[j];}
469 Real t_entry{t_min.maxCoeff()}, t_exit{t_max.minCoeff()};
470 if (t_entry <= t_exit && t_exit >= 0) {
return 0.0;}
473 for (
Integer i{0}; i < N; ++i) {
474 if (
m_origin[i] < b_min[i]) {p2[i] = b_max[i];}
475 else if (
m_origin[i] > b_max[i]) {p2[i] = b_min[i];}
482 if (t_proj < 0.0) {p1 =
m_origin;
return v.norm();}
485 return (p2 - p1).squaredNorm();
515 void print(std::ostream & os)
const {
517 "────────────────────────────────────────────────────────────────────────────────\n" <<
519 "\to = " <<
m_origin.transpose() <<
'\n' <<
521 "────────────────────────────────────────────────────────────────────────────────\n";
533 template <
typename Real, Integer N>
A class representing an axis-aligned bounding box (AABB) in N-dimensional space.
Definition Box.hxx:49
Real interior_distance(Point const &p) const
Definition Box.hxx:515
Real exterior_distance(Point const &p) const
Definition Box.hxx:569
bool contains(Point const &p) const
Definition Box.hxx:428
Point const & min() const
Definition Box.hxx:172
Point const & max() const
Definition Box.hxx:184
A mathematical ray in N-dimensional space.
Definition Ray.hxx:39
Point const & origin() const
Definition Ray.hxx:151
static constexpr Real DUMMY_TOL
Definition Ray.hxx:46
void print(std::ostream &os) const
Definition Ray.hxx:515
Vector const & direction() const
Definition Ray.hxx:163
Real distance(Point const &p, Real tol=DUMMY_TOL) const
Definition Ray.hxx:319
AABBtree::Point< Real, N > Point
Definition Ray.hxx:48
Real distance(Point const &p, Point &c, Real tol=DUMMY_TOL) const
Definition Ray.hxx:329
Vector m_direction
Definition Ray.hxx:52
Ray(Ray const &r)
Definition Ray.hxx:73
bool intersects(Box< Real, N > const &b, Real tol=DUMMY_TOL) const
Definition Ray.hxx:239
Ray & transform(Transform const &t)
Definition Ray.hxx:216
Ray translated(Vector const &t) const
Definition Ray.hxx:197
Real interior_distance(Box< Real, N > const &b, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
Definition Ray.hxx:419
Ray normalized() const
Definition Ray.hxx:175
bool is_approx(Ray const &r, Real const tol=DUMMY_TOL) const
Definition Ray.hxx:182
Ray(Ray< OtherReal, N > const &r)
Definition Ray.hxx:126
Ray transformed(Transform const &t) const
Definition Ray.hxx:206
Vector & direction()
Definition Ray.hxx:157
Real squared_interior_distance(Box< Real, N > const &b, Real tol=DUMMY_TOL) const
Definition Ray.hxx:340
bool contains(Point const &p, Real tol=DUMMY_TOL) const
Definition Ray.hxx:228
Ray(Point const &o, Vector const &d)
Definition Ray.hxx:80
AABBtree::Vector< Real, N > Vector
Definition Ray.hxx:49
Ray(Real const o, Real const d)
Definition Ray.hxx:90
Ray< NewReal, N > cast() const
Definition Ray.hxx:136
Real interior_distance(Box< Real, N > const &b, Real tol=DUMMY_TOL) const
Definition Ray.hxx:406
Point & origin()
Definition Ray.hxx:145
Point m_origin
Definition Ray.hxx:51
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)
Definition Ray.hxx:117
static constexpr Real INF
Definition Ray.hxx:45
Ray & normalize()
Definition Ray.hxx:169
bool intersect(Box< Real, N > const &b, Point &c, Point &f, Real tol=DUMMY_TOL) const
Definition Ray.hxx:266
Real squared_interior_distance(Box< Real, N > const &b, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
Definition Ray.hxx:353
static constexpr Real EPS
Definition Ray.hxx:44
Ray(Real const o_x, Real const o_y, Real const d_x, Real const d_y)
Definition Ray.hxx:102
Real exterior_distance(Box< Real, N > const &b, Real tol=DUMMY_TOL) const
Definition Ray.hxx:495
Real squared_distance(Point const &p, Point &c, Real tol=DUMMY_TOL) const
Definition Ray.hxx:306
Real squared_exterior_distance(Box< Real, N > const &b, Real tol=DUMMY_TOL) const
Definition Ray.hxx:429
Real squared_exterior_distance(Box< Real, N > const &b, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
Definition Ray.hxx:441
Real exterior_distance(Box< Real, N > const &b, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
Definition Ray.hxx:508
Real squared_distance(Point const &p, Real tol=DUMMY_TOL) const
Definition Ray.hxx:294
Ray & translate(Vector const &t)
Definition Ray.hxx:190
Namespace for the AABBtree library.
Definition AABBtree.hh:70
Eigen::Vector< Real, N > Point
Definition AABBtree.hh:91
std::ostream & operator<<(std::ostream &os, Box< Real, N > const &b)
Definition Box.hxx:828
Eigen::Vector< Real, N > Vector
Definition AABBtree.hh:90
AABBTREE_DEFAULT_INTEGER_TYPE Integer
The Integer type used in the AABBtree class.
Definition AABBtree.hh:78