def get_fraction(dist, r_max, diameter):
    """Compute what fraction of a point of the provided diameter at distance
    dist is contained in a sphere of radius r_max."""
    if dist < r_max - diameter / 2:
        return 1
    if dist > r_max + diameter / 2:
        return 0
    else:
        return -dist / diameter + r_max / diameter + 0.5