-
Notifications
You must be signed in to change notification settings - Fork 0
/
rand.py
43 lines (38 loc) · 1015 Bytes
/
rand.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import random
try:
from cgkit.cgtypes import vec3
except:
from cgtypes import vec3
import math
mut = 'uniform'
def rnd(a, b, v):
if mut == 'gauss' and v != None:
y = random.gauss(v, 0.5)
if y<a: y = float(a)
if y>b: y = float(b)
return y
elif mut == 'uniform':
return random.uniform(a, b)
def randomVec3(ov):
"Create a random normalised vector"
try:
if ov == None:
ov = (None, None, None)
v = vec3(rnd(-1,1,ov[0]), rnd(-1,1,ov[1]), rnd(-1,1,ov[2])).normalize()
except:
v = vec3(1,0,0)
return v
def randomQuat(v):
"Create a random quaternion (vector and angle)"
if v != None:
(oldrad, oldvec) = v
else:
(oldrad, oldvec) = (None, None)
rad = rnd(0, 2*math.pi, oldrad)
vec = randomVec3(oldvec)
return (rad, tuple(vec))
def randomAxis(v):
if v == None:
v = (None, None)
xyz = vec3(rnd(-1,1,v[0]), rnd(-1,1,v[1]), 0)
return tuple(xyz.normalize())