segment_segment_intersect.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Francisca Gil Ureta <gilureta@cs.nyu.edu>
  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. // A: p + t*r : t \in [0,1]
  16. // B: q + u*s : u \in [0,1]
  17. // Inputs:
  18. // p 3-vector origin of segment A
  19. // r 3-vector direction of segment A
  20. // q 3-vector origin of segment B
  21. // s 3-vector direction of segment B
  22. // eps precision
  23. // Outputs:
  24. // t scalar point of intersection along segment A, t \in [0,1]
  25. // u scalar point of intersection along segment B, u \in [0,1]
  26. // Returns true if intersection
  27. template<typename DerivedSource, typename DerivedDir>
  28. IGL_INLINE bool segment_segment_intersect(
  29. const Eigen::PlainObjectBase <DerivedSource> &p,
  30. const Eigen::PlainObjectBase <DerivedDir> &r,
  31. const Eigen::PlainObjectBase <DerivedSource> &q,
  32. const Eigen::PlainObjectBase <DerivedDir> &s,
  33. double &t,
  34. double &u,
  35. double eps = 1e-6
  36. );
  37. }
  38. #ifndef IGL_STATIC_LIBRARY
  39. # include "segment_segment_intersect.cpp"
  40. #endif
  41. #endif //IGL_SEGMENT_SEGMENT_INTERSECT_H