Имея точки его вершин и центроид.
На изображении я показал пример, где синяя линия представляет собой линию, вдоль которой многоугольник развивается больше всего.
Желтый кружок (извините если вы его едва видите) представляет центроид, а красный кружок представляет середину многоугольника.
Пример того, что я имею в виду:

Я пытался решить проблему, вычислив собственные векторы, связанные с наибольшим собственным значением ковариационной матрицы.
Я провел несколько тестов, и это, кажется, работает, но когда он пытается вычислить угол этого многоугольника, он возвращает значение около 80 °, тогда как то, что я ожидаемое значение равно 0°.
Неправильный результат:

Я не уверен, то ли я просто ошибся в математических расчетах, то ли в моей реализации на C# есть недостаток (показанный ниже):
// Returns the angle between the x-axis and the line along which the figure extends mainly.
public double GetOrientation()
{
Point centroid = this.GetCentroid(); // Centroid of the polygon.
int vertexesNumber = this.GetVertexesNumber(); // Number of vertexes of the polygon.
double covXX = 0.0; // Variance of x, indicates how much x varies from the mean.
double covYY = 0.0; // Variance of y, indicates how much y varies from the mean.
double covXY = 0.0; // Covariance between x and y, indicates how much x and y vary together.
// Calculates the covariance matrix, indicates how the vertexes are distributed with respect to the centroid.
foreach (Point vertex in vertexes) // For each vertex of the polygon.
{
double x = vertex.X - centroid.X; // Calculates the difference of the vertex at x from the centroid at x.
double y = vertex.Y - centroid.Y; // Calculates the difference of the vertex at y from the centroid at y.
covXX += x * x; // Adds the square of the deviation from x to the centroid.
covYY += y * y; // Adds the square of the deviation from y to the centroid.
covXY += x * y; // Adds the product of deviations from x and y.
}
covXX /= vertexesNumber; // Calculates the mean of the variance along x.
covYY /= vertexesNumber; // Calculates the mean of the variance along y.
covXY /= vertexesNumber; // Calculates the mean of the covariance between x and y.
double tr = covXX + covYY; // Calculates the trace of the matrix.
double det = covXX * covYY - covXY * covXY; // Calculates the determinant of the matrix.
double lambda = (tr + Math.Sqrt(tr * tr - 4 * det)) / 2; // Calculates the greatest eigenvalue of the matrix.
double a1 = covXY; // Calculates the component along the x-axis of the eigenvector associated with the greatest eigenvalue.
double a2 = lambda - covXX; // Calculates the component along the y-axis of the eigenvector associated with the greatest eigenvalue.
double angle = Math.Atan2(a2, a1); // Calculates the angle between the x-axis and the line along which the polygon extends mainly, defined by the vector a1, a2.
angle *= 180.0 / Math.PI; // Converts the angle from radians to degrees.
return angle;
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... -a-generic
Мобильная версия