;+ ;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: ; COORD_ROT ; ; PURPOSE: ; Takes a set of (x,y,z) coordinates (can be arrays of the same length), as well as a rotation matrix OR ; a set of 3 euler angles, then rotates the coordinates. ; ; CALLING SEQUENCE: ; COORD_ROT, X, Y, Z, XP, YP, ZP, ROT_MATRIX=rot_matrix[, EX, EY, EZ, EXP, EYP, EZP, EULER_ANGLES=euler_angles, DEGREE=degree, CENTER=center, INVERT=invert, FAST=fast] ; ; INPUTS: ; X, Y, Z = Set of cartesian coordinates. Each of them can either be scalars, or arrays of the same size. ; ROTMATRIX - The 3 x 3 rotation matrix that allows the passage from the X,Y,Z frame of reference to the XP, YP, ZP frame, for which the axes point ; in the same directions than the eigenvectors of the X, Y, Z coordinates distribution. EULER_ANGLES can be specified instead of ROTMATRIX. ; ; OPTIONAL INPUTS: ; EX, EY, EZ - Uncertainties on the X, Y, Z coordinates. They will be carried ; to the errors on the XP, YP, ZP coordinates in the new frame of reference. ; ; OPTIONAL INPUT KEYWORDS: ; /DEGREE - Understands Euler angles in degrees rather than radians. ; EULER_ANGLES - A 3-elements array containing respectively the psi, theta and phi Euler angles (also called alpha, beta, gamma) to rotate the coordinates. ; **These angles are assumed to be in RADIANS unless de DEGREE keyword is specified** ; CENTER - The central point around which the rotation is to be performed. ; /INVERT - Perform the inverse of the rotation specified by either the Euler angles or the rotation matrix. ; /FAST - Avoids propagating errors on the coordinates. ; ; ; OUTPUTS: ; CENTER_XYZ - A 3-elements array containing the center in the X, Y and Z directions, respectively. This is the only point where the X, Y, Z and ; XP, YP, ZP frames of reference match together. By default, center is assumed to be [0,0,0]. ; SIGMA_XYZ_P - A 3-elements array containing the 1-sigma scatter in the XP, YP and ZP direction (i.e. in the rotated frame of reference). Note ; that the direction with the largest scatter in the X,Y,Z frame will not necessarily match that of the XP,YP,ZP frame (e.g. if X ; is the direction with the largest scatter, it might be YP or ZP in the rotated frame). ; ROTMATRIX - The 3 x 3 rotation matrix that allows the passage from the X,Y,Z frame of reference to the XP, YP, ZP frame, for which the axes point ; in the same directions than the eigenvectors of the X, Y, Z coordinates distribution. ; EULER_ANGLES - A 3-elements array containing respectively the psi, theta and phi Euler angles (also called alpha, beta, gamma). ; XP, YP, ZP - The positions of the X, Y, Z coordinates in the rotated frame of reference. ; EXP, EYP, EZP - The EX, EY, EZ errors on coordinates, propagated in the rotated frame of reference. ; ; NOTE: ; ; Please acknowledge Gagné et al. 2014 (http://adsabs.harvard.edu/abs/2013arXiv1312.5864G) when using this routine. ; ; WARNING: ; ; Euler angles must be specified in **radians** unless the /DEGREE keyword is set. ; ; PROCEDURES USED: ; EULER_TO_ROTMATRIX() ; ; MODIFICATION HISTORY: ; WRITTEN, Jonathan Gagne, January, 11 2014 ;- Pro coord_rot, x, y, z, xp, yp, zp, ex, ey, ez, exp, eyp, ezp, EULER_ANGLES=euler_angles, ROTMATRIX=rotmatrix_in, DEGREE=degree, CENTER=center, INVERT=invert, FAST=fast ;Declare subroutines forward_function euler_to_rotmatrix ;Check keywords if keyword_set(rotmatrix_in) then $ rotmatrix = rotmatrix_in if ~keyword_set(euler_angles) and ~keyword_set(rotmatrix) then $ message, ' You must enter either a 3x3 rotation matrix or a set of 3 euler angles ! Syntax : coord_rot, x, y, z, xp, yp, zp, ex, ey, ez, exp, eyp, ezp, EULER_ANGLES=euler_angles, ROTMATRIX=rotmatrix_in, DEGREE=degree, CENTER=center, INVERT=invert, FAST=fast' if ~keyword_set(center) then $ CENTER = [0.,0.,0.] errors_set = (keyword_set(ex) and keyword_set(ey) and keyword_set(ez)) if keyword_set(fast) then errors_set = 0 ;Transform Euler angles to rotation matrix if needed if ~keyword_set(rotmatrix) then $ rotmatrix = euler_to_rotmatrix(euler_angles, DEGREE=degree) if keyword_set(invert) then $ rotmatrix = transpose(rotmatrix) ;Check the lenght of input arrays np = n_elements(x) if n_elements(y) ne np or n_elements(z) ne np then $ message, ' The three input arrays X,Y,Z must have the same length !' ;Make the rotations xp = rotmatrix[0,0] * (x - center[0]) + rotmatrix[0,1] * (y - center[1]) + rotmatrix[0,2] * (z - center[2]) + center[0] yp = rotmatrix[1,0] * (x - center[0]) + rotmatrix[1,1] * (y - center[1]) + rotmatrix[1,2] * (z - center[2]) + center[1] zp = rotmatrix[2,0] * (x - center[0]) + rotmatrix[2,1] * (y - center[1]) + rotmatrix[2,2] * (z - center[2]) + center[2] ;Reflect errors in the new coordinates if errors_set then begin exp = sqrt(rotmatrix[0,0]^2 * ex^2 + rotmatrix[0,1]^2 * ey^2 + rotmatrix[0,2]^2 * ez^2) eyp = sqrt(rotmatrix[1,0]^2 * ex^2 + rotmatrix[1,1]^2 * ey^2 + rotmatrix[1,2]^2 * ez^2) ezp = sqrt(rotmatrix[2,0]^2 * ex^2 + rotmatrix[2,1]^2 * ey^2 + rotmatrix[2,2]^2 * ez^2) endif else begin exp = finite(xp)*0. eyp = exp ezp = exp endelse End