ray_box_intersect.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_RAY_BOX_INTERSECT_H
  9. #define IGL_RAY_BOX_INTERSECT_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <Eigen/Geometry>
  13. namespace igl
  14. {
  15. // Determine whether a ray origin+t*dir and box intersect within the ray's parameterized
  16. // range (t0,t1)
  17. //
  18. // Inputs:
  19. // source 3-vector origin of ray
  20. // dir 3-vector direction of ray
  21. // box axis aligned box
  22. // t0 hit only if hit.t less than t0
  23. // t1 hit only if hit.t greater than t1
  24. // Outputs:
  25. // tmin minimum of interval of overlap within [t0,t1]
  26. // tmax maximum of interval of overlap within [t0,t1]
  27. // Returns true if hit
  28. template <
  29. typename Derivedsource,
  30. typename Deriveddir,
  31. typename Scalar>
  32. IGL_INLINE bool ray_box_intersect(
  33. const Eigen::PlainObjectBase<Derivedsource> & source,
  34. const Eigen::PlainObjectBase<Deriveddir> & dir,
  35. const Eigen::AlignedBox<Scalar,3> & box,
  36. const Scalar & t0,
  37. const Scalar & t1,
  38. Scalar & tmin,
  39. Scalar & tmax);
  40. }
  41. #ifndef IGL_STATIC_LIBRARY
  42. # include "ray_box_intersect.cpp"
  43. #endif
  44. #endif