math - Weighted random coordinates -


this may more of search term, solutions welcome. i'm looking create n amount of random x,y coordinates. issue having coordinates "weighted" or have more of chance of falling closer specific point. i've created close using pseudo code:

x = rand(100) //random integer between 0 , 100 x = rand(x) //random number between 0 , previous rand value //randomize x positive or negative //repeat y 

this works pull objects toward 0,0 - if create enough points, can see pattern of x , y axis. because if x manages 100, chances high y closer to.

i'm looking avoid formation of x,y line. bonus points if there way throw in multiple "weighted coordinates" random coordinates sort of gravitate to, instead of statically 0,0.

this easier in polar coordinates. have generate uniform random angle , power distributed distance. here's example in python:

import math random import random  def randompoint(aroundx, aroundy, scale, density):   angle = random()*2*math.pi    x = random()   if x == 0:     x = 0.0000001    distance = scale * (pow(x, -1.0/density) - 1)   return (aroundx + distance * math.sin(angle),           aroundy + distance * math.cos(angle)) 

here's distribution of randompoint(0, 0, 1, 1):

points spread out, more dense @ origin

we can shift center around point 1,2 randompoint(1, 2, 1, 1):

points spread out, more dense @ 1,2

we can spread across larger area increasing scale. here's randompoint(0, 0, 3, 1):

points spread out randomly on larger area

and can change shape, tendency flock together, changing density. randompoint(0, 0, 1, 3):

points tightly centered around origin


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -