Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.awt.Polygon - Help with double values

843807Nov 19 2007 — edited Nov 19 2007
Hello everyone,

Hello everyone - I'm mapping latitude and longitude points to create "boundaries" - then check and see if a point is within those boundaries.

I really like java.awt.Polygon, but my coordinates are not int's, and since they vary in decimal places, I really don't want to convert them to ints - and deal with that.

The following code works - but does anyone know a better way of doing it?
public static void main(String[] args) {
    Path2D.Double d = new Path2D.Double();
    d.moveTo(39.146038,-84.571381);
    d.lineTo(39.147103,-84.325562);
    d.lineTo(39.04052,-84.348907);
    d.lineTo(39.045853,-84.605713);
    d.closePath();
    System.out.println(d.contains(39.095963,-84.468384));
}
I'd prefer to not use a third party jar for this, but wouldn't eliminate it from the possibilities. I like polygon because I don't have to start with moveTo() or finish with closePath() - it's handled automatically.

Thanks in advance for the suggestions.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 17 2007
Added on Nov 19 2007
6 comments
564 views