polygon

How to draw an arbitrary irregular polygon with n sides?

≡放荡痞女 提交于 2019-12-04 18:47:14
I am trying to find an algorithm of how to draw a simple (no lines are allowed to intersect), irregular polygon. The number of sides should be defined by the user, n>3 . Here is an intial code which only draws a complex polygon (lines intersect): var ctx = document.getElementById('drawpolygon').getContext('2d'); var sides = 10; ctx.fillStyle = '#f00'; ctx.beginPath(); ctx.moveTo(0, 0); for(var i=0;i<sides;i++) { var x = getRandomInt(0, 100); var y = getRandomInt(0, 100); ctx.lineTo(x, y); } ctx.closePath(); ctx.fill(); // https://stackoverflow.com/a/1527820/1066234 function getRandomInt(min,

Neighbor Polygons from List of Polygon Indices

女生的网名这么多〃 提交于 2019-12-04 18:44:46
I have a mesh in a form like this . with a list of indices representing each polygon at the end. I need to generate a list of neighboring polygons for each polygon, and was wondering if anyone knows of an efficient algorithm to do this? The simplest way that comes to mind is for each polygon, check if every other polygon has two matching indices - but this looks like it involves a few nested loops. I don't mind using this, performance isn't a huge issue here, but yeah I'm just scouting for alternatives. There isnt any limitation on the max indices/vertices per polygon, but for simplicity's

C# fill out side of a polygon

大兔子大兔子 提交于 2019-12-04 18:38:04
In c# I can fill a polygon in a bitmap image as following. using (Graphics g = Graphics.FromImage(bitmap)) { g.FillPolygon(colorBrush, points.ToArray()); } FillPolygon method fills the pixels inside the polygon, in this case, the white pixels and the black pixels remains the same. Now, I want just the opposite of this operation. That means, exterior pixels will be filled and interior pixels will remain the same. I this case, black pixels are exterior pixels. Edit I need this because let's say, I have a binary image of an object. I need to clip the pixels with background color(black) and the

How to determine a diagonal is in or out of a concave polygon?

99封情书 提交于 2019-12-04 17:44:50
The diagonal (a diagonal is a segment connecting nonadjacent vertices) of a concave (non-convex) polygon can be completely in or out of the polygon(or can intersect with the edges of polygon). How to determine whether it is completely in the polygon?( a method without point-in-polygon test ). Kamran Bigdely If the diagonal has at least one intersection with the edges, it is partially in and partially out of the polygon, however, If the diagonal has no intersection with them, there are only two states: it is compeletely in or completely out of the polygon. To determine whether it is in or out

Polygon Algorithm

十年热恋 提交于 2019-12-04 17:03:17
I'm trying to code a general algorithm that can find a polygon from the area swept out by a circle (red line) that follows some known path (green line), and where the circle gets bigger as it moves further down the known path. Basically, can anyone point me down a direction to solve this, please? I can't seem to nail down which tangent points are part of the polygon for any point (and thus circle) on the path. Any help is appreciated. Well, the easiest is to approximate your path by small segments on which your path is linear, and your circle grows linearly. Your segments and angles will

What algorithm use to find the intersection area between polygon and circle? [closed]

五迷三道 提交于 2019-12-04 17:03:02
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I have map. On the top of map layer have a polygon A and circle B. They are intersected each others. Any algorithm can calculate the area of intersection C ? Dan Anderson Assuming that you're willing to take an approximation of the circle (a polygon with a large number of sides...) then there are a bunch of algorithms to compute the result of polygon clipping (see here , for a short listing). A simple

HTML 5: Canvas copying Pixel Data within a Polygon

我怕爱的太早我们不能终老 提交于 2019-12-04 16:37:31
Good afternoon, I am new to Canvas in HTML 5 and in using it with Javascript. But I can see how powerful this really is and I needed help. I have done a search and could not find a clear answer to this. Perhaps someone here can help. I have created a context on the Canvas with a background image in place. Now, I want crop or copy a part of that image which is contained in Polygon Data and place it else where on the screen. I know how to create the background image. I know how to create a polygon over that image and I know how to copy image data to another part of the screen. So how would I

How to allow only one feature/polygon to be edited at a time with Leaflet?

荒凉一梦 提交于 2019-12-04 14:20:17
问题 It's been days I'm trying to solve my problem. I have a polygon layer from a GeoJSON. I want to edit my polygons with the click event. When I click on a polygon it becomes editable but what I want is that when I click on another polygon, the first polygon is no longer in editable mode. OpenLayers but naturally does not Leaflet. Here's an excerpt from my code: var editableLayers = new L.FeatureGroup().addTo(map); var polygon_json; $.ajax({ type: "GET", dataType: "json", url: "get_json.php",

How to draw straight lines inside google map polygon

扶醉桌前 提交于 2019-12-04 13:31:33
问题 I have created a google map using google map javascript API V3 . I am drawing number of zipcode polygons. The polygons are of different colors depending upon some condition. Now I want to draw straight lines/ hash marks inside some of the polygons depending upon certain criteria. How can we do it. Below is the code which I have written for drawing the polygons. {% if zip.zip_info.zip_polygon %} var path = [ {% for polycoord in zip.zip_info.zip_polygon %} new google.maps.LatLng({{polycoord.1}}

fast calculation of the intersection area of a triangle and the unit square

天大地大妈咪最大 提交于 2019-12-04 13:25:00
In my current project I need to calculate the intersection area of triangles and the unit squares in an infinite grid. For every triangle (given by three pairs of floating point numbers) I need to know the area (in the interval (0,1] ) it has in common with every square it intersects. Right now I convert both (the triangle and the square) to polygons and use Sutherland-Hodgman polygon clipping to calculate the intersection polygon, which I then use to calculate its area . This approach now shows to be a performance bottleneck in my application. I guess a more specialized (analytical) algorithm