• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java geometry - coordinates, points

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!

 
If you're gonna buy things, buy this thing and I get a fat kickback:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic