summaryrefslogtreecommitdiff
path: root/gaunt01/src/outsidePolygon.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-04-19 09:41:27 +0100
committerTim Redfern <tim@eclectronics.org>2012-04-19 09:41:27 +0100
commit98437cad0a3a59245e5fe772d4e310de4228757a (patch)
treedaca14fc20fc354d9225b2608541f2590bff4136 /gaunt01/src/outsidePolygon.cpp
parent7eb7b1a64d5a22ae707c0a9d4115cb3c326f472f (diff)
cleaning up
Diffstat (limited to 'gaunt01/src/outsidePolygon.cpp')
-rw-r--r--gaunt01/src/outsidePolygon.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/gaunt01/src/outsidePolygon.cpp b/gaunt01/src/outsidePolygon.cpp
new file mode 100644
index 0000000..8f9b61e
--- /dev/null
+++ b/gaunt01/src/outsidePolygon.cpp
@@ -0,0 +1,35 @@
+#include "outsidePolygon.h"
+
+
+bool OutsidePolygon(vector<ofPoint>& polygon,ofPoint p)
+//thanks to Paul Bourke
+//http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/
+{
+ int counter = 0;
+ int i;
+ double xinters;
+ ofPoint p1,p2;
+
+ p1 = polygon[0];
+ for (i=1;i<=polygon.size();i++) {
+ p2 = polygon[i % polygon.size()];
+ if (p.y > min(p1.y,p2.y)) {
+ if (p.y <= max(p1.y,p2.y)) {
+ if (p.x <= max(p1.x,p2.x)) {
+ if (p1.y != p2.y) {
+ xinters = (p.y-p1.y)*(p2.x-p1.x)/(p2.y-p1.y)+p1.x;
+ if (p1.x == p2.x || p.x <= xinters)
+ counter++;
+ }
+ }
+ }
+ }
+ p1 = p2;
+ }
+
+ if (counter % 2 == 0)
+ return true;
+ else
+ return false;
+}
+