removes equator, achieves uniform distribution of stars implementing rejection sampling, adds UNIX script header

This commit is contained in:
tosh 2013-05-09 12:08:19 +02:00
parent 408a21b515
commit 395e4a7852

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python
# #
# gen_stars.py # gen_stars.py
# interface # interface
@ -12,7 +14,7 @@ from random import random,randint
from math import sqrt, hypot, atan2, pi, fmod, degrees from math import sqrt, hypot, atan2, pi, fmod, degrees
from sys import argv,stderr from sys import argv,stderr
hemisphere_only, equator, meridians= False, 1000, 1000 hemisphere_only, equator, meridians= False, 0, 1000
n_random = 100000 n_random = 100000
if len(argv) > 1: if len(argv) > 1:
@ -50,10 +52,13 @@ for i in range(n_random):
g = max(0,min(255,w + randint(-20,60))) g = max(0,min(255,w + randint(-20,60)))
b = max(0,min(255,w + randint(-10,100))) b = max(0,min(255,w + randint(-10,100)))
# position # position
x,y,z = random()*2-1,random(),random()*2-1 while True:
if not hemisphere_only: x,y,z = random()*2-1,random(),random()*2-1
y = y*2-1 if not hemisphere_only:
l = sqrt(x*x + y*y + z*z) y = y*2-1
l = sqrt(x*x + y*y + z*z)
if l <= 1.0:
break
x /= l; y /= l; z /= l x /= l; y /= l; z /= l
xz = hypot(x,z) xz = hypot(x,z)