home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / examples / example03.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  1.4 KB  |  73 lines

  1. /* Illustration of 1-1 scaling for polar plot */
  2. #include "plplot.h"
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. main()
  7. {
  8.       int i,j;
  9.       float dtr, theta, dx, dy, r;
  10.       char text[3];
  11.       static float x0[361], y0[361];
  12.       static float x[361], y[361];
  13.  
  14.       dtr = 3.141592654/180.0;
  15.       for (i=0; i<=360; i++) {
  16.         x0[i] = cos(dtr * i);
  17.         y0[i] = sin(dtr * i);
  18.       }
  19.  
  20.       plstar(1,1);
  21.  
  22.       /* Set up viewport and window, but do not draw box */
  23.  
  24.       plenv(-1.3,1.3,-1.3,1.3,1,-2);
  25.       for (i=1; i<=10; i++) {
  26.         for (j=0; j<=360; j++) {
  27.           x[j] = 0.1*i*x0[j];
  28.           y[j] = 0.1*i*y0[j];
  29.         }
  30.  
  31.        /* Draw circles for polar grid */
  32.  
  33.         plline(361,x,y);
  34.       }
  35.  
  36.       plcol(2);
  37.       for (i=0; i<=11; i++) {
  38.         theta = 30.0*i;
  39.         dx = cos(dtr*theta);
  40.         dy = sin(dtr*theta);
  41.  
  42.         /* Draw radial spokes for polar grid */
  43.  
  44.         pljoin(0.0,0.0,dx,dy);
  45.         sprintf(text,"%d",round(theta));
  46.  
  47.         /* Write labels for angle */
  48.  
  49.         if (dx >= 0)
  50.           plptex(dx,dy,dx,dy,-0.15,text);
  51.         else
  52.           plptex(dx,dy,-dx,-dy,1.15,text);
  53.       }
  54.  
  55.       /* Draw the graph */
  56.  
  57.       for (i=0; i<=360; i++) {
  58.         r = sin(dtr*(5*i));
  59.         x[i] = x0[i] * r;
  60.         y[i] = y0[i] * r;
  61.       }
  62.       plcol(3);
  63.       plline(361,x,y);
  64.  
  65.       plcol(4);
  66.       plmtex("t",2.0,0.5,0.5,"#frPLPLOT Example 3 - r(#gh)=sin 5#gh");
  67.  
  68.       /* Close the plot at end */
  69.  
  70.       plend();
  71. }
  72.  
  73.