' Polygon.ReturnCentroid ' Despite what ArcView's online help says, Polygon.ReturnCenter does NOT ' return the true centroid. This routine is adapted from O'Rourke, ' Computational Geometry in C. ' Arguments: thePolygon ' Returns: theCentroid (Point) thePolygon = SELF.Get(0) if (thePolygon.AsList.Count > 1) then MsgBox.Error("This routine only works with simple polygons.","Centroid") return nil end plist = thePolygon.AsPolyLine.Flip.AsMultiPoint.AsList n = plist.Count CGx = 0 CGy = 0 Areasum2 = 0 for each i in 1..(n-2) x0 = plist.Get(0).GetX y0 = plist.Get(0).GetY x1 = plist.Get(i).GetX y1 = plist.Get(i).GetY x2 = plist.Get(i+1).GetX y2 = plist.Get(i+1).GetY Cent3x = x0 + x1 + x2 Cent3y = y0 + y1 + y2 A2 = ((x1 - x0) * (y2 - y0)) - ((x2 - x0) * (y1 - y0)) CGx = CGx + (A2 * Cent3x) CGy = CGy + (A2 * Cent3y) Areasum2 = Areasum2 + A2 end CGx = CGx / (3 * Areasum2) CGy = CGy / (3 * Areasum2) return CGx@CGy