Wolfram Research

Function Repository Resource:

RandomRotationQuaternion

Source Notebook

Return uniformly distributed random rotations in quaternion form

Contributed by: Sander Huisman

ResourceFunction["RandomRotationQuaternion"][]

returns a unit quaternion from uniformly distributed random rotations.

ResourceFunction["RandomRotationQuaternion"][m]

returns m unit quaternions from uniformly distributed random rotations.

Details

The rotation axis is chosen randomly from a unit sphere. Rotations around that axis have to be chosen from a specific distribution to uniformly generate random orientations, see Ref. [1].

Examples

Basic Examples (1) 

Generate a random orientation:

In[1]:=
ResourceFunction["RandomRotationQuaternion"][]
Out[1]=

Scope (1) 

Generate 5 random orientations:

In[2]:=
ResourceFunction["RandomRotationQuaternion"][5]
Out[2]=

Properties and Relations (1) 

The norm of a quaternion corresponding to random orientations is equal to 1:

In[3]:=
Norm /@ ResourceFunction["RandomRotationQuaternion"][10]
Out[3]=

Neat Examples (1) 

Generate 2500 random points on a sphere by rotating the vector {0,0,1} with random orientations:

In[4]:=
v = ResourceFunction["Quaternion"] @@ {0, 0, 0, 1};
q = ResourceFunction["RandomRotationQuaternion"][2500];
qinv = Conjugate /@ q;
out = MapThread[(#1 ** v) ** #2 &, {q, qinv}];
out = Map[Rest][List @@@ out];
Graphics3D[Point[out], ImageSize -> 200]
Out[4]=

Resource History

Source Metadata

Related Resources

License Information