predicates.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2019 Qingnan Zhou <qnzhou@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. #pragma once
  9. #ifndef IGL_PREDICATES_PREDICATES_H
  10. #define IGL_PREDICATES_PREDICATES_H
  11. #include <igl/igl_inline.h>
  12. #include <Eigen/Core>
  13. namespace igl {
  14. namespace predicates {
  15. enum class Orientation {
  16. POSITIVE=1, INSIDE=1,
  17. NEGATIVE=-1, OUTSIDE=-1,
  18. COLLINEAR=0, COPLANAR=0, COCIRCULAR=0, COSPHERICAL=0, DEGENERATE=0
  19. };
  20. // Initialize internal variable used by predciates. Must be called before
  21. // using exact predicates.
  22. IGL_INLINE void exactinit();
  23. // Compute the orientation of the triangle formed by pa, pb, pc.
  24. //
  25. // Input:
  26. // pa, pb, pc 2D points.
  27. //
  28. // Output:
  29. // Return POSITIVE if pa, pb, pc are counterclockwise oriented.
  30. // NEGATIVE if they are clockwise oriented.
  31. // COLLINEAR if they are collinear.
  32. template<typename Vector2D>
  33. IGL_INLINE Orientation orient2d(
  34. const Eigen::MatrixBase<Vector2D>& pa,
  35. const Eigen::MatrixBase<Vector2D>& pb,
  36. const Eigen::MatrixBase<Vector2D>& pc);
  37. // Compute the orientation of the tetrahedron formed by pa, pb, pc, pd.
  38. //
  39. // Input:
  40. // pa, pb, pc, pd 3D points.
  41. //
  42. // Output:
  43. // Return POSITIVE if pd is "below" the oriented plane formed by pa, pb and pc.
  44. // NEGATIVE if pd is "above" the plane.
  45. // COPLANAR if pd is on the plane.
  46. template<typename Vector3D>
  47. IGL_INLINE Orientation orient3d(
  48. const Eigen::MatrixBase<Vector3D>& pa,
  49. const Eigen::MatrixBase<Vector3D>& pb,
  50. const Eigen::MatrixBase<Vector3D>& pc,
  51. const Eigen::MatrixBase<Vector3D>& pd);
  52. // Decide whether a point is inside/outside/on a circle.
  53. //
  54. // Input:
  55. // pa, pb, pc 2D points that defines an oriented circle.
  56. // pd 2D query point.
  57. //
  58. // Output:
  59. // Return INSIDE if pd is inside of the circle defined by pa, pb and pc.
  60. // OUSIDE if pd is outside of the circle.
  61. // COCIRCULAR pd is exactly on the circle.
  62. template<typename Vector2D>
  63. IGL_INLINE Orientation incircle(
  64. const Eigen::MatrixBase<Vector2D>& pa,
  65. const Eigen::MatrixBase<Vector2D>& pb,
  66. const Eigen::MatrixBase<Vector2D>& pc,
  67. const Eigen::MatrixBase<Vector2D>& pd);
  68. // Decide whether a point is inside/outside/on a sphere.
  69. //
  70. // Input:
  71. // pa, pb, pc, pd 3D points that defines an oriented sphere.
  72. // pe 3D query point.
  73. //
  74. // Output:
  75. // Return INSIDE if pe is inside of the sphere defined by pa, pb, pc and pd.
  76. // OUSIDE if pe is outside of the sphere.
  77. // COSPHERICAL pd is exactly on the sphere.
  78. template<typename Vector3D>
  79. IGL_INLINE Orientation insphere(
  80. const Eigen::MatrixBase<Vector3D>& pa,
  81. const Eigen::MatrixBase<Vector3D>& pb,
  82. const Eigen::MatrixBase<Vector3D>& pc,
  83. const Eigen::MatrixBase<Vector3D>& pd,
  84. const Eigen::MatrixBase<Vector3D>& pe);
  85. }
  86. }
  87. #ifndef IGL_STATIC_LIBRARY
  88. # include "predicates.cpp"
  89. #endif
  90. #endif