point_inside_convex_polygon.cpp 1.4 KB

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