Space Filling
Points in a Sphere


return to main index





Falloff 0.0 to 9.8


Filling a Circle (2D)

Get a random xy point in a unit square.

Find distance to center.

If distance greater than 1.0 try again.
This will avoid processing points that are in the "corners" of the unit square.

Calculate a target radius,
    target_rad = pow( 1 - distance, falloff)
where falloff are values such as,
    0.0 uniform radial filling of the unit circle,
    1.0 linear radial gradient,
    2.0 quadratic radial gradient.

Calculate a random number 0 to 1 (probability). Only if the probability is less than target_rad is the xy point accepted.


Listing 1 (python code)


import random, math
  
width = 0.004
  
def scatter2d(falloff, num, frame):
    accepted = 0
    fname = '/Users/malcolm/distribution2d.%d.rib' % frame
    f = open(fname, 'w')
    f.write('Points "P" [\n')
    while accepted < num:
        x = random.uniform(-1.0, 1.0)
        y = random.uniform(-1.0, 1.0)
        
        distance = math.sqrt(x * x + y * y)
        if distance > 1:
            continue
        target_rad = math.pow( (1.0 - distance), falloff)
        probability = random.random()
        if(probability <= target_rad): # and math.fabs(y) <= target_rad):
            f.write('%1.3f %1.3f 0 \n' % (x,y))
            accepted += 1
    f.write('] "constantwidth" [%1.3f]\n' % width)
    f.close()
    return accepted
  
incr = 0.2
for j in range(50):
    random.seed(1)
    falloff = j * incr
    scatter2d(falloff, 40000, j)
    print falloff




© 2002- Malcolm Kesson. All rights reserved.