algorithm - Random point within oval with higher probability for a point closer to the centre? -
i feel question quite descriptive illustrate in words.
picture radial gradient (black in centre, white on edge) want generate random point more fall in black, less fall in grey, , less fall in white.
could point me in right direction? i'm quite stumped :/
if b
matrix such y = c + bx
affine transformation maps unit circle ellipse (which assume mean "oval"), probability distribution looks seem want given y ~ n(c, bb^t)
b^t
transpose of b
.
you can sample distribution generating column vector x
of 2 distributed variables , applying transformation y = c + bx
. there many libraries generating pair of distributed variables; in java, x0=rand.nextgaussian(); x1=rand.nextgaussian()
work.
this generate points outside ellipse. can avoid rejecting such points. test whether x0*x0 + x1*x1 > 1
, reject if true.
one more thing: if want "more white" near edge of ellipse, can change standard deviation of gaussians generate number less 1:
sd = 0.5; x0 = sd * rand.nextgaussian(); x1 = sd * rand.nextgaussian(); while (x0*x0 + x1*x1 > 1); y0 = c0 + b[0][0] * x0 + b[0][1] * x1 y1 = c1 + b[1][0] * x0 + b[1][1] * x1
if want "less white", set sd
number greater 1.
Comments
Post a Comment