ray_sphere_intersect.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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_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. // Inputs:
  18. // o origin of ray
  19. // d direction of ray
  20. // c center of sphere
  21. // r radius of sphere
  22. // Outputs:
  23. // t0 parameterization of first hit (set only if exists) so that hit
  24. // position = o + t0*d
  25. // t1 parameterization of second hit (set only if exists)
  26. //
  27. // Returns the number of hits
  28. template <
  29. typename Derivedo,
  30. typename Derivedd,
  31. typename Derivedc,
  32. typename r_type,
  33. typename t_type>
  34. IGL_INLINE int ray_sphere_intersect(
  35. const Eigen::PlainObjectBase<Derivedo> & o,
  36. const Eigen::PlainObjectBase<Derivedd> & d,
  37. const Eigen::PlainObjectBase<Derivedc> & c,
  38. r_type r,
  39. t_type & t0,
  40. t_type & t1);
  41. }
  42. #ifndef IGL_STATIC_LIBRARY
  43. #include "ray_sphere_intersect.cpp"
  44. #endif
  45. #endif