segment_segment_intersect.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Francisca Gil Ureta <[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_SEGMENT_SEGMENT_INTERSECT_H
  9. #define IGL_SEGMENT_SEGMENT_INTERSECT_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. /// Determine whether two line segments A,B intersect
  15. ///
  16. /// A: p + t*r : t \in [0,1]
  17. /// B: q + u*s : u \in [0,1]
  18. ///
  19. /// @param[in] p 3-vector origin of segment A
  20. /// @param[in] r 3-vector direction of segment A
  21. /// @param[in] q 3-vector origin of segment B
  22. /// @param[in] s 3-vector direction of segment B
  23. /// @param[out] t scalar point of intersection along segment A, t \in [0,1]
  24. /// @param[out] u scalar point of intersection along segment B, u \in [0,1]
  25. /// @param[in] eps precision
  26. /// @return true if intersection
  27. template<typename DerivedSource, typename DerivedDir>
  28. IGL_INLINE bool segment_segment_intersect(
  29. const Eigen::MatrixBase <DerivedSource> &p,
  30. const Eigen::MatrixBase <DerivedDir> &r,
  31. const Eigen::MatrixBase <DerivedSource> &q,
  32. const Eigen::MatrixBase <DerivedDir> &s,
  33. double &t,
  34. double &u,
  35. double eps = 1e-6);
  36. }
  37. #ifndef IGL_STATIC_LIBRARY
  38. # include "segment_segment_intersect.cpp"
  39. #endif
  40. #endif