Coordinate Conversions
Depending upon the data and type of visualization, you may want to convert between normalized, data or device coordinates (described in IDL Coordinate Systems). This section details two-dimensional and three-dimensional coordinate system characteristics and provides resources for various coordinate conversions. See the following for details:
Two-Dimensional Coordinate Conversion
This section describes the formulae for conversions to and from each coordinate system. In the following discussion, Dx is a data coordinate, Nx is a normalized coordinate, and Rx is a raw device coordinate. Let Vx and Vy represent the size of the visible area of the currently selected display or drawing surface.
The field S is a two-element array of scaling factors used to convert X coordinates from data units to normalized units. S contains the parameters of the linear equation, converting data coordinates to normalized coordinates. S[0] is the intercept, and S[1] is the slope. Also, let Dx be the data coordinate, Nx the normalized coordinate, Rx the device coordinate, Vx the device X size (in device coordinates).
With the above variables defined, the linear two-dimensional coordinate conversions for the x coordinate can be written as follows:
|
Coordinate Conversion
|
Linear
|
Logarithmic
|
|---|---|---|
| Data to normal |
|
|
| Data to device |
|
|
| Normal to device |
|
|
| Normal to data |
|
|
| Device to data |
|
|
| Device to normal |
|
|
The y- and z-axis coordinates are converted in exactly the same manner, with the exception that there is no z device coordinate and that logarithmic z-axes are not permitted.
This coordinate conversion functionality is built into object graphics through the XCOORD_CONVERT and YCOORD_CONVERT properties or each type of visualization object. If you are working with a Direct Graphics display, you can use the CONVERT_COORD function.
Three-Dimensional Coordinate Conversion
To convert from a three-dimensional coordinate to a two-dimensional coordinate, IDL follows these steps:
- Data coordinates are converted to three-dimensional normalized coordinates. To convert the x coordinate from data to normalized coordinates, use the formula Nx = X0 + X1Dx. The same process is used to convert the y and z coordinates using !Y.S and !Z.S.
- The three-dimensional normalized coordinate, P = (Nx, Ny, Nz), whose homogeneous representation is (Nx, Ny, Nz, 1), is multiplied by the concatenated transformation matrix !P.T:
- The vector P′ is scaled by dividing by w, and the normalized two-dimensional coordinates are extracted:
- The normalized xy coordinate is converted to device coordinates as described in Two-Dimensional Coordinate Conversion.
P′ = P • !P.T
N′x = P′x/P′w and N′y = P′y/P′w
Using Coordinate Conversions
How coordinate conversions are defined depend upon the display type as follows:
- iTools — in an iTool display, the interactive nature of the tool makes coordinate conversions transparent. There is no need to programmatically configure the transformation matrices of the objects. See Manipulating the Display (iTool User's Guide) for information on zooming, scaling and translation.
- Object Graphics — converting an object's data coordinates into normalized coordinates for display is a common task. See Positioning Visualizations in a View (Object Programming) for details on the elements involved in defining an object's position. Positioning Objects in a View (Object Programming) also includes information on how to use coordinate conversions (see Converting Data to Normal Coordinates) and information on programmatically defining the object's placement in a view (see Translating, Rotating and Scaling Objects).
- Direct Graphics — the IDL Direct Graphics system automatically positions and sizes static visualizations so there is no need to set up a transformation matrix. However, you can convert between the supported coordinate systems. See "CONVERT_COORD" (IDL Reference Guide) for information on this conversion in Direct Graphics.