EXH.C

/****************************************************************************
        (c) 1984 - 2003 by Scientific Endeavors Corporation.
        All rights reserved.

        This program illustrates the E and H vectors for a plane wave
        travelling along the z-axis.
****************************************************************************/

#include <graphic.h>                           /* Include all needed files */

#if TCQ                                 /* Set stack for Borland (Turbo) C */
extern unsigned _stklen = 0x3000;
#endif

float pi = (float)PI;                                       /* Constant pi */
float z[51], x[51], x1[51], dz;                    /* Declare these arrays */
float ya[2] = {0.0f, 0.0f};                       /* externally to prevent */
float za[2] = {-3.0f, 3.0f};                             /* stack overflow */

/****************************************************************************
    Main program
****************************************************************************/
void GPC_MAIN(void)
{
    float zmin = -3.0f, zstp = 3.0f, zmax = 3.0f;
    float ymin = -3.0f, ystp = 3.0f, ymax = 3.0f;
    float xmin = 0.0f, xstp = pi, xmax = 3.5f * pi;
    float xvu = 40.0f, yvu = -10.0f, zvu = 10.0f;
    int i;

    bgnplot(1, 'g', "sample.tkf");               /* GraphiC initialization */
    startplot(BLACK);
    metricunits(0);                                 /* Plots are in inches */

    font(4, "swissbld.fnt", '\310', "news.fnt", '\311',    /* Select fonts */
        "newsgrm.fnt", '\312', "simplex.fnt", '\313');
    skew(.2f);                             /* Allow characters to be skewed */
    fillfont(1);                                    /* Enable font filling */

    page(9.0f, 6.884f);                      /* Size of page and plot area */
    area2d(7.6f, 5.5f);

    volm3d(20.0f, 6.0f, 3.0f);                       /* Input workbox size */
    vuabs(xvu, yvu, zvu);                               /* Input viewpoint */

    axesoff(AXESOFF);                    /* No axes since numbers unneeded */
    graf3d(xmin, xstp, xmax, ymin, ystp, ymax, zmin, zstp, zmax);

    color(WHITE);                                       /* Draw white axes */
    curv3d(ya, za, ya, 2);
    curv3d(ya, ya, za, 2);

    plane3d(3, 0.0f, 0);                       /* Draw labels in y-z plane */
    pltfnt(3.0f, 0.0f, "\311x", .1f, 0);
    pltfnt(0.0f, 3.0f, "\311y", .1f, 0);

/*
    DRAW THE CURVES IN SEPARATE HALF CYCLES TO GET
    THE CORRECT HIDDEN LINE EFFECT
*/

    acrop(1);                             /* Turn off cropping for vectors */
    dz = .02f * pi * 2.f;                     /* MAKE A CYCLE OF SINE WAVE */
    for(i = 0; i < 51; i++) {
        z[i] = i * dz;
        x[i] = 2.f * (float)sin((double)z[i]);
        x1[i] = 0.0f;
    }
    plane3d(1, 0.0f, 0);                                      /* x-y plane */
    curvfill(z, x, 26, z, x1, 26, 158, 0);  /* Fill between curve and axis */
    plane3d(2, 0.0f, 0);                                      /* x-z plane */
    curvfill(z, x, 51, z, x1, 51, 147, 0);  /* Fill between curve and axis */

    for(i = 0; i < 51; i++) {              /* MAKE NEXT CYCLE OF SINE WAVE */
        z[i] += pi;
        x[i] = -x[i];
    }
    plane3d(1, 0.0f, 0);                                      /* x-y plane */
    curvfill(z, x, 51, z, x1, 51, 158, 0);  /* Fill between curve and axis */
    color(BLACK);                            /* Draw black vector to erase */
    uvector(z[39], x1[39], z[39], x[39], 2.0f, .05f, "11");
    color(CYAN);                                   /* Now draw cyan vector */
    uvector(z[39], x1[39], z[39], x[39], 2.0f, .05f, "11");
    color(LGT_CYAN);                            /* Light cyan vector label */
    pltfnt(z[39], x[39], "\311`E`", .08f, 0);

    for(i = 0; i < 51; i++) {              /* MAKE NEXT CYCLE OF SINE WAVE */
        z[i] += pi;
        x[i] = -x[i];
    }
    plane3d(2, 0.0f, 0);                                      /* x-z plane */
    curvfill(z, x, 41, z, x1, 41, 147, 0);  /* Fill between curve and axis */
    color(BLACK);                            /* Draw black vector to erase */
    uvector(z[13], x1[13], z[13], x[13], 2.0f, .05f, "11");
    color(CYAN);                                   /* Now draw cyan vector */
    uvector(z[13], x1[13], z[13], x[13], 2.0f, .05f, "11");
    color(LGT_CYAN);                            /* Light cyan vector label */
    pltfnt(z[13], x[13], "\311`H`", .08f, 0);

    for(i = 0; i < 51; i++) {              /* MAKE NEXT CYCLE OF SINE WAVE */
        z[i] += pi;
        x[i] = -x[i];
    }
    plane3d(1, 0.0f, 0);                                       /* x-y plane */
    curvfill(z, x, 15, z, x1, 15, 158, 0);  /* Fill between curve and axis */
    color(YELLOW);                              /* Yellow vector and label */
    uvector(z[12], x1[12], z[25], x1[12], 2.0f, .05f, "11");
    pltfnt(z[26], x1[12], "\311`E\312*\311H`", .08f, 0);
    plane3d(0, 0.f, 0);             /* Reset the plane for normal plotting */

    color(GREEN);                                      /* Green plot title */
    titlht(.15f);
    fntchg((Uchar)'\311');
    d3head("The `E` and `H` vectors for a Plane Electromagnetic Wave", 't');
    dateit((Uchar)'\313');                  /* Put date-time stamp on plot */

    endplot();                                 /* GraphiC closing routines */
    stopplot();
}