Check if Point Is Inside A Polygon

There is a project on Github with code: https://github.com/substack/point-in-polygon (MIT license): function inside(point, vs) { // ray-casting algorithm based on // https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html/pnpoly.html var x = point[0], y = point[1]; var inside = false; for (var i = 0, j = vs.length – 1; i < vs.length; j = i++) { var xi = vs[i][0], yi … Read more

Calculate area of polygon given (x,y) coordinates

Implementation of Shoelace formula could be done in Numpy. Assuming these vertices: import numpy as np x = np.arange(0,1,0.001) y = np.sqrt(1-x**2) We can redefine the function in numpy to find the area: def PolyArea(x,y): return 0.5*np.abs(np.dot(x,np.roll(y,1))-np.dot(y,np.roll(x,1))) And getting results: print PolyArea(x,y) # 0.26353377782163534 Avoiding for loop makes this function ~50X faster than PolygonArea: %timeit … Read more

A simple algorithm for polygon intersection

I understand the original poster was looking for a simple solution, but unfortunately there really is no simple solution. Nevertheless, I’ve recently created an open-source freeware clipping library (written in Delphi, C++ and C#) which clips all kinds of polygons (including self-intersecting ones). This library is pretty simple to use: http://sourceforge.net/projects/polyclipping/ .

An algorithm for inflating/deflating (offsetting, buffering) polygons

I thought I might briefly mention my own polygon clipping and offsetting library – Clipper. While Clipper is primarily designed for polygon clipping operations, it does polygon offsetting too. The library is open source freeware written in Delphi, C++ and C#. It has a very unencumbered Boost license allowing it to be used in both … Read more