next up previous 229
Next: Handling of Bad Coordinate Values
Up: Transforming General Coordinate Data
Previous: Transforming General Coordinate Data

Example 6. Mapping 3-dimensional coordinates into 2 dimensions.

In the following, a set of data points representing a 3-dimensional object is converted into a related set of 2-dimensional points using TRN_TRNR. The resulting points are then plotted using GKS. With a suitable choice of mapping, such an arrangement might be used to generate perspective pictures of 3-dimensional objects:

*  Define dimensions of the DATA and RESULT arrays.
      PARAMETER ( MAXPTS = 5000, MAXDIM = 3 )

*  Declare variables and arrays.
      INTEGER IPOINT, STATUS, ID
      REAL X, Y, Z, DATA( MAXPTS, MAXDIM ), RESULT( MAXPTS, MAXDIM )

*  Generate 3-d coordinates of helix.
      DO 1 IPOINT = 1, 3601
         THETA = REAL( IPOINT - 1 ) * 2.0 * 3.14159 / 360.0
         X = COS( THETA )                              [1]
         Y = SIN( THETA )
         Z = REAL( IPOINT - 1 ) / 360.0

*  Enter coordinates into the DATA array.
         DATA( IPOINT, 1 ) = X                         [2]
         DATA( IPOINT, 2 ) = Y
         DATA( IPOINT, 3 ) = Z
    1 CONTINUE

*  Transform the data points.
      CALL TRN_TRNR( .FALSE., MAXPTS, 3, 3601, DATA, ID, MAXPTS, 2,
     :               RESULT, STATUS )                  [3]

*  Plot the resulting 2-dimensional data points.
      CALL GPL( 3601, RESULT( 1, 1 ), RESULT( 1, 2 ) ) [4]

Programming notes:

  1. The coordinates of a set of 3-dimensional data points are generated.

  2. The coordinates are stored so that DATA( I, J ) contains the J'th coordinate of data point I. These coordinates need not fill the entire array.

  3. TRN_TRNR is called to apply the compiled mapping. The size of the input and output coordinate arrays are specified, together with the numbers of coordinates associated with each input and output data point. An error will result if the compiled mapping does not have the appropriate numbers of input and output variables.

  4. The 2-dimensional output data points are plotted. Their coordinates are stored in the RESULT array in a similar manner to those in the DATA array. As before, these coordinates need not entirely fill the RESULT array.



next up previous 229
Next: Handling of Bad Coordinate Values
Up: Transforming General Coordinate Data
Previous: Transforming General Coordinate Data

TRANSFORM Coordinate Transformation Facility
Starlink User Note 61
R.F. Warren-Smith
12th January 2006
E-mail:starlink@jiscmail.ac.uk

Copyright © 2000 Council for the Central Laboratory of the Research Councils