# euler2rotmat

Make a rotation (or direction cosine) matrix of sets of Euler angles

Q = euler2rotmat(p,r,h) % Matlab & Octave
or
Q = euler2rotmat(prh)  % Matlab & Octave

Q <- euler2rotmat(p, r, h)  # R 

Make a rotation (or direction cosine) matrix out of sets of Euler angles, pitch, roll, and heading.

Input var Description Units Default value
p is the pitch angle radians N/A
r is the roll angle radians N/A
[p,r,h] (only in Octave/Matlab)a three column matrix consisting of p, r, and h as column vectors radians N/A
Output var Description Units
Q contains one or more 3×3 rotation matrices. If p, r, and h are all scalars, Q is a 3×3 matrix, Q = H*P*R where H, P and R are the cannonical rotation matrices corresponding to the yaw, pitch and roll rotations, respectively. To rotate a vector or matrix of triaxial measurements, pre-multiply by Q. If p, r or h contain multiple values, Q is a 3-dimensional matrix with size 3x3xn where n is the number of Euler angle triples that are input. To access the k'th rotation matrix in Q use squeeze(Q(:,:,k)).
• p, r and h must either be the same size vectors (i.e., all sampled at the same rate) or one or more of p, r or h can be a scalar in which case the same angle is used for all
• If p, r, and h are all scalars, Q is a 3×3 matrix, Q = H*P*R where H, P and R are the cannonical rotation matrices corresponding to the yaw, pitch and roll rotations, respectively. To rotate a vector or matrix of triaxial measurements, pre-multiply by Q. If p, r or h contain multiple values, Q is a 3-dimensional matrix with size 3x3xn where n is the number of Euler angle triples that are input. To access the k'th rotation matrix in Q use squeeze(Q(:,:,k)).

### Matlab & Octave

 Q = euler2rotmat([22 -22 85]*pi/180)
Q = [0.080809  -0.911425  -0.403453
0.923656   0.220605  -0.313358
0.374607  -0.347329   0.859670]

### R

vec1 <- matrix(c(1:10), nrow = 10)
vec2 <- matrix(c(11:20), nrow = 10)
vec3 <- matrix(c(21:30), nrow = 10)
Q <- euler2rotmat(p = vec1, r = vec2, h = vec3)
Q = matrix(c(-0.2959394, -0.4645966, -0.834607648,
0.4520470,  0.7015905, -0.550839682,
0.8414710, -0.5402970,  0.002391215), byrow = TRUE, nrow = 3)