predicates.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // Compute the orientation of the triangle formed by pa, pb, pc.
  21. //
  22. // Input:
  23. // pa, pb, pc 2D points.
  24. //
  25. // Output:
  26. // Return POSITIVE if pa, pb, pc is counterclockwise oriented.
  27. // NEGATIVE if they are clockwise oriented.
  28. // COLLINEAR if they are collinear.
  29. template<typename Vector2D>
  30. IGL_INLINE Orientation orient2d(
  31. const Eigen::MatrixBase<Vector2D>& pa,
  32. const Eigen::MatrixBase<Vector2D>& pb,
  33. const Eigen::MatrixBase<Vector2D>& pc);
  34. // Compute the orientation of the tetrahedron formed by pa, pb, pc, pd.
  35. //
  36. // Input:
  37. // pa, pb, pc, pd 3D points.
  38. //
  39. // Output:
  40. // Return POSITIVE if pd is "below" the oriented plane formed by pa, pb and pc.
  41. // NEGATIVE if pd is "above" the plane.
  42. // COPLANAR if pd is on the plane.
  43. template<typename Vector3D>
  44. IGL_INLINE Orientation orient3d(
  45. const Eigen::MatrixBase<Vector3D>& pa,
  46. const Eigen::MatrixBase<Vector3D>& pb,
  47. const Eigen::MatrixBase<Vector3D>& pc,
  48. const Eigen::MatrixBase<Vector3D>& pd);
  49. // Decide whether a point is inside/outside/on a circle.
  50. //
  51. // Input:
  52. // pa, pb, pc 2D points that defines an oriented circle.
  53. // pd 2D query point.
  54. //
  55. // Output:
  56. // Return INSIDE if pd is inside of the circle defined by pa, pb and pc.
  57. // OUSIDE if pd is outside of the circle.
  58. // COCIRCULAR pd is exactly on the circle.
  59. template<typename Vector2D>
  60. IGL_INLINE Orientation incircle(
  61. const Eigen::MatrixBase<Vector2D>& pa,
  62. const Eigen::MatrixBase<Vector2D>& pb,
  63. const Eigen::MatrixBase<Vector2D>& pc,
  64. const Eigen::MatrixBase<Vector2D>& pd);
  65. // Decide whether a point is inside/outside/on a sphere.
  66. //
  67. // Input:
  68. // pa, pb, pc, pd 3D points that defines an oriented sphere.
  69. // pe 3D query point.
  70. //
  71. // Output:
  72. // Return INSIDE if pe is inside of the sphere defined by pa, pb, pc and pd.
  73. // OUSIDE if pe is outside of the sphere.
  74. // COSPHERICAL pd is exactly on the sphere.
  75. template<typename Vector3D>
  76. IGL_INLINE Orientation insphere(
  77. const Eigen::MatrixBase<Vector3D>& pa,
  78. const Eigen::MatrixBase<Vector3D>& pb,
  79. const Eigen::MatrixBase<Vector3D>& pc,
  80. const Eigen::MatrixBase<Vector3D>& pd,
  81. const Eigen::MatrixBase<Vector3D>& pe);
  82. }
  83. }
  84. #ifndef IGL_STATIC_LIBRARY
  85. # include "predicates.cpp"
  86. #endif
  87. #endif