I'm hoping for the equivalent of CGAL (in C++)--I want convex partitioning of polygons or at least triangulation. It also has to be free. A previous question suggested JTS, but it doesn't seem to have those functions.
JTS supports delaunay triangulation, but not constrained triangulation (holes):
http://lin-ear-th-inking.blogspot.com/2009/04/delaunay-triangulation-in-jts-111.html
For constrained delaunay triangulation you can use Poly2Tri.
Works quite good, but could not triangulate polygons with holes, where the holes touch the outline or touch another polygon.
At the moment I use the OpenGl Tesselator (glut) with the java wrapper jogl (http://jogamp.org/) for triangulation in java.
You have to implement the correct callbacks and do some fiddling in there.
Neither of them satisfies all (my) needs, but until now I haven't found a better one.
GeoTools has a pretty extensive library of geometry manipulation algorithms, but of course just like JTS it is somewhat GIS-oriented.
http://www.geotools.org/
CGAL has SWIG driven bindings since 2012. 2D conforming triangulation and meshes is part of it. Please visit the github wiki for furhter info's.
You could try GeoLib which is an excellent geometry package.
Related
I have a requirement to process geojson file (it has multiple polygons) and find a given point (longitude and latitude) contains with in polygon. I am looking for a java solution. Can you please recommend possible solutions?
Thanks.
If you need more functionality than what JTS offers, you should check out GeoTools.
It provides the ability to read and write most major cartographic formats, supports map projections and coordinate transformations, and is a much more full featured GIS suite.
JTS is strictly geometry -- it deals with 2d shapes with no units attached.
When one needs a geometry library for Java JTS should be mentioned at first. And of course Java-GeoJSon to load the data. The latter library is built upon JTS, so you even don't need any special adapters between two libraries.
I'm looking for a java library for android or an algorithm description which can calculate the difference between 2 polygons. I've been looking for a few hours with no luck. Any suggestions?
Check out the JTS library. It gets tons of use in the Java GIS world, and is generally useful for solving topology problems in Java. JTS represents various topology types (including Polygons) as with a Geometry base class. Here's the method for calculating the difference between two geometries (including two polygons): http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html#difference%28com.vividsolutions.jts.geom.Geometry%29
You can download JTS from http://sourceforge.net/projects/jts-topo-suite/.
The subtraction?
Check out the Area API. It has a subtract() method.
I'm looking for a naive algorithm to find the furthest point Voronoi diagram. Input sizes are not going to be big enough where I need something complex and as there are no Java libraries that I can find.
I was hoping someone could describe a simple algorithm that shouldn't be too hard to compute?
Thanks
You can find an algorithm pseduocode for farthest-point Voronoi diagram here. The Java code written by the same person is here.
I know this is kind of a late addition, but you might want to take a look at the Tektosyne library.
It can generate Voronoi diagrams and Delaunay triangulations, with conversion to DCEL subdivisions and has support for graph algorithms like A* pathfinding, path coverage, flood fill, line of sigh.
I'm reading "Beginning Java Game Programming 2/e" and the book heavily emphasizes using AffineTransform.
There is just one problem, it doesn't explain at all what it is, what it does, and the purpose of AffineTransform.
I have done some google searches, but they're just showing me matrix math... Could someone point me in the right direction?
That's because an affine transform is matrix math. It's any kind of mapping from one image to another that you can construct by moving, scaling, rotating, reflecting, and/or shearing the image. The Java AffineTransform class lets you specify these kinds of transformations, then use them to produce modified versions of images.
Answer is years late, but if anyone else is struggling with this then I recommend reading Introduction to 3D Game Programming With DirectX 11 by Frank Luna. It is a very good book. Though book is about DirectX 11 the first three chapters are just about the math concepts needed for graphics. The chapters explains the math well and provided lots of exercises to practice the topics at the end of the chapter. (You may doing 2D games but the math is the same, the vectors and matrices have just one less dimension.)
I'm trying to create a method that will take in two arbitrary lists of nodes, for a subject and a clipping polygon, and output either:
a) the area of the overlap
b) a list of nodes for the resulting (clipped) polygon so that I can calculate the area
I've found lots of examples which clip an arbitrary polygon using a rectangular window (which is fairly standard in graphics) but that's not what I need. I understand that it's fairly complex, particularly when you get holes, convex polygons and the like. The only simplifying assumption which I can make is that the arbitrary polygons will not contain any holes.
I'm not at all an expert in this field, so would something like the Sutherland-Hodgman algorithm work? Are there any libraries out there which already do this, or is my best bet to simply implement the algorithm as described in pseudo-code on Wikipedia?
Thanks for the help!
Are there any libraries out there which already do this ...
Polygon clipping is a complex task. I wouldn't recommend trying to do it yourself unless you want to spend many months on it.
Wikipedia lists a number of clipping libraries (and IIRC in that list only Clipper is free for use in commercial applications):
http://en.wikipedia.org/wiki/Boolean_operations_on_polygons#External_links
ps: I admit to a personal bias for Clipper since I'm the author :)
More info here: http://angusj.com/delphi/clipper.php
Sounds like Weiler-Atherton is the one you need:
The algorithm requires polygons to be
clockwise and not reentrant (self
intersecting). The algorithm can
support holes (as counter-clockwise
polygons wholly inside their parent
polygon), but requires additional
algorithms to decide which polygons
are holes.
Your polygons fit those criteria, right?
I don't know about implementations, but it sounds like you would be better off implementing W-A than S-H if either of your polygons could be concave.
Try gpc.
I found that using the JavaGeom library worked very well. It integrates the code from the Java port of GPC (which is no longer available) and thus allows arbitrary polygon operations. Using SimplePolygon2D and Polygon2DUtils.intersection() I was able to get the desired operation.
I've tried a lot of different libraries and the one that worked best was the JTS Topological Suite which is pure Java and LGPL2 licensed.