The 3x3 rotation matrix for a rotation about the x, y, or z-axis.
EXAMPLE
real(wp),dimension(3,3) :: rotmat
real(wp),dimension(3) :: vec,vec2
real(wp) :: ang
ang = pi / 4.0_wp
vec = [1.414_wp, 0.0_wp, 0.0_wp]
rotmat = rotation_matrix(z_axis,ang)
vec2 = matmul(rotmat,vec)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | axis |
x_axis, y_axis, or z_axis |
||
real(kind=wp), | intent(in) | :: | angle |
angle in radians |
the rotation matrix
pure function rotation_matrix(axis,angle) result(rotmat) implicit none real(wp),dimension(3,3) :: rotmat !! the rotation matrix integer,intent(in) :: axis !! x_axis, y_axis, or z_axis real(wp),intent(in) :: angle !! angle in radians real(wp) :: c,s !precompute these: c = cos(angle) s = sin(angle) select case (axis) case(x_axis); rotmat = reshape([one, zero, zero, zero, c, -s, zero, s, c],[3,3]) case(y_axis); rotmat = reshape([c, zero, s, zero, one, zero, -s, zero, c],[3,3]) case(z_axis); rotmat = reshape([c, -s, zero, s, c, zero, zero, zero, one],[3,3]) case default; rotmat = zero end select end function rotation_matrix