C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Calculate center for each polygon in a list efficiently

By : user2172768
Date : October 22 2020, 08:10 PM
I'm am looking for an efficient algorithm to calculate the the average of the coordinates of the corners for each element.
code :
``````SELECT element_id
, ARRAY[avg(coordinates[1]), avg(coordinates[2]), avg(coordinates[3])]
FROM   tbl -- or your org. query here
GROUP  BY 1;
``````

Share :

## Using matlab to calculate the properties of a polygon defined as a list of points

By : user2096612
Date : March 29 2020, 07:55 AM
should help you out You should check out the submission POLYGEOM by H.J. Sommer on the MathWorks File Exchange. It looks like it has all the property measurements you want, and nice documentation describing the formulae used in the code.

## How do I calculate the center of a polygon in Google Maps Android API v2?

By : ju ji
Date : March 29 2020, 07:55 AM
I wish this help you Below is the code which I am using now to find the center of polygon:-
code :
``````public static double[] centroid(List<PolyPoints> points) {
double[] centroid = { 0.0, 0.0 };

for (int i = 0; i < points.size(); i++) {
centroid[0] += points.get(i).getLatitude();
centroid[1] += points.get(i).getLongitude();
}

int totalPoints = points.size();
centroid[0] = centroid[0] / totalPoints;
centroid[1] = centroid[1] / totalPoints;

return centroid;
}
``````

## Calculte the whole center of gravity/geometric center of a polygon list

By : tamelik
Date : March 29 2020, 07:55 AM
I hope this helps . Give rgeos::gCentroid a look. You can apply it in many ways. If you have a SpatialPolygons object, say, from a call to readOGR, you can do:
code :
``````map <- readOGR(dsn, layer)
centers <- data.frame(gCentroid(map, byid=TRUE))
``````
``````library(rgdal)
library(sp)
library(PBSmapping)
library(maptools)

do.call("rbind", lapply(polys, function(x) {
calcCentroid(SpatialPolygons2PolySet(SpatialPolygons(list(Polygons(list(x), ID=1)))))
}))[,3:4]

##            X        Y
## 1  5.8108434 20.16466
## 2 -3.2619048 29.38095
## 3  5.5600000 34.72000
## 4  3.8000000 32.57037
## 5  6.3608108 32.49189
## 6 -2.2500000 31.60000
## 7 -8.1733333 27.61333
## 8  0.3082011 27.44444
## 9  8.6685714 26.78286
``````
``````do.call("rbind", lapply(polys, function(x) {
data.frame(mean(coordinates(x)[,1]), mean(coordinates(x)[,2]))
}))

##   mean.coordinates.x....1.. mean.coordinates.x....2..
## 1                  5.819892                  20.15484
## 2                 -3.242593                  29.37778
## 3                  5.539474                  34.71579
## 4                  3.815517                  32.56552
## 5                  6.323034                  32.47191
## 6                 -2.230952                  31.60000
## 7                 -8.140476                  27.61905
## 8                  0.350000                  27.40885
## 9                  8.746825                  26.92063
``````

## How to calculate area of polygon from list of points with python?

By : Saransh Group
Date : March 29 2020, 07:55 AM
around this issue I have a list/array of 2D points which form a non-convex non-self-intersecting shape. I want to calculate the area enclosed by that polygon. , use the shapely module available for both Python 2.7 and 3
code :
``````In [41]: from shapely.geometry import Polygon

In [48]: coords  = ((-1, 0), (-1, 1), (0, 0.5), (1, 1), (1, 0), (-1, 0))

In [49]: polygon = Polygon(coords)

In [50]: polygon.area
Out[50]: 1.5
``````

## Given an irregular polygon's vertex list, how to create internal triangles to build a flat 3D mesh efficiently?

By : anvesha
Date : March 29 2020, 07:55 AM
I hope this helps you . You could make use of a constrained Delaunay triangulation (which is not trivial to implement!). Good library implementations are available within Triangle and CGAL, providing efficient O(n*log(n)) implementations.
If the vertex set is small, the ear-clipping algorithm is also a possibility, although it wont necessarily give you a Delaunay triangulation (it will typically produce sub-optimal triangles) and runs in O(n^2). It is pretty easy to implement yourself though.