randrot

Uniformly distributed random rotations

Syntax

R = randrot
R = randrot(m)
R = randrot(m1,...,mN)
R = randrot([m1,...,mN])

Description

R = randrot returns a unit quaternion drawn from a uniform distribution of random rotations.

example

R = randrot(m) returns an m-by-m matrix of unit quaternions drawn from a uniform distribution of random rotations.

example

R = randrot(m1,...,mN) returns an m1-by-...-by-mN array of random unit quaternions, where m1,…, mN indicate the size of each dimension. For example, randrot(3,4) returns a 3-by-4 matrix of random unit quaternions.

R = randrot([m1,...,mN]) returns an m1-by-...-by-mN array of random unit quaternions, where m1,…, mN indicate the size of each dimension. For example, randrot([3,4]) returns a 3-by-4 matrix of random unit quaternions.

Examples

collapse all

Generate a 3-by-3 matrix of uniformly distributed random rotations.

r = randrot(3)
r = 

  3×3 quaternion array


      0.71601 - 0.048195i +  0.69548j + 0.036254k     -0.33542 -  0.39466i -  0.84503j +  0.13285k     0.069862 -  0.23387i +  0.96842j + 0.050806k
      0.31625 +  0.20986i +  0.29758j -  0.87601k      0.42409 - 0.047461i +  0.28419j -  0.85856k      0.73316 +  0.35984i +  0.53474j -  0.21687k
      0.16941 +  0.32961i -  0.74097j +  0.56002k      0.42141 +  0.88708i +  0.09635j +  0.16195k      0.52868 +  0.64498i +  0.39167j +   0.3887k

Create a vector of 500 random quaternions. Use rotatepoint to visualize the distribution of the random rotations applied to point (1, 0, 0).

q = randrot(500,1);

pt = rotatepoint(q, [1 0 0]);

figure
scatter3(pt(:,1), pt(:,2), pt(:,3))
axis equal

Input Arguments

collapse all

Size of square quaternion matrix, specified as an integer value. If m is 0 or negative, then R is returned as an empty matrix.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Size of each dimension, specified as two or more integer values. If the size of any dimension is 0 or negative, then R is returned as an empty array.

Example: randrot(2,3) returns a 2-by-3 matrix of random quaternions.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Vector of size of each dimension, specified as a row vector of two or more integer values. If the size of any dimension is 0 or negative, then R is returned as an empty array.

Example: randrot([2,3]) returns a 2-by-3 matrix of random quaternions.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Random quaternions, returned as a quaternion or array of quaternions.

Data Types: quaternion

References

[1] Shoemake, K. "Uniform Random Rotations." Graphics Gems III (K. David, ed.). New York: Academic Press, 1992.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2019a