Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pylab import *
- from math import *
- from random import *
- def rand(a, b):
- return (b-a)*random() + a
- surfaceThickness = 0.01
- manyBins = 50
- fewBins = 10
- numpoints = xrange(10000)
- # point picking in a sphere
- # mathworld.wolfram.com/SpherePointPicking.html (area has to be preserved)
- # www.mathworks.de/de/help/matlab/math/numbers-placed-randomly-within-volume-of-sphere.html
- theta = [acos(2.0*rand(0.0, 1.0)-1.0) for x in numpoints]
- phi = [rand(0.0, 2*pi) for x in numpoints]
- radius = [3*(rand (1.0-surfaceThickness,1.0)**(1.0/3.0)) for x in numpoints]
- pointsSurf = [(r*sin(t)*cos(p), r*sin(t)*sin(p), r*cos(t)) for r,t,p in zip (radius,theta,phi)] # sphere
- radius = [3*(rand (0.0,1.0)**(1.0/3.0)) for x in numpoints]
- pointsFull = [(r*sin(t)*cos(p), r*sin(t)*sin(p), r*cos(t)) for r,t,p in zip (radius,theta,phi)] # sphere
- px, py, pz = zip (*pointsSurf)
- subplot (2,2,1)
- hist2d (px,py, bins=manyBins)
- colorbar ()
- subplot (2,2,3)
- hist2d (px,py, bins=fewBins)
- colorbar ()
- px, py, pz = zip (*pointsFull)
- subplot (2,2,2)
- hist2d (px,py, bins=manyBins)
- colorbar ()
- subplot (2,2,4)
- hist2d (px,py, bins=fewBins)
- colorbar ()
- show ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement