• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java geometry - coordinates, points

 
Adam Schaible
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



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.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
boolean contains(double x, double y) in the java.awt Interface Shape and has methods to determine whether points or rectangles lie partly or entirely within the interior of the Shape.

Additionally the method boolean contains(double x, double y) can accept floating point values.
 
Adam Schaible
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked at java.awt.Shape - the interface definately does have methods that determine if a given shape contains a point that can be expressed by a pair of doubles.

My problem is that the interface doesn't define how points are added - and I've yet to find an implementation that works as easily as Polygon but accepts double's as point coordinates.
 
Adam Schaible
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have yet to find a class that works for me, so I made a quick and dirty implementation of Polygon for double values. It's a minimalistic approach, but posting for others. If someone knows a better class, please let me know!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic