FUNCTION smei_sky2cam, rvec, camera=camera, quaternion=quaternion, $ degrees=degrees, rectangular=rectangular ;+ ; NAME: ; smei_sky2cam ; PURPOSE: ; Convert from equatorial coordinates to coordinates in the UCSD ; SMEI camera frame. ; CATEGORY: ; camera/idl ; CALLING SEQUENCE: ; R = smei_sky2cam( rvec, [ camera=camera, quaternion=quaternion, /degrees] ) ; INPUTS: ; rvec array[2,n] or array[3,n]; type: float ; positions in the sky as spherical or rectangular ; equatorial coordinates. ; ; /rect NOT SET: spherical coordinates ; rvec[0,*] is RA; ; rvec[1,*] is declination ; rvec[3,*] (usually the distance) ; ; /rect SET: rectangular coordinates ; rvec[0,*] is x-coordinate (toward vernal equinox ; rvec[1,*] is y-coordinate ; rvec[3,*] is z-coordinate (toward equatorial north) ; ; The units of the angles are determined by the setting of /degrees. ; OPTIONAL INPUT PARAMETERS: ; /degrees if set, all in- and output angles are in degrees ; (default: radians). Note that the input 'camera' structure, ; if specified, must be consistent with the setting of /degrees. ; ; /rectangular if set then rvec is in rectangular Cartesian coordinates. ; The 1st dimension in rvec MUST be 3; if it is not then ; this keyword is ignored. ; ; camera=camera Identifies the SMEI camera ; ; Can be any one of the following three. ; ; array[1]; type: SMEI_FRM_HDR structure ; this determines the camera and the quaternion. ; The keyword 'quaternion', if present, ; will be ignored. ; ; array[1]; type: SMEI_CAMERA_FOV structure ; structure containing information about SMEI field of ; view; usually the return value of href=smei_camera= ; with the /get_structure keyword set. ; This determines the fixed S/C-to-camera quaternion. The ; Coriolis quaternion must be specified using the ; 'quaternion' keyword. ; ; scalar; type: integer ; camera number (1,2 or 3). ; This determines the fixed S/C-to-camera quaternion. The ; Coriolis quaternion must be specified using the ; 'quaternion' keyword. ; ; If not specified then camera=1 is assumed. ; ; The camera number is used as argument to smei_camera to ; obtain the fov structure. ; quaternion=quaternion ; array[4]; type: float ; Coriolis S/C quaternion ; OUTPUTS: ; R array[3,n]; type: float ; x,y,z coordinates of unit vector in the UCSD camera ; frame ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; ToRadians, InitVar, smei_camera, IsType, SyncDims, boost, smei_cam_quaternion ; CvRotation ; PROCEDURE: ; MODIFICATION HISTORY: ; MAR-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Extracted from smei_sky2ccd. ;- rpm = ToRadians(degrees=degrees) InitVar, rectangular, /key ; Analyze input. CASE 1 OF IsType(camera, /structure): begin CASE tag_names(camera, /structure_name) OF 'SMEI_FRM_HDR': BEGIN fov = smei_camera(camera=camera.camera, /get_structure, degrees=degrees) quaternion = smei_property(camera,/quaternion) ; S/C quaternion END 'SMEI_CAMERA_FOV': fov = camera ENDCASE END IsType(camera, /undefined): fov = smei_camera(camera=1, /get_structure, degrees=degrees) ELSE: fov = smei_camera(camera=camera, /get_structure, degrees=degrees) ENDCASE sz_rvec = size(rvec) npart = sz_rvec[1] ; # components (2 or 3) nvec = n_elements(rvec)/npart sz_3 = sz_rvec sz_3[1] = 3 ; Three components sz_3[sz_3[0]+2] = sz_3[sz_3[0]+2]/npart*3 rectangular = rectangular and npart eq 3 r = reform(rvec,npart,nvec) IF NOT rectangular THEN BEGIN IF npart EQ 2 THEN boost, r, replicate(1, nvec) ; Make unit vector in spherical coordinates r = cv_coord(from_sphere=r, /to_rect, degrees=degrees) ENDIF r = r/(replicate(1,3)#[sqrt(total(r*r,1))]) ; Make sure we have unit vectors ; Rotate input spherical coordinates r[0,*] and r[1,*] to a coordinate ; system with the optical axis as z-axis. IF IsType(quaternion, /defined) THEN BEGIN dcm = smei_cam_quaternion(quaternion, fov.camera) dcm = CvRotation(from_quaternion=dcm, /to_dcm) r = transpose(dcm)#r ENDIF SyncDims, r, size=sz_3 RETURN, r & END