I have polygon set. In this set some are exterior polygons and some may (or may not) be holes. I don't know at this stage that which are polygon holes. I want to calculate the final polygon combining all the polygons including holes.
I thought of this approach:
//'SomeLib' that has polygon boolean fucntions
var polygonSet = [poly1,poly2,...polyn];
var union, intersection;
var combinedPoly = SomeLib.XOR(polygonSet[0], polygonSet[1]);
for( var i=2; i<polygonSet.length ; i++) {
combinedPoly = SomeLib.XOR(combinedPoly, polygonSet[i]);
//or if XOR is not available
union = SomeLib.union(combinedPoly, polygonSet[i]);
intersection = SomeLib.intersection(combinedPoly, polygonSet[i]);
combinedPoly = union - intersection;
}
So my requirement for module is
List of the libraries that I came across and some points as I understood:
In some cases these functions are part of big libraries that are overloaded with other functions or libraries work with SVG or Geo-spatial environement or many are add on to existing library.
Please suggest for my requirement which library is appropriate? Are there any more javscript modular libraries for polygon boolean functions?
Boolean operations on polygons (union, intersection, difference, xor) Boolean polygon clipping/overlay operations (union, intersection, difference, xor) on Polygon and MultiPolygon geometry. Multisegments, polygons & multipolygons clipping based on algorithm by F. Martinez et al.
Martinez-Rueda polygon clipping algorithm, does boolean operation on polygons (multipolygons, polygons with holes etc): intersection, union, difference, xor Cython wrapper for the C++ translation of the Angus Johnson's Clipper library (ver. 6.4.2) This is a fairly straightforward port of the polybooljs library to the C# programming language.
A JavaScript Boolean represents one of two values: true or false. Very often, in programming, you will need a data type that can only have one of two values, like For this, JavaScript has a Boolean data type.
Four different boolean shape operations are available for this purpose. The result images are shown below: You can use Zone2::getTriangles () to conveniently extract the triangles of a zone. However, if you are rather interested in its boundary, use Zone2::getBorderEdges () to retrieve a vector of Edge2 objects.
I use my own methods that operate on SVG convex polygons:
Set Convex Polygons Counter-Clockwise Points
Polygons - Fix for Convex/CCW
Point Inside Convex Polygon: Jordan Curve Theorem
Line Intersect Polygon - vector analysis
Intersecting Polygons - vectors analysis
Composite Intersecting Polygon - Jordan Curve Theorem
Convex Polygons - Trim, Uses Sutherland-Hodgman clipping algorithm
These are shown here.
Also, you may want to check out this.
I had started implementing Vatti polygon clipping algorithm, here is the code repository. But I found Greiner Hormann polygon clipping algorithm is much better. So I am not maintaining the code now.
I recommend Greiner Hormann implementation in JavaScript for polygon clipping or other boolean operations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With