开发者

How do I create a random path?

开发者 https://www.devze.com 2023-04-13 02:29 出处:网络
I\'m looking for an algorithm that can generate something like what\'s in this image: I\'ve read about drunken walk algorithms 开发者_如何学Pythonbut they don\'t seem to quite fit what I need. I\'m

I'm looking for an algorithm that can generate something like what's in this image:

How do I create a random path?

I've read about drunken walk algorithms 开发者_如何学Pythonbut they don't seem to quite fit what I need. I'm not sure if I can achieve what I'm looking for with a heavily modified drunken walk algorithm or if I should be looking for some other algorithm to mess with.


Since you want to avoid self-intersection, a random walk is going to be difficult to do correctly. You could easily paint yourself into a corner. I would suggest starting with a single line segment that crosses the area, then splitting this line segment somewhere in the middle and shifting the midpoint by some random amount proportional to the length of the line segment. Repeat this process recursively for the two new line segments. If you end up with a midpoint that causes one of the two new line segments to cross an existing line segment, then try a different midpoint. Stop the recursion when your line segments are short (however you want to define that).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号