Function:s2impa

From S2PLOT

Revision as of 04:48, 22 November 2007; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

s2skypa

Draw an impulse plot with/without trunks.

Prototype

void s2impa(float **data, int nx, int ny,int i1, int i2, int j1, int j2,
float datamin, float datamax, float *tr, int trunk, int symbol);

Description

Draw an impulse plot with arbitrary rotation / skew / translation specified by the tr matrix. Draw trunks of points if trunk is true. Use point types as for s2pt.

See Also

s2skypaDraw a skyscraper plot with/without walls

Code Example

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "s2plot.h"

#define XLIMIT 10.0
#define YLIMIT 10.0
#define ZLIMIT 10.0
#define TWOPI 6.2831853

#define NX 32
#define NY 32

int main(int argc, char *argv[])
{

   float x1 = -XLIMIT, x2 = XLIMIT;             /* x world coord range */
   float y1 = -YLIMIT, y2 = YLIMIT;             /* y world coord range */
   float z1 = -ZLIMIT, z2 = ZLIMIT;             /* z world coord range */
   int i, j;                                    /* Loop variables */
   float **image;                               /* 2D array for image */
   float minz = 9e30;                           /* Minimum value */
   float maxz = -9e30;                          /* Maximum value */
   float x, y, dx, dy;                          /* Temporary variables */
   float tr[12];                                /* Transformation matrix */
   int trunk = 0;                               /* Should trunks be drawn? */
   int symbol = 4;                              /* Plotting symbol for tip */

   s2opend("/?",argc,argv);                     /* Open the display */

   dx = (x2-x1)/(float)(NX-1);                  /* Spacing in X */
   dy = (y2-y1)/(float)(NY-1);                  /* Spacing in Y */

   s2swin(x1-0.5*dx,x2+0.5*dx,y1-0.5*dy,y2+0.5*dy,z1,z2);
                                                /* Set the window coordinates */
   s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0);  /* Draw coordinate box */

   dx = (x2-x1)/(float)(NX-1);                  /* Spacing in X */
   dy = (y2-y1)/(float)(NY-1);                  /* Spacing in Y */

   image = (float **)calloc(NX, sizeof(float **));      /* Allocate memory */
   for (i=0;i<NX;i++) {
      image[i] = (float *)calloc(NY, sizeof(float *));  /* Allocate memory */
      x = i*dx + x1;
      for (j=0;j<NY;j++) {
         y = j*dy + y1;
         image[i][j] = -sqrt(x*x + y*y);                /* Data points */
         image[i][j] += rand() / (float)RAND_MAX;
         minz = (image[i][j] < minz) ? image[i][j] : minz;
         maxz = (image[i][j] > maxz) ? image[i][j] : maxz;
      }
   }

   s2icm("rainbow", 1000, 1500);                /* Install colour map */
   s2scir(1000, 1500);                          /* Set colour range */

   /* Set up the transformation mapping from grid to world coordinatee */

   tr[0] = x1; tr[1] = (x2-x1)/(float)(NX-1); tr[2] = 0.0; tr[3] = 0.0;
   tr[4] = y1; tr[5] = 0.0; tr[6] = (y2-y1)/(float)(NY-1); tr[7] = 0.0;
   tr[8] = z1; tr[9] = 0.0;   tr[10] = 0.0;   tr[11] = 0.0;

   /* Draw the data mapped to the z-plane */
   s2surpa(image, NX, NY, 0, NX-1, 0, NY-1, minz, maxz, tr);
   
   tr[8] = z1 - minz * (z2 - z1) / (maxz - minz);       /* Fix up z minimum */
   tr[11] = (z2 - z1) / (maxz - minz);                  /* Fix up z range */

   /* Draw the data as impulses */
   s2impa(image, NX, NY, 0, NX-1, 0, NY-1, minz, maxz, tr, trunk, symbol);

   s2show(1);                                   /* Show the S2PLOT window */

   return 1;

}

Back to S2PLOT function list.


Personal tools