Polygon 1 (innen) mit
"X: 2590431 Y: 5823888"
"X: 2590433 Y: 5823881"
"X: 2590439 Y: 5823883"
"X: 2590439 Y: 5823885"
Polygon 2 (außen) mit
"X: 2590431,90722877 Y: 5823888,13312532"
"X: 2590433,4463628 Y: 5823881,72434687"
"X: 2590439,73619589 Y: 5823883,76414255"
"X: 2590439,32130088 Y: 5823885,79535345"
Warum und wie kann der Schwerpunkt außerhalb liegen? Ich will nur verstehen.
Zur Berechnung der Schwerpunkte habe ich verwendet
Code: Select all
///
/// Method to compute the centroid of a polygon. This does NOT work for a complex polygon.
///
/// points that define the polygon
/// centroid point, or PointF.Empty if something wrong
public static PointF GetCentroid(List poly)
{
float accumulatedArea = 0.0f;
float centerX = 0.0f;
float centerY = 0.0f;
for (int i = 0, j = poly.Count - 1; i < poly.Count; j = i++)
{
float temp = poly[i].X * poly[j].Y - poly[j].X * poly[i].Y;
accumulatedArea += temp;
centerX += (poly[i].X + poly[j].X) * temp;
centerY += (poly[i].Y + poly[j].Y) * temp;
}
if (Math.Abs(accumulatedArea) < 1E-7f)
return PointF.Empty; // Avoid division by zero
accumulatedArea *= 3f;
return new PointF(centerX / accumulatedArea, centerY / accumulatedArea);
}
Mobile version