lundi 28 septembre 2020

How do I program a spatially dependend random number distribution?

I wrote a routine that distributes circles randomly (uniformly) with an arbitrary diameter in my study area.

def no_nearby_dots(new_dot, dots_sim, min_distance):
    for dot in dots_sim:
        if np.sqrt((dot[0] - new_dot[0]) ** 2 + (dot[1] - new_dot[1]) ** 2) <= min_distance:
            return False
    return True

while realizations < simulations:
    dots_sim = []
    new_dot = True
    dots_sim.append((np.random.uniform(xmin, xmax), np.random.uniform(ymin, ymax)))
    failed_attempts = 0
    while new_dot:
        xp = np.random.uniform(xmin, xmax)
        yp = np.random.uniform(ymin, ymax)
        if no_nearby_dots((xp, yp), dots_sim, diameter):
            dots_sim.append((xp, yp))
            failed_attempts = 0
        else:
            failed_attempts += 1
        if len(dots_sim) == n_sim:
            new_dot = False
        if failed_attempts > 2000:
            new_dot = False
            print('ERROR...exit loop')
            break

    x_sim = [dot[0] for dot in dots_sim]
    y_sim = [dot[1] for dot in dots_sim]

I want to introduce a second circle around the initial ones where the possibility of distributing points reduces exponentially towards the inner border -> I want to prevent a "hard" border, the points are allowed to occur anywhere on the plane but not closer than diameter, additionally they can only occur to a certain degree between diameter and diameter2.

Are there any ideas how to do that?




Aucun commentaire:

Enregistrer un commentaire