I have found a nice example how to find the center point of a polygon (and here in JS):
-> See this jsfiddle example
So, with this polygon
var polygon = [
{'x':770, 'y':400},
{'x':529, 'y':643},
{'x':320, 'y':494},
{'x':424, 'y':381},
{'x':459, 'y':369}
];
I should find the center point like so:
var con = new Contour();
con.pts = polygon;
document.write(con.centroid)
But con.centroid is undefined.
What am I doing wrong?
Thanks in advance!
You call the
Contourconstructor way before theContourprototype has been defined. In the said jsfiddle, move yourdocument.writeto the end, and all will go… better.Also, you need to actually call the
centroidfunction you defined: