ray_sphere_intersect.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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_SPHERE_INTERSECT_H
  9. #define IGL_RAY_SPHERE_INTERSECT_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. /// Compute the intersection between a ray from O in direction D and a sphere
  15. /// centered at C with radius r
  16. ///
  17. /// @param[in] o origin of ray
  18. /// @param[in] d direction of ray
  19. /// @param[in] c center of sphere
  20. /// @param[in] r radius of sphere
  21. /// @param[out] t0 parameterization of first hit (set only if exists) so that
  22. /// hit position = o + t0*d
  23. /// @param[out] t1 parameterization of second hit (set only if exists)
  24. /// @return the number of hits
  25. template <
  26. typename Derivedo,
  27. typename Derivedd,
  28. typename Derivedc,
  29. typename r_type,
  30. typename t_type>
  31. IGL_INLINE int ray_sphere_intersect(
  32. const Eigen::MatrixBase<Derivedo> & o,
  33. const Eigen::MatrixBase<Derivedd> & d,
  34. const Eigen::MatrixBase<Derivedc> & c,
  35. r_type r,
  36. t_type & t0,
  37. t_type & t1);
  38. }
  39. #ifndef IGL_STATIC_LIBRARY
  40. #include "ray_sphere_intersect.cpp"
  41. #endif
  42. #endif