This is a late answer, but it can be done using the Javascript Clipper Library . The desired operation is Simplification (which internally uses the Union operation), and it removes the self-intersections where the edge intersects the other edges (s).
Attention! Javascript Clipper 5 cannot guarantee that in all cases the solution consists only of really simple polygons. This, as a special case, is the vertices touching the edges. Clipper 6 (the Javascript version is not ready yet) can handle them as special cases.
Simplify polygons using the Javascript Clipper main editor
You can play with Clipper using the Javascript Clipper Main Demo . Click "Polygons-Custom", and you can enter your own polygon and perform the necessary operations.
Take your example:
[[7.86, 196.24, 199.177, 47.169, 51.21, 224.102, 223.146, 7.40, 7.86]]
If you enter these points in a demo (like a theme or a clip), you get the following polygon:
Then do the Simplify operation, which produces the following solution:
If you click Solution in Polygon Explorer, you will see the coordinates of the simplified polygon: [[199,177, 47,169, 47,75,141,13, 7,144, 7,86, 49,62,72,02, 51,21, 114,51,50, 73, 196.24, 197.28.89.49, 224.102, 223.146, 198.38,145.32]]
Simplifying Polygon Code Example
And finally, I put the full functional code in JSBIN , which includes the SVG drawing functions and is therefore quite long:
<html> <head> <title>Javascript Clipper Library / Simplifying Polygons</title> <script src="clipper.js"></script> <script> function draw() { var subj_polygons = [[{"X":7,"Y":86},{"X":196,"Y":24},{"X":199,"Y":177},{"X":47,"Y":169},{"X":51,"Y":21},{"X":224,"Y":102},{"X":223,"Y":146},{"X":7,"Y":140},{"X":7,"Y":86}]]; var scale = 100; subj_polygons = scaleup(subj_polygons, scale); var cpr = new ClipperLib.Clipper(); cpr.AddPolygons(subj_polygons, ClipperLib.PolyType.ptSubject); var solution_polygons = new ClipperLib.Polygons(); solution_polygons = cpr.SimplifyPolygons(subj_polygons, ClipperLib.PolyFillType.pftNonZero); </script> </head> <body onload="draw()"> <h2>Javascript Clipper Library / Simplifying Polygons</h2> This page shows an example of simplifying polygon and drawing it using SVG. <div id="svgcontainer"></div> </body> </html>