polygon

Calculate the area of a polygon with latitude and longitude

断了今生、忘了曾经 提交于 2019-11-29 05:22:09
I have this code, written using this: source1 and this: source 2 public static double CalculatePolygonArea(IList<GpsLocation> coordinates) { double area = 0; if (coordinates.Count > 2) { for (var i = 0; i < coordinates.Count-1; i++) { GpsLocation p1, p2; p1 = coordinates[i]; p2 = coordinates[i + 1]; area += ToRad(p2.Longitude - p1.Longitude) * (2 + Math.Sin(ToRad(p1.Latitude)) + Math.Sin(ToRad(p2.Latitude))); area = area * R * R / 2; } } return Math.Abs(area); } Here is my test code: [Fact] public void GpsPolygonAreaTest() { var poly = new List<GpsLocation>(); var p1 = new GpsLocation(0, 0);

Library for polygon operations [closed]

天大地大妈咪最大 提交于 2019-11-29 03:52:17
问题 I've recently encountered a need for a library or set of libraries to handle operations on 2D polygons. I need to be able to perform boolean/clipping operations (difference and union) and triangulation. So far the libraries I've found are poly2tri, CGAL, and GPC. Poly2tri looks good for triangulation but I'm still left with boolean operations, and I'm unsure about its maturity. CGAL and GPC are only free if my own project is free. My particular project isn't commercial, so I'm hesitant to pay

Python: find area of polygon from xyz coordinates

左心房为你撑大大i 提交于 2019-11-29 02:52:18
问题 I'm trying to use the shapely.geometry.Polygon module to find the area of polygons but it performs all calculations on the xy plane. This is fine for some of my polygons but others have a z dimension too so it's not quite doing what I'd like. Is there a package which will either give me the area of a planar polygon from xyz coordinates, or alternatively a package or algorithm to rotate the polygon to the xy plane so that i can use shapely.geometry.Polygon().area ? The polygons are represented

Check whether a point is inside of a simple polygon

拥有回忆 提交于 2019-11-29 00:59:56
问题 I'm trying to determine whether a point is located inside of a polygon or not. I use the following (for Swift modified) algorithm from this website: func contains(polygon: [Point], test: Point) -> Bool { let count = polygon.count var i: Int, j: Int var contains = false for (i = 0, j = count - 1; i < count; j = i++) { if ( ((polygon[i].y >= test.y) != (polygon[j].y >= test.y)) && (test.x <= (polygon[j].x - polygon[i].x) * (test.y - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x)

Cutting a multipoint ploygon out of Bitmap and placing it on transparency

寵の児 提交于 2019-11-29 00:34:37
I have a bitmap out of which I'm cutting out a multipi point polygon. I'm curious what the correct process is for taking the pixels within the arbitrary shape and copying them onto a new bitmap where the rest of the pixels are transparent. The objective is to allow the user to trace the shape and then remove everything outside the polygon. I have the polygon part worked out (as a an array of points), but now am stumped as to how to transfer just the selected pixels to a new Bitmap. TIA Not sure how your code works, but here's an idea on how to do it: Calculate the bounding rectangle of the

Placing a MapLabel on top of a Polygon in Google Maps V3

拟墨画扇 提交于 2019-11-28 23:19:58
I'm trying to place a MapLabel on top of a Polygon in Google Maps V3. I've tried to set the MapLabel zIndex to 2 and the Polygon zIndex to 1 without any luck. Isn't this possible since the Polygon doesn't really follow zIndex? I've created a jsFiddle for you guys to check out: http://jsfiddle.net/7wLWe/1/ Solution: In maplabel.js change: mapPane.appendChild(canvas); to: floatPane.appendChild(canvas); The reason is because floatPane is above all map layers (pane 6) http://code.google.com/apis/maps/documentation/javascript/reference.html#OverlayView This is probably a late find.. but hope

Calculating Area of Irregular Polygon in C#

感情迁移 提交于 2019-11-28 21:37:52
I've managed to write a 'for dummies' how to calculate the area of irregular polygon in C#, but I need it to be dynamic for any amount of verticies . Can someone please help? Class: public class Vertex { private int _vertexIdx; private double _coordX; private double _coordY; private double _coordZ; public Vertex() { } public Vertex(int vertexIdx, double coordX, double coordY, double coordZ) { _vertexIdx = vertexIdx; _coordX = coordX; _coordY = coordY; _coordZ = coordZ; } public int VertexIdx { get { return _vertexIdx; } set { _vertexIdx = value; } } public double X { get { return _coordX; }

How can you find the centroid of a concave irregular polygon in JavaScript?

人走茶凉 提交于 2019-11-28 21:22:32
How can you find the centroid of a concave irregular polygon given its vertices in JavaScript? I want to pass a set of x,y points to a JavaScript function and be given an x,y point. var my_points = [{x:3,y:1},{x:5,y:8},{x:2,y:9}]; function get_polygon_centroid(points){ // answer } var my_centroid = get_polygon_centroid(my_points); The my_points variable is only supposed to represent the format of the points to be given, not to represent the specific count of points to be given . The centroid returned will be a point somewhere inside the polygon. The end goal would be to add a marker at the

Generate new polygons from a cut polygon (2D)

帅比萌擦擦* 提交于 2019-11-28 20:49:22
I'm stuck with this little problem and my algorithm to solve this doesn't hold for all cases. Does anybody has an idea how to solve this? Here's an example polygon: example http://img148.imageshack.us/img148/8804/poly.png Formal description We have a list of points in CW order defining the polygon. We also can query whether a point is a cutting point with is_cut(p) , where p is a given point. Now we want to compute new polygons caused by this "cut". The algorithm should do this: Input: {a, c1, b, c4, c, c5, d, c6, e, c3, f, c2} Output: {a, c1, c2} , {b, c4, c3, f, c2, c1} , {d, c6, c5} , {e,

Google map: Add click listener to each polygon

帅比萌擦擦* 提交于 2019-11-28 20:37:32
I am working on a webapplication. I have a google map, where I add polygons from an array. I loop through that array and add the polygons to the map. I also need to add an event listener to the polygon click and alert the position of the polygon This is what I'm doing map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); //Loop on the polygonArray for (var i = 0; i < polygonArray.length; i++) { //Add the polygon var p = new google.maps.Polygon({ paths: polygonArray[i], strokeWeight: 0, fillColor: '#FF0000', fillOpacity: 0.6, indexID: i }); p.setMap(map); //Add the click