Created
April 30, 2012 18:20
-
-
Save kayru/2560742 to your computer and use it in GitHub Desktop.
Generate random points on disc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
def GeneratePointsInsideDisc(num_points) : | |
points = [] | |
for i in range(num_points) : | |
while True : | |
x = random.uniform(-1,1) | |
y = random.uniform(-1,1) | |
if( (x*x+y*y) <= 1.0 ) : | |
points.append([x,y]) | |
break | |
return points | |
if len(sys.argv) > 1 : | |
points = GeneratePointsInsideDisc(int(sys.argv[1])) | |
print "float2 points[] = \n{" | |
for i in range(len(points)) : | |
print "\tfloat2(%(x).03f, %(y).03f)," % {"x":points[i][0], "y":points[i][1]} | |
print "};" | |
else: | |
print "Usage: generate_points_inside_disc.py <num_points>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment