Autoguidage
Posté : 02 décembre 2014, 16:50
Bonjour, soyez les bienvenues sur le groupe des amateurs d'astronomie.
https://astronomie.madtiger.fr:4443/
Code : Tout sélectionner
/// <summary>
/// Method to compute the centroid of a polygon. This does NOT work for a complex polygon.
/// </summary>
/// <param name="poly">points that define the polygon</param>
/// <returns>centroid point, or PointF.Empty if something wrong</returns>
public static PointF GetCentroid(List<PointF> 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 (accumulatedArea < 1E-7f)
return PointF.Empty; // Avoid division by zero
accumulatedArea *= 3f;
return new PointF(centerX / accumulatedArea, centerY / accumulatedArea);
}
Code : Tout sélectionner
public static Point GetCentroid( Point[ ] nodes, int count )
{
int x = 0, y = 0, area = 0, k;
Point a, b = nodes[ count - 1 ];
for( int i = 0; i < count; i++ )
{
a = nodes[ i ];
k = a.Y * b.X - a.X * b.Y;
area += k;
x += ( a.X + b.X ) * k;
y += ( a.Y + b.Y ) * k;
b = a;
}
area *= 3;
return ( area == 0 ) ? Point.Empty : new Point( x /= area, y /= area );
}
Code : Tout sélectionner
Image I avec n_r lignes et n_c colones
cent_r, cent_c, sum = 0
for i from 0 to (n_r - 1)
for j from 0 to (n_c - 1)
cent_r += î[i,j] * (i + 1)
cent_c += î[i,j] * (j + 1)
sum += I[i,j]
cent_r /= sum
cent_c /= sum