Commit def6c071 authored by Jan Stránský's avatar Jan Stránský

added utils.randomOrientation function

added a visual test
parent f03a37c0
Pipeline #161235455 canceled with stages
in 3 minutes and 10 seconds
# viusally testing utils.randomOrientation function
n = 100
O.bodies.append([box((0,0,0),(10,1,.1),orientation=randomOrientation()) for _ in range(n)])
......@@ -922,3 +922,17 @@ class clumpTemplate(object):
self.numCM = len(relRadii)
self.relRadii = relRadii
self.relPositions = relPositions
def randomOrientation():
Returns (uniformly distributed) random orientation.
Taken from `Eigen::Quaternion::UnitRandom() source code <>`_.
Uses standard Python random.random() function(s), you can :code:`random.seed()` it
from math import pi,sqrt,sin,cos
u1 = random.random()
u2 = random.random() * pi
u3 = random.random() * pi
a = sqrt(1 - u1)
b = sqrt(u1)
return Quaternion(a*sin(u2),a*cos(u2),b*sin(u3),b*cos(u3))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment