Skip to content

equal_interval_points

cellseg_gsontools.lines.equal_interval_points(obj, n=None, delta=None)

Resample the points of a shapely object at equal intervals.

Parameters:

Name Type Description Default
obj Any

Any shapely object that has length property.

required
n int

Number of points, defaults to None

None
delta float

Distance between points, defaults to None

None

Returns:

Name Type Description
points ndarray

Array of points at equal intervals along the input object.

Source code in cellseg_gsontools/lines.py
def equal_interval_points(obj: Any, n: int = None, delta: float = None):
    """Resample the points of a shapely object at equal intervals.

    Parameters:
        obj (Any):
            Any shapely object that has length property.
        n (int):
            Number of points, defaults to None
        delta (float):
            Distance between points, defaults to None

    Returns:
        points (numpy.ndarray):
            Array of points at equal intervals along the input object.
    """
    length = obj.length

    if n is None:
        if delta is None:
            delta = obj.length / 1000
        n = round(length / delta)

    distances = np.linspace(0, length, n)
    points = [obj.interpolate(distance) for distance in distances]
    points = np.array([(p.x, p.y) for p in points])

    return points