;+ ; NAME: ; NORMALIZE ; ; PURPOSE: ; ; This is a utility routine to calculate the scaling vector ; required to position a graphics primitive of specified range ; at a specific position in an arbitray coordinate system. The ; scaling vector is given as a two-element array like this: ; ; scalingVector = [translationFactor, scalingFactor] ; ; The scaling vector should be used with the [XYZ]COORD_CONV ; keywords of a graphics object or model. For example, if you ; wanted to scale an X axis into the coordinate range of -0.5 to 0.5, ; you might type something like this: ; ; xAxis->GetProperty, Range=xRange ; xScale = Normalize(xRange, Position=[-0.5, 0.5]) ; xAxis, XCoord_Conv=xScale ; ; AUTHOR: ; ; FANNING SOFTWARE CONSULTING ; David Fanning, Ph.D. ; 1645 Sheely Drive ; Fort Collins, CO 80526 USA ; Phone: 970-221-0438 ; E-mail: davidf@dfanning.com ; Coyote's Guide to IDL Programming: http://www.dfanning.com ; ; CATEGORY: ; Object Graphics ; ; CALLING SEQUENCE: ; xscaling = NORMALIZE(xrange, POSITION=position) ; ; INPUTS: ; XRANGE: A two-element vector specifying the data range. ; ; KEYWORD PARAMETERS: ; POSITION: A two-element vector specifying the location ; in the coordinate system you are scaling into. The vector [0,1] ; is used by default if POSITION is not specified. ; ; COMMON BLOCKS: ; None. ; ; EXAMPLE: ; See above. ; ; MODIFICATION HISTORY: ; Written by: David W. Fanning, OCT 1997. ; Fixed a problem with illegal divide by zero. 21 April 2005. DWF. ; Fixed a problem when range[0] is greater than range[1]. 11 July 2006. DWF. ;- ;########################################################################### ; ; LICENSE ; ; This software is OSI Certified Open Source Software. ; OSI Certified is a certification mark of the Open Source Initiative. ; ; Copyright © 2005-2006 Fanning Software Consulting ; ; This software is provided "as-is", without any express or ; implied warranty. In no event will the authors be held liable ; for any damages arising from the use of this software. ; ; Permission is granted to anyone to use this software for any ; purpose, including commercial applications, and to alter it and ; redistribute it freely, subject to the following restrictions: ; ; 1. The origin of this software must not be misrepresented; you must ; not claim you wrote the original software. If you use this software ; in a product, an acknowledgment in the product documentation ; would be appreciated, but is not required. ; ; 2. Altered source versions must be plainly marked as such, and must ; not be misrepresented as being the original software. ; ; 3. This notice may not be removed or altered from any source distribution. ; ; For more information on Open Source Software, visit the Open Source ; web site: http://www.opensource.org. ; ;########################################################################### FUNCTION Normalize, range, Position=position On_Error, 1 IF N_Params() EQ 0 THEN Message, 'Please pass range vector as argument.' IF (N_Elements(position) EQ 0) THEN position = [0.0D, 1.0D] ELSE $ position=Double(position) range = Double(range) IF range[1] GE range[0] THEN BEGIN scale = [((position[0]*range[1])-(position[1]*range[0])) / $ ((range[1]-range[0]) > 1e-12), (position[1]-position[0])/((range[1]-range[0]) > 1e-12)] ENDIF ELSE BEGIN scale = [((position[1]*range[0])-(position[0]*range[1])) / $ ((range[0]-range[1]) > 1e-12), (position[1]-position[0])/((range[0]-range[1]) > 1e-12)] scale[1] = -scale[1] ENDELSE RETURN, scale END ;-------------------------------------------------------------------------