;+
;Language : IDL 8.2.2
;================================================================================
;The AAS gives permission to anyone who wishes to use these subroutines to run their own calculations.
;Permission to republish or reuse these routines should be directed to permissions@aas.org.
;
;Note that the AAS does not take responsibility for the content of the source code. Potential users should
;be wary of applying the code to conditions that the code was not written to model and the accuracy of the
;code may be affected when compiled and executed on different systems.
;================================================================================
; NAME:
; EULER_TO_ROTMATRIX
;
; PURPOSE:
; Takes a set of three Euler angles as input, and returns the associated rotation matrix.
;
; CALLING SEQUENCE:
; matrix = EULER_TO_ROTMATRIX( euler_angles[, /DEGREE] )
;
; INPUTS:
; EULER - A 3-elements array containing, respectively, the psi, theta and phi Euler angles (also called alpha, beta, gamma).
;
; OPTIONAL INPUT KEYWORD:
; /DEGREE - Use this keyword to input Euler angle in degrees (default is radians).
;
; OUTPUTS:
; MATRIX = A 3-dimensional, 3x3 rotation matrix.
;
; NOTE:
;
; By default, the Euler angles are expected to be input in radians.
;
; PROCEDURES USED:
; NONE
;
; MODIFICATION HISTORY:
; WRITTEN, Jonathan Gagne, August, 21 2013
;-
Function euler_to_rotmatrix, euler_angles_in, DEGREE=degree
;Transform degrees to degree if asked for
if keyword_set(degree) then $
euler_angles = euler_angles_in * !pi/180. else $
euler_angles = euler_angles_in
;Build three rotation matrices around the x-, y- and z-axis
Rx = [[1.,0.,0.],$
[0.,cos(euler_angles[0]),-sin(euler_angles[0])],$
[0.,sin(euler_angles[0]), cos(euler_angles[0])]]
Ry = [[cos(euler_angles[1]),0.,sin(euler_angles[1])],$
[0,1.,0.],$
[-sin(euler_angles[1]),0.,cos(euler_angles[1])]]
Rz = [[cos(euler_angles[2]),-sin(euler_angles[2]),0.],$
[sin(euler_angles[2]), cos(euler_angles[2]),0.],$
[0.,0.,1.]]
;Combine these matrixes to get the final rotation matrix
;We don't care about parentheses since matrix product is associative
R = Rx#Ry#Rz
;Return the result
return, R
End