point_inside_polygon.cpp 1.0 KB

123456789101112131415161718192021222324252627282930
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2019 Hanxiao Shen <[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. #include "point_inside_polygon.h"
  9. template <typename Scalar>
  10. bool igl::predicates::point_inside_polygon(
  11. const Eigen::Matrix<Scalar,-1,2>& P,
  12. const Eigen::Matrix<Scalar,1,2>& q
  13. ){
  14. for(int i=0;i<P.rows();i++){
  15. int i_1 = (i+1) % P.rows();
  16. Eigen::RowVector2d a = P.row(i);
  17. Eigen::RowVector2d b = P.row(i_1);
  18. auto r = igl::predicates::orient2d(a,b,q);
  19. if(r == igl::predicates::Orientation::COLLINEAR ||
  20. r == igl::predicates::Orientation::NEGATIVE)
  21. return false;
  22. }
  23. return true;
  24. }
  25. #ifdef IGL_STATIC_LIBRARY
  26. template bool igl::predicates::point_inside_polygon<double>(Eigen::Matrix<double, -1, 2, 0, -1, 2> const&, Eigen::Matrix<double, 1, 2, 1, 1, 2> const&);
  27. #endif