point_inside_convex_polygon.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233
  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_convex_polygon.h"
  9. template <typename DerivedP, typename DerivedQ>
  10. IGL_INLINE bool igl::predicates::point_inside_convex_polygon(
  11. const Eigen::MatrixBase<DerivedP>& P,
  12. const Eigen::MatrixBase<DerivedQ>& q
  13. ){
  14. EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(DerivedP, -1, 2);
  15. EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(DerivedQ, 1, 2);
  16. typedef typename DerivedP::Scalar Scalar;
  17. for(int i=0;i<P.rows();i++){
  18. int i_1 = (i+1) % P.rows();
  19. Eigen::Matrix<Scalar,1,2> a = P.row(i);
  20. Eigen::Matrix<Scalar,1,2> b = P.row(i_1);
  21. auto r = igl::predicates::orient2d(a,b,q);
  22. if(r == igl::predicates::Orientation::COLLINEAR ||
  23. r == igl::predicates::Orientation::NEGATIVE)
  24. return false;
  25. }
  26. return true;
  27. }
  28. #ifdef IGL_STATIC_LIBRARY
  29. template bool igl::predicates::point_inside_convex_polygon<Eigen::Matrix<double, -1, 2, 0, -1, 2>, Eigen::Matrix<double, 1, 2, 1, 1, 2> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> > const&);
  30. #endif