polygon

SciPy Create 2D Polygon Mask

与世无争的帅哥 提交于 2019-11-26 12:06:52
问题 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 transform of this polygon using scipy.ndimage.morphology.distance_transform_edt.) Can anyone show me how to do this? 回答1: The answer turns out to be quite simple: import numpy from PIL import Image, ImageDraw # polygon = [(x1,y1),(x2,y2),...] or [x1,y1

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

我是研究僧i 提交于 2019-11-26 11:36:40
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 style polygon. In Map V2, we can draw a polygon programmatically with the help of Google Official Doc but what should a user do? I have found Unclear answer for Map V2 I started with simple Google Map & draw polygon to do this programmatically & it is working properly but now I am looking for how a user can draw? I don't want to draw based on the

How do I determine if two convex polygons intersect?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 11:11:45
问题 Suppose there are a number of convex polygons on a plane, perhaps a map. These polygons can bump up against each other and share an edge, but cannot overlap. To test if two polygons P and Q overlap, first I can test each edge in P to see if it intersects with any of the edges in Q . If an intersection is found, I declare that P and Q intersect. If none intersect, I then have to test for the case that P is completely contained by Q , and vice versa. Next, there\'s the case that P == Q .

How to test if a point is inside of a convex polygon in 2D integer coordinates?

早过忘川 提交于 2019-11-26 10:58:45
问题 The polygon is given as a list of Vector2I objects (2 dimensional, integer coordinates). How can i test if a given point is inside? All implementations i found on the web fail for some trivial counter-example. It really seems to be hard to write a correct implementation. The language does not matter as i will port it myself. 回答1: If it is convex, a trivial way to check it is that the point is laying on the same side of all the segments (if traversed in the same order). You can check that

Polygon enclosing a set of points

∥☆過路亽.° 提交于 2019-11-26 10:58:22
问题 I have a set S of points (2D : defined by x and y) and I want to find P, the smallest (meaning : with the smallest number of points) polygon enclosing all the points of the set, P being an ordered subset of S. Are there any known algorithms to compute this? (my lack of culture in this domain is astonishing...) Thanks for your help 回答1: There are many algorithms for this problem. It is called "minimum bounding box". You will find solutions too searching for "convex hull", especially here. One

How to intersect two polygons?

允我心安 提交于 2019-11-26 10:22:09
问题 This seems non-trivial (it gets asked quite a lot on various forums), but I absolutely need this as a building block for a more complex algorithm. Input : 2 polygons (A and B) in 2D, given as a list of edges [(x0, y0, x1, y2), ...] each. The points are represented by pairs of double s. I do not know if they are given clockwise, counter-clockwise or in any direction at all. I do know that they are not necessarily convex. Output : 3 polygons representing A, B and the intersecting polygon AB.

How to determine if a point is inside a 2D convex polygon?

我怕爱的太早我们不能终老 提交于 2019-11-26 08:04:50
问题 I have a convex polygon (typically just a rotated square), and I know all of 4 points. How do I determine if a given point (yellow/green) is inside the polygon? EDIT: For this particular project, I don\'t have access to all of the libraries of the JDK, such as AWT. 回答1: This page: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html shows how to do this for any polygon. I have a Java implementation of this, but it is too big to post here in its entirety. However, you should

How to fill geom_polygon with different colors above and below y = 0?

穿精又带淫゛_ 提交于 2019-11-26 07:46:46
问题 Considering the following polygon plot: ggplot(df, aes(x=year,y=afw)) + geom_polygon() + scale_x_continuous(\"\", expand=c(0,0), breaks=seq(1910,2010,10)) + theme_bw() However, i want to fill this with two different colors. For example red for the black areas above 0 and blue for the black areas below 0 . Unfortunately, using fill=col doesn\'t fill the correct areas. I tried the following code (I added the geom_line in order to illustrate where the border of the fill should be): ggplot(df,

Check if point is in spatial object which consists of multiple polygons/holes

帅比萌擦擦* 提交于 2019-11-26 07:39:26
问题 I have a SpatialPolygonsDataFrame with 11589 objects of class \"polygons\". 10699 of those objects consists of exactly 1 polygon, however the rest of those objects consists of multiple polygons (2 to 22). If an object of consists of multiple polygons, three scenarios are possible: Sometimes, those additional polygons describe a \"hole\" in the geographic ara describe by the first polygon in the object of class \"polygons\". Sometimes, those additional polygons describe additional geographic

Google Maps v3: check if point exists in polygon

走远了吗. 提交于 2019-11-26 07:26:52
问题 I am looking to find a way of checking if a point exists inside a polygon in Google Maps v3 (JavaScript). I\'ve searched everywhere and the only solutions I have found so far have been to do with getting the bounds of the polygon, but the code shown seems to just create a rectangle and keeps expanding its surface area to include all relevant points. By the way, the reason I can\'t just use a big square i.e. getting a polygons bounds, is that I have bordering polygons on the map and they can