From 75aca76eb7f54a34b07711c4339b27faec834808 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Thu, 12 Jan 2012 00:53:37 +0000 Subject: [PATCH] Added PointInsidePolygon function --- vcg/space/intersection2.h | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/vcg/space/intersection2.h b/vcg/space/intersection2.h index 58ae7117..366287d0 100644 --- a/vcg/space/intersection2.h +++ b/vcg/space/intersection2.h @@ -253,6 +253,46 @@ namespace vcg { } return false; } + + template + bool PointInsidePolygon(vcg::Point2 p, + const std::vector > &polygon) + { + int n=polygon.size(); + vcg::Box2 BB; + for (int i=0;i r; + vcg::Point2 direct=vcg::Point2(0,0); + switch (dir) + { + case 0 : direct.X()=1;break; + case 1 : direct.Y()=1;break; + case 2 : direct.X()=-1; break; + default :direct.Y()=-1; + } + r.SetOrigin(p); + r.SetDirection(direct); + for (int i=0;i p_inters; + if (vcg::RaySegmentIntersection(r,polygon[i],p_inters))intersection++; + } + if ((intersection%2)==1) + inside_test++; + } + return(inside_test>2); + } //intersection between a circle and a line template