this is because your polygon is oriented Clockwise (CW). The convention in the library is to consider point within polygon by taking into account polygon orientation. This allows working with polygon with holes.
You can solve your problem by several ways:
* check both contains and getSignedArea method. The point is isinside the enclosing area if the condition is met:
boolean z = p.contains(136.0,124.0) ^ p.getSignedArea()<0;
* use the complement of the polygon (method p.complement())
regards,
David
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using the contains() method with SimplyPolygon2D objects, and am getting inconsistent results.
Here's an example:
SimplePolygon2D p = new SimplePolygon2D();
p.addVertex(new Point2D(161.297,104.032));
p.addVertex(new Point2D(121.514,105.052));
p.addVertex(new Point2D(123.676,144.829));
p.addVertex(new Point2D(163.459,140.749));
boolean z = p.contains(136.0,124.0);
When I run this code I get z = false, which seems clearly wrong.
Any suggestions? Has anyone else had similar issues? Thank you.
Hi,
this is because your polygon is oriented Clockwise (CW). The convention in the library is to consider point within polygon by taking into account polygon orientation. This allows working with polygon with holes.
You can solve your problem by several ways:
* check both contains and getSignedArea method. The point is isinside the enclosing area if the condition is met:
boolean z = p.contains(136.0,124.0) ^ p.getSignedArea()<0;
* use the complement of the polygon (method p.complement())
regards,
David
Thanks David!
The problem is solved when I make sure the polygon is oriented counter-clockwise:
if (p.getSignedArea()<0)
p = p.complement();