using numpy random
This commit is contained in:
parent
b6cb7b45ea
commit
bbb00b30e8
|
@ -4,7 +4,7 @@
|
||||||
# NOTE: everything here needs to be a np array #
|
# NOTE: everything here needs to be a np array #
|
||||||
###################################################
|
###################################################
|
||||||
|
|
||||||
import math,random,os
|
import math,os
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
# ******************************************************************************************
|
# ******************************************************************************************
|
||||||
|
@ -371,14 +371,12 @@ class Quaternion:
|
||||||
def fromRandom(cls,randomSeed = None):
|
def fromRandom(cls,randomSeed = None):
|
||||||
if randomSeed == None:
|
if randomSeed == None:
|
||||||
randomSeed = int(os.urandom(4).encode('hex'), 16)
|
randomSeed = int(os.urandom(4).encode('hex'), 16)
|
||||||
random.seed(randomSeed)
|
np.random.seed(randomSeed)
|
||||||
r1 = random.random()
|
r = np.random.random(3)
|
||||||
r2 = random.random()
|
w = math.cos(2.0*math.pi*r[0])*math.sqrt(r[2])
|
||||||
r3 = random.random()
|
x = math.sin(2.0*math.pi*r[1])*math.sqrt(1.0-r[2])
|
||||||
w = math.cos(2.0*math.pi*r1)*math.sqrt(r3)
|
y = math.cos(2.0*math.pi*r[1])*math.sqrt(1.0-r[2])
|
||||||
x = math.sin(2.0*math.pi*r2)*math.sqrt(1.0-r3)
|
z = math.sin(2.0*math.pi*r[0])*math.sqrt(r[2])
|
||||||
y = math.cos(2.0*math.pi*r2)*math.sqrt(1.0-r3)
|
|
||||||
z = math.sin(2.0*math.pi*r1)*math.sqrt(r3)
|
|
||||||
return cls([w,x,y,z])
|
return cls([w,x,y,z])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue