Questions tagged [polygon]

For issues relating to the creation, manipulation and rendering of polygons in graphical user interfaces.

A polygon is a two-dimensional figure that is bounded by a closed path composed of a finite sequence of straight line segments. Polygons are drawn and rendered in graphical user interfaces.

4546 questions
2017
votes
23 answers

How do CSS triangles work?

There're plenty of different CSS shapes over at CSS Tricks - Shapes of CSS and I'm particularly puzzled with a triangle: #triangle-up { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; …
Stanislav Shabalin
  • 19,028
  • 3
  • 18
  • 18
601
votes
42 answers

How can I determine whether a 2D Point is within a Polygon?

I'm trying to create a fast 2D point inside polygon algorithm, for use in hit-testing (e.g. Polygon.contains(p:Point)). Suggestions for effective techniques would be appreciated.
331
votes
25 answers

How to determine if a list of polygon points are in clockwise order?

Having a list of points, how do I find if they are in clockwise order? For example: point[0] = (5,0) point[1] = (6,4) point[2] = (4,5) point[3] = (1,5) point[4] = (1,0) would say that it is anti-clockwise (or counter-clockwise, for some people).
Stécy
  • 11,951
  • 16
  • 64
  • 89
241
votes
15 answers

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

How would I "inflate" a polygon? That is, I want to do something similar to this: The requirement is that the new (inflated) polygon's edges/points are all at the same constant distance from the old (original) polygon's (on the example picture they…
Igor Brejc
  • 18,714
  • 13
  • 76
  • 95
112
votes
5 answers

Check if Point Is Inside A Polygon

I want to check if a point lies within a specific polygon. The polygon is: polygon= [ [-73.89632720118, 40.8515320489962], [-73.8964878416508, 40.8512476593594], [-73.8968799791431, 40.851375925454], …
user3378649
  • 5,154
  • 14
  • 52
  • 76
112
votes
9 answers

Extract points/coordinates from a polygon in Shapely

How do you get/extract the points that define a shapely polygon? Thanks! Example of a shapely polygon from shapely.geometry import Polygon # Create polygon from lists of points x = [list of x vals] y = [list of y vals] polygon = Polygon(x,y)
ryanjdillon
  • 17,658
  • 9
  • 85
  • 110
79
votes
13 answers

Calculate area of polygon given (x,y) coordinates

I have a set of points and would like to know if there is a function (for the sake of convenience and probably speed) that can calculate the area enclosed by a set of points. for example: x = np.arange(0,1,0.001) y = np.sqrt(1-x**2) points =…
pbreach
  • 16,049
  • 27
  • 82
  • 120
76
votes
8 answers

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

It doesn't need to be 100% correct, it can be the center of the bounding rectangle.
ANd
  • 1,155
  • 2
  • 10
  • 8
76
votes
10 answers

A simple algorithm for polygon intersection

I'm looking for a very simple algorithm for computing the polygon intersection/clipping. That is, given polygons P, Q, I wish to find polygon T which is contained in P and in Q, and I wish T to be maximal among all possible polygons. I don't mind…
Elazar Leibovich
  • 32,750
  • 33
  • 122
  • 169
64
votes
6 answers

SciPy Create 2D Polygon Mask

I need to create a numpy 2D array which represents a binary mask of a polygon, using standard Python packages. input: polygon vertices, image dimensions output: binary mask of polygon (numpy 2D array) (Larger context: I want to get the distance…
Isaac Sutherland
  • 3,082
  • 4
  • 28
  • 37
63
votes
15 answers

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

I need to find a point that is a visual center of an irregularly shaped polygon. By visual center, I mean a point that appears to be in the center of a large area of the polygon visually. The application is to put a label inside the polygon. Here is…
Mikhil
62
votes
4 answers

Check if geo-point is inside or outside of polygon

I am using python and I have defined the latitudes and longitudes (in degrees) of a polygon on the map. My goal is to check if a generic point P of coordinates x,y falls within such polygon. I would like therefore to have a function that allows me…
Federico Gentile
  • 5,650
  • 10
  • 47
  • 102
60
votes
10 answers

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

From the man page for XFillPolygon: If shape is Complex, the path may self-intersect. Note that contiguous coincident points in the path are not treated as self-intersection. If shape is Convex, for every pair of points inside the polygon, the…
hhafez
  • 38,949
  • 39
  • 113
  • 143
58
votes
4 answers

How to draw free hand polygon in Google map V2 in Android?

I want to draw a Free Hand Polygon on the Map in Google Map V2. This task was possible with Overlay Map V1 but Google Map has removed that class from V2. (Per this Google Map V2 has Remove Overlay Class). Good Example for Google Map V1 to draw free…
Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
56
votes
7 answers

How to calculate rounded corners for a polygon?

I'm looking for an algorithm that allows me to create rounded corners from a polygon. I have an array of points that represents the polygon (outlined in red) and on output I want an array of points that represents the polygon with rounded corners…
ZouBi
  • 763
  • 1
  • 7
  • 17
1
2 3
99 100