Sunday, December 13, 2009

VB.Net Find Center of a Polygon

Private Function CenterOfPolygon(ByRef _pointf() As PointF) As PointF
CenterOfPolygon = New Point(0, 0)

Dim total_points As Integer = _pointf.Length
Dim x_total As Single = 0, y_total As Single = 0
For Each _point As PointF In _pointf
x_total = x_total + _point.X
y_total = y_total + _point.Y
Next

CenterOfPolygon.X = x_total / total_points
CenterOfPolygon.Y = y_total / total_points

End Function

No comments:

Post a Comment