How do I efficiently determine if a polygon is convex, non-convex or complex?

You can make things a lot easier than the Gift-Wrapping Algorithm… that’s a good answer when you have a set of points w/o any particular boundary and need to find the convex hull. In contrast, consider the case where the polygon is not self-intersecting, and it consists of a set of points in a list … Read more

Check if geo-point is inside or outside of polygon

Here is a possible solution to my problem. Geographical coordinates must be stored properly. Example np.array([[Lon_A, Lat_A], [Lon_B, Lat_B], [Lon_C, Lat_C]]) Create the polygon Create the point to be tested Use polygon.contains(point) to test if point is inside (True) or outside (False) the polygon. Here is the missing part of the code: from shapely.geometry import … Read more

What is the fastest way to find the “visual” center of an irregularly shaped polygon?

I have found a very good solution to this from MapBox called Polylabel. The full source is available on their Github too. Essentially it tries to find the visual centre of the polygon as T Austin said. Certain details suggest this may be a practical solution: Unfortunately, calculating [the ideal solution ] is both complex … 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/ .

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

How to get the center of a polygon in google maps v3?

Matthew’s answer is a good solution. However, when using the Google Maps API v3, you might want to pass each point of the polygon to a LatLngBounds object through the extend() method, and then finally call the getCenter() method on the LatLngBounds object. Consider the following example: var bounds = new google.maps.LatLngBounds(); var i; // … Read more

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