Created
April 30, 2012 18:22
-
-
Save kayru/2560755 to your computer and use it in GitHub Desktop.
Generate random points inside a sphere
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 GeneratePointsInsideSphere(num_points) : | |
points = [] | |
for i in range(num_points) : | |
while True : | |
x = random.uniform(-1,1) | |
y = random.uniform(-1,1) | |
z = random.uniform(-1,1) | |
if( (x*x+y*y+z*z) <= 1.0 ) : | |
points.append([x,y,z]) | |
break | |
return points | |
if len(sys.argv) > 1 : | |
points = GeneratePointsInsideSphere(int(sys.argv[1])) | |
print "float3 points[] = \n{" | |
for i in range(len(points)) : | |
print "\tfloat3(%(x).03f, %(y).03f, %(z).03f)," % {"x":points[i][0], "y":points[i][1], "z":points[i][2]} | |
print "};" | |
else: | |
print "Usage: generate_points_inside_sphere.py <num_points>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment