Skip to content

convex_hull

ray_hull_intersections(directions, hull, method='fast')

Find the distance from the origin to the intersection with the given ConvexHull for a list of directions. Assumes directions is a (N, 3) array of unit vectors representing directions, and hull is a ConvexHull object centered about the origin.

Parameters:

Name Type Description Default
directions ndarray

(N, 3) array of unit vectors

required
hull ConvexHull

A ConvexHull for which to find intersections

required

Returns:

Type Description

np.ndarray: (N,) array of the distances for each intersection

Source code in chmpy/shape/convex_hull.py
def ray_hull_intersections(directions, hull, method="fast"):
    """
    Find the distance from the origin to the intersection with the 
    given ConvexHull for a list of directions. Assumes `directions`
    is a (N, 3) array of unit vectors representing directions, and
    `hull` is a `ConvexHull` object centered about the origin.


    Args:
        directions (np.ndarray): (N, 3) array of unit vectors
        hull (ConvexHull): A ConvexHull for which to find intersections


    Returns:
        np.ndarray: (N,) array of the distances for each intersection
    """
    if method == "fast":
        return _ray_hull_intersections_batch(directions, hull)
    else:
        return np.array([_ray_hull_intersection(p, hull) for p in directions])

transform_hull(sht, hull, **kwargs)

Calculate the spherical harmonic transform of the shape of the provided convex hull

Parameters:

Name Type Description Default
sht SHT

the spherical harmonic transform object handle

required
n_i ConvexHull

the convex hull (or shape to describe)

required
kwargs dict

keyword arguments for optional settings. Options include:

origin (np.ndarray): specify the center of the surface
    (default is the geometric centroid of the interior atoms)
distances (bool): also return the distances of intersection

{}

Returns:

Type Description

np.ndarray: the coefficients from the analysis step of the SHT

Source code in chmpy/shape/convex_hull.py
def transform_hull(sht, hull, **kwargs):
    """
    Calculate the spherical harmonic transform of the shape of the
    provided convex hull

    Args:
        sht (SHT): the spherical harmonic transform object handle
        n_i (ConvexHull): the convex hull (or shape to describe)
        kwargs (dict): keyword arguments for optional settings.
            Options include:
            ```
            origin (np.ndarray): specify the center of the surface
                (default is the geometric centroid of the interior atoms)
            ```
            distances (bool): also return the distances of intersection

    Returns:
        np.ndarray: the coefficients from the analysis step of the SHT
    """

    x, y, z = sht.grid_cartesian
    directions = np.c_[x.flatten(), y.flatten(), z.flatten()]

    r = ray_hull_intersections(directions, hull).reshape(x.shape)
    coeffs = sht.analysis(r)
    if kwargs.get("distances", False):
        return coeffs, r
    else:
        return coeffs