Exemple #1
0
int
main(int argc, char *argv[]) {
    char *me, *outS;
    hestOpt *hopt;
    hestParm *hparm;
    airArray *mop;

    int fidx, aidx, num, frames;
    double psc, width[2], arrowWidth, lineWidth, angle, seglen,
           x0, y0, x1, y1, cc, ss;
    wheelPS wps;
    char filename[AIR_STRLEN_MED];

    me = argv[0];
    mop = airMopNew();
    hparm = hestParmNew();
    hparm->elideMultipleNonExistFloatDefault = AIR_TRUE;
    hopt = NULL;
    airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);
    hestOptAdd(&hopt, "w", "arrowWidth lineWidth", airTypeDouble, 2, 2, width,
               "1.0 0.2", "widths");
    hestOptAdd(&hopt, "n", "number", airTypeInt, 1, 1, &num, "10",
               "number of arrows");
    hestOptAdd(&hopt, "f", "frames", airTypeInt, 1, 1, &frames, "10",
               "number of frames");
    hestOptAdd(&hopt, "psc", "scale", airTypeDouble, 1, 1, &psc, "200",
               "scaling from world space to PostScript points");
    hestOptAdd(&hopt, "o", "prefix", airTypeString, 1, 1, &outS, NULL,
               "prefix of file names");
    hestParseOrDie(hopt, argc-1, argv+1, hparm,
                   me, interInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE);
    airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
    airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

    for (fidx=0; fidx<frames; fidx++) {
        sprintf(filename, "%s%03d.eps", outS, fidx);
        if (!(wps.file = airFopen(filename, stdout, "wb"))) {
            fprintf(stderr, "%s: couldn't open output file\n", me);
            airMopError(mop);
            return 1;
        }

        lineWidth = width[0];
        arrowWidth = width[1];
        wps.psc = psc;
        ELL_4V_SET(wps.bbox, -0.45, -0.85, 1.1, 0.85);
        wheelPreamble(&wps);

        fprintf(wps.file, "0 setlinecap\n");

        wheelGray(&wps, 0.4);
        wheelWidth(&wps, lineWidth);

        x0 = 0;
        y0 = 0;
        seglen = 1.0/num;
        angle = AIR_AFFINE(0, fidx, frames, 0, 2*AIR_PI);
        for (aidx=1; aidx<=num; aidx++) {
            cc = cos(angle*aidx)*seglen;
            ss = sin(angle*aidx)*seglen;
            x1 = x0 + 0.90*cc;
            y1 = y0 + 0.90*ss;
            wheelArrow(&wps, x0, y0, x1, y1, arrowWidth, arrowWidth*0.4);
            x0 += cc;
            y0 += ss;
        }

        wheelGray(&wps, 0.0);
        wheelArrow(&wps, 0, 0, x0, y0, arrowWidth, arrowWidth*0.4);

        wheelEpilog(&wps);
        airFclose(wps.file);
    }

    airMopOkay(mop);
    exit(0);
}
Exemple #2
0
int
main(int argc, char *argv[]) {
  char *me, *outS;
  hestOpt *hopt;
  hestParm *hparm;
  airArray *mop;
  
  double tval[6], ABC[3], geom[3], rnth[3], RA, norm, mu2, tmpr=0, tmpa=0,
    xroot[3], yroot[3], bbox[4], htick, htth, psc;
  wheelPS wps;
  int correct, labels, drawRA;

  me = argv[0];
  mop = airMopNew();
  hparm = hestParmNew();
  hparm->elideMultipleNonExistFloatDefault = AIR_TRUE;
  hopt = NULL;
  airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);
  hestOptAdd(&hopt, "t", "a b c d e f", airTypeDouble, 6, 6, tval,
             "nan nan nan nan nan nan nan",
             "six values of symmetric tensors");
  hestOptAdd(&hopt, "ABC", "A B C", airTypeDouble, 3, 3, ABC, "nan nan nan",
             "directly give coefficients of cubic polynomial "
             "(and override info from \"-t\")");
  hestOptAdd(&hopt, "g", "c rad th", airTypeDouble, 3, 3, geom, "nan nan nan",
             "directly give center, radius, and angle (in degrees) of wheel "
             "(and override info from \"-t\" and \"-ABC\"");
  hestOptAdd(&hopt, "p", "RA norm th", airTypeDouble, 3, 3, rnth, 
             "nan nan nan",
             "directly give RA, norm, and angle (in degrees) of tensor "
             "(and override info from \"-t\", \"-ABC\", and \"-geom\"");
  hestOptAdd(&hopt, "correct", NULL, airTypeInt, 0, 0, &correct, NULL,
             "when using \"-g\", be honest about what the estimated "
             "acos(sqrt(2)*skew)/3 is going to be");
  hestOptAdd(&hopt, "labels", NULL, airTypeInt, 0, 0, &labels, NULL,
             "put little labels on things; fix with psfrag in LaTeX");
  hestOptAdd(&hopt, "RA", NULL, airTypeInt, 0, 0, &drawRA, NULL,
             "draw extra geometry associated with RA");
  hestOptAdd(&hopt, "htick", "pos", airTypeDouble, 1, 1, &htick, "nan",
             "location of single tick mark on horizontal axis");
  hestOptAdd(&hopt, "htth", "thick", airTypeDouble, 1, 1, &htth, "3",
             "thickness of horizontal tick");
  hestOptAdd(&hopt, "bb", "bbox", airTypeDouble, 4, 4, bbox, 
             "nan nan nan nan", "bounding box, in world space around the "
             "region of the graph that should be drawn to EPS");
  hestOptAdd(&hopt, "ysc", "scale", airTypeDouble, 1, 1, &(wps.yscale), "0.5",
             "scaling on Y axis for drawing graph of characteristic "
             "polynomial, or \"0\" to turn this off.");
  hestOptAdd(&hopt, "psc", "scale", airTypeDouble, 1, 1, &psc, "100",
             "scaling from world space to PostScript points");
  hestOptAdd(&hopt, "o", "filename", airTypeString, 1, 1, &outS, "-",
             "file to write EPS output to");
  hestParseOrDie(hopt, argc-1, argv+1, hparm,
                 me, wheelInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE);
  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  if (!(wps.file = airFopen(outS, stdout, "wb"))) {
    fprintf(stderr, "%s: couldn't open output file\n", me);
    airMopError(mop); return 1;
  }
  airMopAdd(mop, wps.file, (airMopper)airFclose, airMopAlways);

  if (AIR_EXISTS(rnth[0])) {
    RA = rnth[0];
    norm = rnth[1];
    mu2 = (norm*norm/3)*(2*RA*RA/(1 + 2*RA*RA));
    geom[0] = sqrt(mu2)/(sqrt(2)*RA);
    geom[1] = sqrt(2*mu2);
    geom[2] = rnth[2];
    wheelGeomToRoot(xroot, yroot, geom);
    wheelGeomToABC(ABC, geom[0], geom[1], geom[2]);
  } else if (AIR_EXISTS(geom[0])) {
    wheelGeomToRoot(xroot, yroot, geom);
    if (correct) {
      tval[0] = xroot[0];
      tval[1] = tval[2] = 0;
      tval[3] = xroot[1];
      tval[4] = 0;
      tval[5] = xroot[2];
      wheelTenToGeom(geom,
                     tval[0], tval[1], tval[2], tval[3], tval[4], tval[5]);
      wheelGeomToRoot(xroot, yroot, geom);
    }
    wheelGeomToABC(ABC, geom[0], geom[1], geom[2]);
    wheelGeomToRNTH(rnth, geom[0], geom[1], geom[2]);
  } else if (AIR_EXISTS(ABC[0])) {
    wheelABCToGeom(geom, ABC[0], ABC[1], ABC[2]);
    wheelGeomToRNTH(rnth, geom[0], geom[1], geom[2]);
    wheelGeomToRoot(xroot, yroot, geom);
  } else {
    wheelTenToGeom(geom, tval[0], tval[1], tval[2], tval[3], tval[4], tval[5]);
    wheelGeomToRoot(xroot, yroot, geom);
    wheelGeomToRNTH(rnth, geom[0], geom[1], geom[2]);
    wheelGeomToABC(ABC, geom[0], geom[1], geom[2]);
  }
  fprintf(stderr, "%s: RNTH: %g %g %g\n", me, rnth[0], rnth[1], rnth[2]);
  fprintf(stderr, "%s: ABC: %g %g %g\n", me, ABC[0], ABC[1], ABC[2]);
  fprintf(stderr, "%s: xroot: %g %g %g\n",
          me, xroot[0], xroot[1], xroot[2]);
  fprintf(stderr, "%s: geom: %g %g %g\n", me, geom[0], geom[1], geom[2]);

  if (!AIR_EXISTS(bbox[0])) {
    bbox[0] = geom[0] - 1.2*geom[1];
    bbox[1] = - 1.2*geom[1];
    bbox[2] = geom[0] + 1.2*geom[1];
    bbox[3] = + 1.2*geom[1];
    fprintf(stderr, "%s: bbox %g %g %g %g\n", me,
            bbox[0], bbox[1], bbox[2], bbox[3]);
  }
  wps.psc = psc;
  ELL_4V_COPY(wps.bbox, bbox);
  wheelPreamble(&wps);

  /* graph */
  if (wps.yscale) {
    wheelWidth(&wps, 4);
    wheelGray(&wps, 0.5);
    wheelGraph(&wps, xroot[0], xroot[1], xroot[2]);
  }

  /* axis */
  wheelWidth(&wps, 2);
  wheelGray(&wps, 0.0);
  wheelLine(&wps, bbox[0], 0, bbox[2], 0);

  /* circle */
  wheelWidth(&wps, 3);
  wheelCircle(&wps, geom[0], 0, geom[1]);

  /* spokes */
  wheelWidth(&wps, 4);
  wheelLine(&wps, geom[0], 0, xroot[0], yroot[0]);
  wheelLine(&wps, geom[0], 0, xroot[1], yroot[1]);
  wheelLine(&wps, geom[0], 0, xroot[2], yroot[2]);
  
  /* dots at spoke ends */
  wheelDot(&wps, xroot[0], yroot[0], 0.025*geom[1]);
  wheelDot(&wps, xroot[1], yroot[1], 0.025*geom[1]);
  wheelDot(&wps, xroot[2], yroot[2], 0.025*geom[1]);

  /* lines from dots to roots */
  wheelWidth(&wps, 2);
  fprintf(wps.file, "gsave\n");
  fprintf(wps.file, "[2 4] 0 setdash\n");
  wheelLine(&wps, xroot[0], 0, xroot[0], yroot[0]);
  wheelLine(&wps, xroot[1], 0, xroot[1], yroot[1]);
  wheelLine(&wps, xroot[2], 0, xroot[2], yroot[2]);
  fprintf(wps.file, "grestore\n");

  /* tickmarks */
  wheelWidth(&wps, 6);
  wheelLine(&wps, xroot[0], -0.02*geom[1], xroot[0], 0.02*geom[1]);
  wheelLine(&wps, xroot[1], -0.02*geom[1], xroot[1], 0.02*geom[1]);
  wheelLine(&wps, xroot[2], -0.02*geom[1], xroot[2], 0.02*geom[1]);
  if (AIR_EXISTS(htick)) {
    wheelWidth(&wps, htth);
    wheelLine(&wps, htick, -0.04, htick, 0.04);
  }

  /* RA angle */
  if (drawRA) {
    wheelWidth(&wps, 3);
    wheelLine(&wps, 0.0, 0.0, geom[0], geom[1]);
    wheelWidth(&wps, 2);
    fprintf(wps.file, "gsave\n");
    fprintf(wps.file, "[2 4] 0 setdash\n");
    wheelLine(&wps, geom[0], geom[1], geom[0], 0);
    fprintf(wps.file, "grestore\n");
  }

  /* labels, if wanted */
  if (labels) {
    fprintf(wps.file, "/Helvetica findfont 20 scalefont setfont\n");
    wheelLabel(&wps, geom[0], 0, "center");
    wheelLine(&wps, geom[0], -0.02*geom[1], geom[0], 0.02*geom[1]);
    wheelLabel(&wps, (geom[0] + xroot[0])/1.8, yroot[0]/1.8, "radius");
    wheelWidth(&wps, 2);
    wheelArc(&wps, geom[0], 0, geom[1]/2, 0, geom[2]);
    wheelLabel(&wps, geom[0] + geom[1]*cos(AIR_PI*geom[2]/180/2)/2.5, 
               geom[1]*sin(AIR_PI*geom[2]/180/2)/2.5, "theta");
    if (drawRA) {
      tmpr = sqrt(geom[0]*geom[0] + geom[1]*geom[1]);
      tmpa = atan(2.0*rnth[0]);
      wheelWidth(&wps, 2);
      wheelArc(&wps, 0, 0, 0.2*tmpr, 0, 180*tmpa/AIR_PI);
      wheelLabel(&wps, 0.2*tmpr*cos(tmpa/2), 0.2*tmpr*sin(tmpa/2), "phi");
    }
    wheelLabel(&wps, xroot[0], yroot[0], "spoke0");
    wheelLabel(&wps, xroot[1], yroot[1], "spoke-");
    wheelLabel(&wps, xroot[2], yroot[2], "spoke+");
    wheelLabel(&wps, xroot[0], 0, "root0");
    wheelLabel(&wps, xroot[1], 0, "root-");
    wheelLabel(&wps, xroot[2], 0, "root+");
  }

  wheelEpilog(&wps);

  airMopOkay(mop);
  exit(0);
}