0

I have a fairly unique problem I'm trying to solve, and the math is confusing me. I'm working on a map project, and one of the needs is to generate random, "amoeba-like" clusters of points around a given latitude/longitude center.

By "amoeba-like", I mean the cluster shouldn't be overly round or uniform, but should, ideally, have "arms" that extend out from the center. At the same time, the arms should be somewhat random and not particularly spiral-like.

I've tried a number of approaches, but so far, none of the clusters I've generated are quite the shape I want. I've tried approaches similar to what's described here, and I've tried the make_blobs from sklearn. But I couldn't figure out how to extend either of those get the "arms" I'm looking for, and I'm not confident that either of those approaches really makes sense.

Any advice anyone could provide would be much appreciated!

Matt
  • 3
  • 1
  • Could you formalize what you mean by "amoeba-like"? Maybe try generating points from a random walk – c2huc2hu Jul 20 '18 at 13:49
  • It's hard to describe but here's one way I think about it: Choose a center, c, then choose, say, 5 points - p1-p5 - that are all equidistant from c, but in different direction. (So the 5 points exist on a circle around c.) Then, starting at c, generate a random walk of points such that each successive point moves away from c and closer to one of p1-p5. Repeat for each of p1-p5. (Each walk becomes an "arm" of the amoeba.) Does that make sense? – Matt Jul 20 '18 at 14:11
  • or what about `for i in range(5): do random walk until you're more than r away from the centre` – c2huc2hu Jul 20 '18 at 14:14
  • sure yes that works! i can do a random walk, but how do i keep it moving away from the center? my concern is that if the walk is truly random, it'll wander all over such that i lose the "arm" effect that i want. how do i bias it to keep moving away from the center? – Matt Jul 20 '18 at 14:19

1 Answers1

1

As a starting point, I mocked up something based on a random walk stopping when reaching a certain distance away from the centre. You're right though, the arm effect can get hidden. I set it to create 5 arms, and I only really see 2-3. If you don't really care, it might be okay though

import random
import math

STEP_SIZE = 0.5
MAX_WALK_DIST = 5

for i in range(5): 
    x = y = 0
    while x**2+y**2 < MAX_WALK_DIST**2:
        dist = random.random() * STEP_SIZE
        angle = random.random() * math.pi * 2
        x += dist * math.cos(angle)
        y += dist * math.sin(angle)

        print(x, y)

point cloud

c2huc2hu
  • 2,447
  • 17
  • 26
  • thanks! that's better than what i've done so far, so definitely an improvement. i'm not sure what to do about the arms, short of some brute force way where you check if the distance between a new random point and the center is greater than the previous random point and the center, and if not, regenerate the next random point. that feels super inefficient, though. – Matt Jul 20 '18 at 15:10
  • you could do some angle math and always select an angle away from the centre, but your arms would be very spindly. unless this is performance critical code, don't worry about how inefficient it is – c2huc2hu Jul 20 '18 at 15:14