Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Java geometry - coordinates, points Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java geometry - coordinates, points" Watch "Java geometry - coordinates, points" New topic
Author

Java geometry - coordinates, points

Adam Schaible
Ranch Hand

Joined: Oct 04, 2007
Posts: 101
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

Joined: Sep 17, 2006
Posts: 1282
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.


"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Adam Schaible
Ranch Hand

Joined: Oct 04, 2007
Posts: 101
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

Joined: Oct 04, 2007
Posts: 101
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!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java geometry - coordinates, points
 
Similar Threads
Line has two points: asociation or composition?
graph
Display a set of data in graphics format.
Problems moving shapes when set up own Shapes class extending Path2D.Double
Why won't my program draw the line