Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Some useful functions, for generating uniformly distributed random points
- by @_sorceress, March 2014
- =========================================================================
- - All functions input a radius 'r'.
- - 'random' should return a uniformly distributed random number between 0 and 1.
- ---------------------------------------------------------------------
- Point (x,y) on the circle perimeter
- a = 2*pi*random
- x = r*cos(a)
- y = r*sin(a)
- ---------------------------------------------------------------------
- Point (x,y) within the circular disk
- a = 2*pi*random
- b = sqrt(random)*r
- x = b*cos(a)
- y = b*sin(a)
- ---------------------------------------------------------------------
- Point (x,y) within the annulus, with internal radius m*r (where 0<m<1)
- a = 2*pi*random
- b = m*m
- b = r*sqrt(b+random*(1-b))
- x = b*cos(a)
- y = b*sin(a)
- ---------------------------------------------------------------------
- Point (x,y,z) within the cylinder, with height h
- a = 2*pi*random
- b = sqrt(random)*r
- x = b*cos(a)
- y = b*sin(a)
- z = h*random
- ---------------------------------------------------------------------
- Point (x,y,z) on the spherical surface
- a = 2*random-1
- b = 2*pi*random
- c = r*sqrt(1-a*a)
- x = c*cos(b)
- y = c*sin(b)
- z = r*a
- ---------------------------------------------------------------------
- Point (x,y,z) within the spherical ball
- d = r*random^(1/3)
- a = 2*random-1
- b = 2*pi*random
- c = d*sqrt(1-a*a)
- x = c*cos(b)
- y = c*sin(b)
- z = d*a
- ---------------------------------------------------------------------
- Point (x,y,z) within the spherical ball (generally faster, but unpredictable halting time)
- do {
- x = r*(2*random-1)
- y = r*(2*random-1)
- z = r*(2*random-1)
- } while(x*x+y*y+z*z>r*r)
- ---------------------------------------------------------------------
- Point (x,y,z) within the thick spherical shell, with inner radius m*r (where 0<m<1)
- d = m*m*m
- d = r*(d+random*(1-d))^(1/3)
- a = 2*random-1
- b = 2*pi*random
- c = d*sqrt(1-a*a)
- x = c*cos(b)
- y = c*sin(b)
- z = d*a
- ---------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement