def principal_direction_extent(points):
    '''Calculate the extent of a set of 3D points.

   The extent is defined as the maximum distance between
   the projections on the principal directions of the covariance matrix
   of the points.

   Parameter:
       points : a 2D numpy array of points

   Returns:
       extents : the extents for each of the eigenvectors of the cov matrix
       eigs : eigenvalues of the covariance matrix
       eigv : respective eigenvectors of the covariance matrix
    '''
    # center the points around 0.0
    points = np.copy(points)
    points -= np.mean(points, axis=0)

    # principal components
    _, eigv = pca(points)

    extent = np.zeros(3)

    for i in range(eigv.shape[1]):
        # orthogonal projection onto the direction of the v component
        scalar_projs = np.sort(np.array([np.dot(p, eigv[:, i]) for p in points]))
        extent[i] = scalar_projs[-1]

        if scalar_projs[0] < 0.:
            extent -= scalar_projs[0]

    return extent
Calculate the extent of a set of 3D points.

   The extent is defined as the maximum distance between
   the projections on the principal directions of the covariance matrix
   of the points.

   Parameter:
       points : a 2D numpy array of points

   Returns:
       extents : the extents for each of the eigenvectors of the cov matrix
       eigs : eigenvalues of the covariance matrix
       eigv : respective eigenvectors of the covariance matrix