How do I calculate centroid of a polygon if the vertices of the polygon are given?
By : user3287331
Date : March 29 2020, 07:55 AM
Hope that helps http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon , I see the following issues: ar, x, and y are not initialized. code :
x+=((p[i].first+p[i+1].first)*ar);
y+=((p[i].second+p[i+1].second)*ar);
for(i=0;i<points1;i++)
int main()
{
int points;
scanf("%d",&points);
pair<float,float>p[points];
int i;
for(i=0;i<points;i++)
{
scanf("%f %f",&p[i].first,&p[i].second);
}
float ar = 0.0;
float x = 0.0;
float y = 0.0;
for(i=0;i<points;i++)
{
// This allows wraparound when are you dealing with
// the last point in the list.
int j = (i+1)%points;
float common = (p[i].first*p[j].second  p[j].first*p[i].second);
ar += common;
x+=(p[i].first+p[j].first)*common;
y+=(p[i].second+p[j].second)*common;
}
ar *= 0.5;
x /= (6*ar);
y /= (6*ar);
printf("area: %.2f, xc: %.2f, yc: %.2f\n", ar, x, y);
}

Google Maps JavaScript API  Create Polygon from Polylines Snapped to Road
By : iOS Developer
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Change the google.maps.Polyline to a google.maps.Polygon. code :
var traceroadTrip1 = new google.maps.Polygon({
path: roadTrip1,
strokeColor: "red",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
function initialize() {
var pos = new google.maps.LatLng(29.813047, 95.399361);
var myOptions = {
zoom: 11,
center: pos,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), myOptions);
map.setCenter(pos);
roadTrip1 = [
new google.maps.LatLng(29.692093, 95.377307),
new google.maps.LatLng(29.813047, 95.399361),
new google.maps.LatLng(29.692093, 95.377307)
];
var traceroadTrip1 = new google.maps.Polygon({
path: roadTrip1,
strokeColor: "red",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
var service1 = new google.maps.DirectionsService(),
traceroadTrip1, snap_path = [];
var bounds = new google.maps.LatLngBounds();
traceroadTrip1.setMap(map);
for (j = 0; j < roadTrip1.length  1; j++) {
service1.route({
origin: roadTrip1[j],
destination: roadTrip1[j + 1],
travelMode: google.maps.DirectionsTravelMode.DRIVING
}, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
snap_path = snap_path.concat(result.routes[0].overview_path);
traceroadTrip1.setPath(snap_path);
for (var i = 0; i < traceroadTrip1.getPath().getLength(); i++) {
bounds.extend(traceroadTrip1.getPath().getAt(i));
}
map.fitBounds(bounds);
}
});
}
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map"></div>

Calculate if circle fits inside of polygon (triangle/pentagon) given coordinates where touching the polygon is allowed?
By : Jeff Yoak
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The following assumes you already know that the center of the circle is inside the polygon. There are a few things you want to check as your definition that touching the vertices is ok adds some cornercases. This solution works for concave polygons as well. Early check

How to calculate area of lots of polygon where each polygon has different coordinates
By : user3094072
Date : March 29 2020, 07:55 AM
it fixes the issue Suppose I know 700 different values of x as well as another 700 different values of y coordinates. Every 7 points from my coordinates can construct a polygon. I can easily pick any formula (here I have used shoelace formula) to calculate the area of any polygon. But it's really tough to calculate area of each polygon in this way, is there any good way by which I can calculate the area of all polygon (for this case the total number of polygon is 100) at a time, e.g. by using any iteration. , Here's a vectorized way to get polygon areas for all  code :
X = x.reshape(1,7)
Y = y.reshape(1,7)
Xr = np.roll(X,1,axis=1)
Yr = np.roll(Y,1,axis=1)
p1 = np.einsum('ij,ij>i',X,Xr)
p2 = np.einsum('ij,ij>i',Y,Yr)
Area_out = (p1p2)/2
p1 = np.matmul(X[:,None,:],Xr[:,:,None])[:,0,0]
p1 = (X[:,None,:]@Xr[:,:,None])[:,0,0]
p1 = np.einsum('ij,ij>i',X[:,:1],X[:,1:]) + X[:,0]*X[:,1]
p2 = np.einsum('ij,ij>i',Y[:,:1],Y[:,1:]) + Y[:,0]*Y[:,1]
p1 = np.matmul(X[:,None,:1],X[:,1:,None])[:,0,0] + X[:,0]*X[:,1]

How Do I Calculate the Area of a Polygon in a MySQL Database When the Polygon's Points are Lat Longs?
By : deendas
Date : March 29 2020, 07:55 AM
To fix this issue You've got to transform those lats and lons into a more appropriate coordinate system. Since the earth is a sphere, you're talking about calculating an area in spherical coordinates.

