Go to the documentation of this file.00001
00002
00003 import random
00004 import math
00005 import pylab
00006
00007 def generate_leafs(k, depth, centers = [(0.0, 0.0)]):
00008 if depth == 0:
00009 return centers
00010 radius = 10 ** depth
00011 angle = 2*math.pi/k
00012 new_centers = []
00013 for c in centers:
00014 new_centers.extend( [(c[0] + radius*math.cos(i*angle), c[1] + radius*math.sin(i*angle)) for i in range(k)] )
00015 return generate_leafs(k, depth - 1, new_centers)
00016
00017 if __name__ == "__main__":
00018 k = 5
00019 depth = 3
00020 samples = 100
00021 centers = generate_leafs(k, depth)
00022 for i in range(samples):
00023 for c in centers:
00024 for coord in c:
00025 print random.gauss(coord, 1.0),
00026 print
00027
00028 pylab.scatter([c[0] for c in centers], [c[1] for c in centers])
00029 pylab.title("Centers (exact)")
00030 pylab.show()