;===================================================================== ; PV-WAVE ARL ; ; PV-Wave Advanced Rendering Library ; 11/90 D. Carr ; ; (c) Copyright Precision Visuals, Inc., 1990 ; Boulder, Colorado, U.S.A. ; ; All Rights Reserved. ; ; This software is confidential information which is proprietary to ; and a trade secret of Precision Visuals, Inc. Use, duplication or ; disclosure is subject to the terms of an appropriate license ; agreement. ; ------------------------------------------------------------------ ; Use, duplication, or disclosure by the Government is subject to ; restrictions set forth in paragraph (b)(3)(B) of the Rights in ; Technical Data and Computer Software clause in DAR 7-104.9(a). ; ; Contractor : Precision Visuals, Inc., Boulder, Colorado, U.S.A. ; ------------------------------------------------------------------- ; ; Program Overview : FUNCTION Conv_To_Rect ; Conv_To_Rect converts coordinates from polar, cylindrical, or ; spherical to rectangular. If the "polar" keyword is present and ; non-zero then a float(2, n) array is returned with (0, *) ; containing the X coordinates and (1, *) containing the Y ; coordinates. If "polar" is zero (or not present) then a ; float(3, *) array is returned with (0, *) containing the X ; coordinates, (1, *) containing the Y coordinates, and (2, *) ; containing the Z coordinates . ; ; SEE ALSO : Conv_From_Rect ; ; MANDATORY INPUTS : ; ; vec1 : A one dimensional array containing the polar ; (logitude) angles. ; ; vec2 : If "polar" or "cylin" keywords are present and ; non-zero, then vec2 should contain the radii. ; Otherwise, vec3 should contain the latitude ; angles. ; ; vec3 : If "polar" is present and non-zero then vec3 ; should be the scalar value 0 (it is ignored). ; If "Cylin" is present and non-zero then vec3 ; should contain the Z values. Otherwise, vec3 ; should contain the radii for spherical ; coordinates. ; ; OPTIONAL COORDINATES : ; ; degrees : If "degrees" is present and non-zero then the ; input coordinates are in degrees instead of ; radians. ; ; polar : Specifies that the input coordinates are ; polar. ; ; cylin : Specifies that the input coordinates are ; cylindrical. ; ;===================================================================== ; FUNCTION Conv_To_Rect, vec1, vec2, vec3, degrees=degrees, polar=polar, cylin=cylin vec1 = Float(vec1) vec2 = Float(vec2) vec3 = Float(vec3) IF (N_Elements(degrees) EQ 0) THEN degrees = 0 IF (N_Elements(polar) EQ 0) THEN polar = 0 IF (N_Elements(cylin) EQ 0) THEN cylin = 0 IF ((polar(0) EQ 1) AND (cylin(0) EQ 1)) THEN BEGIN Print, "Polar and Cylin keywords can't both be present." STOP ENDIF sphere = 0 IF ((polar NE 1) AND (cylin NE 1)) THEN sphere = 1 n_points = (N_Elements(vec1)) IF (n_points EQ 0) THEN BEGIN Print, "No points to convert." STOP ENDIF IF (degrees(0) NE 0) THEN BEGIN vec1 = vec1 * !DPI / Double(180.0) IF (sphere EQ 1) THEN vec2 = vec2 * !DPI / Double(180.0) ENDIF IF (N_Elements(vec2) NE n_points) THEN BEGIN Print, "vec1 and vec2 arrays are not the same size." STOP ENDIF IF ((polar(0) EQ 0) AND (N_Elements(vec3) NE n_points)) THEN BEGIN Print, "vec1 and vec3 arrays are not the same size." STOP ENDIF IF (sphere EQ 1) THEN BEGIN points = Fltarr(3, n_points) points(0, *) = vec3 * Cos(vec1) * Cos(vec2) points(1, *) = vec3 * Sin(vec1) * Cos(vec2) points(2, *) = vec3 * Sin(vec2) ENDIF IF (cylin(0) EQ 1) THEN BEGIN points = Fltarr(3, n_points) points(0, *) = vec2 * Cos(vec1) points(1, *) = vec2 * Sin(vec1) points(2, *) = vec3 ENDIF IF (polar(0) EQ 1) THEN BEGIN points = Fltarr(2, n_points) points(0, *) = vec2 * Cos(vec1) points(1, *) = vec2 * Sin(vec1) ENDIF RETURN, points END