| |
| |
| |
| |
| |
| |
| |
|
|
| #include "segment_segment_intersect.h" |
|
|
| |
| template <typename DerivedP> |
| IGL_INLINE bool igl::predicates::segment_segment_intersect( |
| const Eigen::MatrixBase<DerivedP>& a, |
| const Eigen::MatrixBase<DerivedP>& b, |
| const Eigen::MatrixBase<DerivedP>& c, |
| const Eigen::MatrixBase<DerivedP>& d |
| ) |
| { |
| typename DerivedP::Scalar Scalar; |
| |
| auto t1 = igl::predicates::orient2d(a,b,c); |
| auto t2 = igl::predicates::orient2d(b,c,d); |
| auto t3 = igl::predicates::orient2d(a,b,d); |
| auto t4 = igl::predicates::orient2d(a,c,d); |
|
|
| |
| auto on_segment = []( |
| const Eigen::MatrixBase<DerivedP>& m, |
| const Eigen::MatrixBase<DerivedP>& n, |
| const Eigen::MatrixBase<DerivedP>& p |
| ){ |
| return ((p(0) >= std::min(m(0),n(0))) && |
| (p(0) <= std::max(m(0),n(0))) && |
| (p(1) >= std::min(m(1),n(1))) && |
| (p(1) <= std::max(m(1),n(1)))); |
| }; |
| |
| |
| if((t1 == igl::predicates::Orientation::COLLINEAR && on_segment(a,b,c)) || |
| (t2 == igl::predicates::Orientation::COLLINEAR && on_segment(c,d,b)) || |
| (t3 == igl::predicates::Orientation::COLLINEAR && on_segment(a,b,d)) || |
| (t4 == igl::predicates::Orientation::COLLINEAR && on_segment(c,d,a))) |
| return true; |
| |
| |
| return (t1 != t3 && t2 != t4); |
| } |
|
|
| #ifdef IGL_STATIC_LIBRARY |
| template bool igl::predicates::segment_segment_intersect<Eigen::Matrix<double, 1, 2, 1, 1, 2> >(Eigen::MatrixBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> > const&); |
| #endif |
|
|