Evaluation of the aspect ratio of a convex hull

What would be the best way to approximate the aspect ratio of a convex hull in Python? I already tried to do this by setting the vertices of the convex hull with an ellipse and assuming the ratio of the semi-axis and the main axis. However, the results are not satisfactory, so I am now studying the derivation of the aspect ratio directly from the convex hull. Any ideas or solutions would be highly appreciated.

Greetings

+6
source share
1 answer

As a rule, you will find the eigenvectors of the covariance matrix of a point cloud. Aspect ratio is the ratio of the largest to the smallest number of eigenvalues.

As an example, for a bunch of random points (you would apply the same thing to your convex hull using only vertices):

import matplotlib.pyplot as plt import numpy as np # Random data num = 100 xy = np.random.random((2,num)) + 0.01 * np.arange(num) eigvals, eigvecs = np.linalg.eig(np.cov(xy)) fig, (ax1, ax2) = plt.subplots(nrows=2) x,y = xy center = xy.mean(axis=-1) for ax in [ax1, ax2]: ax.plot(x,y, 'ro') ax.axis('equal') for val, vec in zip(eigvals, eigvecs.T): val *= 2 x,y = np.vstack((center + val * vec, center, center - val * vec)).T ax2.plot(x,y, 'b-', lw=3) plt.show() 

enter image description here

+7
source

Source: https://habr.com/ru/post/895034/


All Articles