polygons

Implementing a brute force algorithm for detecting a self-intersecting polygon

可紊 提交于 2019-11-30 07:58:35
I initially implemented the Hoey-Shamos algorithm, however it is too complex for future maintainability (I have no say in this), and it wasn't reporting correctly, so an optimized brute force algorithm is what I'm going to use. My question is: How can I optimize this code to be usable? As it stands, my code contains a nested for loop, iterating the same list twice. EDIT: Turned lines into a HashSet and used two foreach loops... shaved about 45 seconds off scanning 10,000. It's still not enough. foreach (Line2D g in lines) { foreach (Line2D h in lines) { if (g.intersectsLine(h)) { return false;

Check if Polygon is Self-Intersecting

若如初见. 提交于 2019-11-30 03:24:59
I have a System.Windows.Shapes.Polygon object, whose layout is determined completely by a series of Points. I need to determine if this Polygon is self intersecting; i.e., if any of the sides of the polygon intersect any of the other sides at a point which is not a vertex. Is there an easy/fast way to compute this? Easy, slow, low memory footprint : compare each segment against all others and check for intersections. Complexity O(n 2 ) . Slightly faster, medium memory footprint (modified version of above): store edges in spatial "buckets", then perform above algorithm on per-bucket basis.

Finding adjacent polygons in R (neighbors)

佐手、 提交于 2019-11-29 21:33:36
I'm starting with a SpatialPolygonsDataFrame which has the data to create a map of the districts of Ghana (available at http://www.diva-gis.org/datadown ). I'm trying to create a matrix with the names of the districts as row and column names and 0s/1s in the interior to indicate if two districts are adjacent (neighboring) or not. I've found several functions in spdep that seem promising, but I can't figure out how to use them for this purpose. I was able to create a "nb" file with the data using poly2nb, but am unsure how to proceed from here or even if I'm on the right track. I'd really

draw a smooth polygon around data points in a scatter plot, in matplotlib

偶尔善良 提交于 2019-11-29 20:38:40
问题 I have a bunch of cross plots with two sets of data and have been looking for a matploltib way of highlighting their plotted regions with smoothed polygon outlines. At the moment i just use Adobe Illustrator and amend saved plot, but this is not ideal. Example: I'd be grateful for any pointers/links to examples. Cheers 回答1: Here, you have an example. I was written the main ideas, but obviously, you could do it better. A short explanations: 1) You need to compute the convex-hull (http://en

Holes in a Polygon

落花浮王杯 提交于 2019-11-29 18:12:33
First off to those that want to make a comment about my low acceptance rating...im new, give me a break. I added this polygon code from this website: http://www.geocodezip.com/v3_polygon_example_donut.html There is an issue though, the radius is not accurate. So if I measure the distance between 2 cities, then draw this circle, it is way off, and gets worse the larger the circle. Any ideas? <script type="text/javascript"> function drawCircle(point, radius, dir) { var d2r = Math.PI / 180; // degrees to radians var r2d = 180 / Math.PI; // radians to degrees var earthsradius = 3959; // 3959 is

How to fill a polygon with a custom hatch in matplotlib?

孤者浪人 提交于 2019-11-29 12:49:12
问题 I'm using python and matplotlib to create several closed polygons. I then need to fill them with a hatch, which can be done through set_hatch. http://matplotlib.org/api/artist_api.html#matplotlib.patches.Patch.set_hatch http://matplotlib.org/examples/pylab_examples/hatch_demo.html Unfortunately I am working with greyscale images, and I need more hatches than provided by default - I would prefer to provide a bitmap (or some similar image) which could be tiled instead of using these hatches

Implementing a brute force algorithm for detecting a self-intersecting polygon

房东的猫 提交于 2019-11-29 10:24:47
问题 I initially implemented the Hoey-Shamos algorithm, however it is too complex for future maintainability (I have no say in this), and it wasn't reporting correctly, so an optimized brute force algorithm is what I'm going to use. My question is: How can I optimize this code to be usable? As it stands, my code contains a nested for loop, iterating the same list twice. EDIT: Turned lines into a HashSet and used two foreach loops... shaved about 45 seconds off scanning 10,000. It's still not

How to simplify a single complex UIBezierPath polygon in iOS

半腔热情 提交于 2019-11-29 04:33:10
Problem: I have a user generated polygon (via registering user's touches on screen) which can be simple or complex (complex means having unknown number of intersections) and I want to have a simple polygon resulting from the same points on the original polygon, something like an outline or a contour if you will. Possible solutions: I have found this , but it is a JavaScript solution and this is a perfect illustration of what I need but in ActionScript! I don't need the Path itself, the points will suffice. How would you approach such problem? Update: As I was looking further around, I have

Voronoi diagram polygons enclosed in geographic borders

人走茶凉 提交于 2019-11-28 20:46:38
I am trying to create Voronoi polygons (aka Dirichlet tessellations or Thiessen polygons) within a fixed geographic region for a set of points. However, I am having trouble finding a method in R that will bound the polygons within the map borders. My main goal is to get accurate area calculations (not simply to produce a visual plot). For example, the following visually communicates what I'm trying to achieve: library(maps) library(deldir) data(countyMapEnv) counties <- map('county', c('maryland,carroll','maryland,frederick', 'maryland,montgomery', 'maryland,howard'), interior=FALSE) x <- c(

Getting a bounded polygon coordinates from Voronoi cells

…衆ロ難τιáo~ 提交于 2019-11-28 20:46:23
I have points (e.g., lat, lon pairs of cell tower locations) and I need to get the polygon of the Voronoi cells they form. from scipy.spatial import Voronoi tower = [[ 24.686 , 46.7081], [ 24.686 , 46.7081], [ 24.686 , 46.7081]] c = Voronoi(towers) Now, I need to get the polygon boundaries in lat,lon coordinates for each cell (and what was the centroid this polygon surrounds). I need this Voronoi to be bounded as well. Meaning that the boundaries don't go to infinity, but rather within a bounding box. Given a rectangular bounding box, my first idea was to define a kind of intersection