home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / splot122.zip / DEMO / INTCALC.SPT < prev    next >
Text File  |  1994-06-06  |  4KB  |  152 lines

  1.  
  2. #include <splot.h>
  3.  
  4. /* This example file illustrates some of the internal math capabilities */ 
  5. /* In this case  x,y data points for several parabolas are calculated */
  6. /* and then drawn. Also the photon uses the sine function to draw a wave. */
  7. /* For the photon the data is not stored in an array, rather the calculated */ 
  8. /* values are added to offsets given as parameters to the photon subroutine */
  9.  
  10. /* make space for the to be generated data */
  11. double pdat[101][2];
  12.  
  13. main()
  14.    {
  15.    double x0,y0;
  16.  
  17.    x0 = 10;
  18.    y0 = 5.5;
  19.  
  20.    /* draw parabolas at x0,y0  to represent bands*/
  21.    siband(x0,y0);
  22.  
  23.    /* draw circles to represent holes in the valence band */
  24.    arc(x0 - 0.5,y0 - 0.25,0.25,0,360);
  25.    stroke();
  26.    arc(x0 + 0.5,y0 - 0.25,0.25,0,360);
  27.    stroke();
  28.  
  29.    /* draw electrons in the conduction band */
  30.    moveto(x0 + 4.25,y0 + 3.25);
  31.    rlineto(-0.5,0);
  32.    moveto(x0 - 4.25,y0 + 3.25);
  33.    rlineto(0.5,0);
  34.    stroke();
  35.  
  36.    /* draw arrows to indicate optical transitions */
  37.    moveto(x0 + 3.5,y0 + 2.75);
  38.    arrowto(x0 + 1,y0 + 0.25);
  39.    moveto(x0 - 3.5,y0 + 2.75);
  40.    arrowto(x0 - 1,y0 + 0.25);
  41.  
  42.    /* label the photon */
  43.    text(x0 + 5, y0,"h!w! = 2E_g_");
  44.    /* but bar through h */
  45.    moveto(x0 + 4.95,y0 + 0.16);
  46.    rlineto(0.3,0.3);
  47.    stroke();
  48.  
  49.    /* draw bands again but higher up */
  50.    x0 = 10;
  51.    y0 = 19;
  52.    siband(x0,y0);
  53.  
  54.    /* draw single hole */
  55.    arc(x0,y0 - 0.25,0.25,0,360);
  56.    stroke();
  57.  
  58.    /* draw single electron */
  59.    moveto(x0 + 4.25,y0 + 3.25);
  60.    rlineto(-0.5,0);
  61.    stroke();
  62.    moveto(x0 + 3.5,y0 + 2.75);
  63.    arrowto(x0 + 0.5,y0 + 0.25);
  64.  
  65.    /* label photon */
  66.    text(x0 + 5, y0,"h!w! = E_g_");
  67.    moveto(x0 + 4.95,y0 + 0.16);
  68.    rlineto(0.3,0.3);
  69.    stroke();                
  70.  
  71.    /* add titles */
  72.    text(10.0,25.15,"Infrared Luminescence",CENTER);
  73.    text(10.0,11.8,"Visible Luminescence",CENTER);
  74.    }
  75.  
  76. int siband(double x0,y0)
  77.    {
  78.  
  79.    /* draws strained SiGe band structure */
  80.    /* as a set of parabolas */
  81.    parab(x0,y0,0.1,-0.1);
  82.    parab(x0,y0 - 1.0,0.05,-0.3);
  83.    parab(x0 - 4.0,y0 + 3.0,0.05,0.3);
  84.    parab(x0 + 4.0,y0 + 3.0,0.05,0.3);
  85.  
  86.    /* draw axes */
  87.    moveto(x0,y0 - 4.0);
  88.    rlineto(0,0.3);
  89.    moveto(x0,y0 - 4.0);
  90.    rarrowto(6,0);
  91.    moveto(x0,y0 - 4.0);
  92.    rarrowto(-6,0);
  93.    stroke();
  94.    moveto(x0 - 7, y0);
  95.    rarrowto(0,3);
  96.    rarrowto(0,-3);
  97.    moveto(x0 - 7.25,y0);
  98.    rlineto(0.5,0);
  99.    moveto(x0 - 7.25,y0 + 3);
  100.    rlineto(0.5,0);
  101.    stroke();
  102.  
  103.    /* draw a photon */
  104.    photon(x0 + 4.5,y0 + 1.5,0.3,0.3);
  105.  
  106.    /* a k vector labels */
  107.    text(x0,y0 - 5,"0",CENTER);
  108.    text(x0 + 6,y0 - 5,"k");
  109.    text(x0 - 7.5,y0 + 1.5,"E_g_",RIGHT);
  110.    }
  111.  
  112. int parab(double x0,double y0,double dx,double a)
  113.    {
  114.    int i;
  115.    double x;
  116.    /* draws a parabola by generating */
  117.    /* a data array first */
  118.    for (i = 0; i <= 50;i++)
  119.       {
  120.       x = i * dx;
  121.       pdat[50 + i][1] = a * x * x + y0; 
  122.       pdat[50 - i][1] = a * x * x + y0; 
  123.       pdat[50 + i][0] = x0 + x;
  124.       pdat[50 - i][0] = x0 - x;
  125.       }
  126.    moveto(pdat[0][0],pdat[0][1]);
  127.    for (i = 0;i <= 100;i++)
  128.       {
  129.       lineto(pdat[i][0],pdat[i][1]);
  130.       }
  131.    stroke();
  132.    }
  133.  
  134. int photon(double x0,double y0,double xscale,double yscale)
  135.    {
  136.    double x,y;
  137.    int i;
  138.  
  139.    /* draw a photon using the sine function */
  140.    moveto(x0,y0);
  141.    for (i = 0;i < 50;i++)
  142.       {
  143.       x = i * 0.255;
  144.       y = sin(x);
  145.       lineto(x * xscale + x0,y * yscale + y0);
  146.       }
  147.    set(FONTMULT,2);    
  148.    rarrowto(2.5 * xscale,0);
  149.    set(FONTMULT,0.5);    
  150.    stroke();
  151.    }
  152.