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 centroid of a polygon in a Google Maps V3 application.