Back to index

radiance  4R0+20100331
Defines | Functions | Variables
genworm.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "calcomp.h"
#include "resolu.h"
#include "rterror.h"
#include "fvect.h"

Go to the source code of this file.

Defines

#define XNAME   "X`SYS`" /* x function name */
#define YNAME   "Y`SYS`" /* y function name */
#define ZNAME   "Z`SYS`" /* z function name */
#define RNAME   "R`SYS`" /* r function name */
#define PI   3.14159265358979323846
#define max(a, b)   ((a) > (b) ? (a) : (b))

Functions

double l_hermite (char *)
double l_bezier (char *)
double l_bspline (char *)
int main (int argc, argv)

Variables

static const char RCSid [] = "$Id: genworm.c,v 2.8 2004/08/21 11:54:06 greg Exp $"

Define Documentation

#define max (   a,
 
)    ((a) > (b) ? (a) : (b))

Definition at line 31 of file genworm.c.

#define PI   3.14159265358979323846

Definition at line 29 of file genworm.c.

#define RNAME   "R`SYS`" /* r function name */

Definition at line 27 of file genworm.c.

#define XNAME   "X`SYS`" /* x function name */

Definition at line 24 of file genworm.c.

#define YNAME   "Y`SYS`" /* y function name */

Definition at line 25 of file genworm.c.

#define ZNAME   "Z`SYS`" /* z function name */

Definition at line 26 of file genworm.c.


Function Documentation

double l_bezier ( char *  nm)
double l_bspline ( char *  nm)
double l_hermite ( char *  nm)
int main ( int  argc,
argv   
)

Definition at line 39 of file genworm.c.

{
       char  stmp[256];
       double  t, f, lastr = 0, r;
       FVECT  lastp, p;
       int  i, nseg;

       varset("PI", ':', PI);
       funset("hermite", 5, ':', l_hermite);
       funset("bezier", 5, ':', l_bezier);
       funset("bspline", 5, ':', l_bspline);

       if (argc < 8)
              goto userror;

       for (i = 8; i < argc; i++)
              if (!strcmp(argv[i], "-e"))
                     scompile(argv[++i], NULL, 0);
              else if (!strcmp(argv[i], "-f"))
                     fcompile(argv[++i]);
              else
                     goto userror;

       sprintf(stmp, "%s(t)=%s;", XNAME, argv[3]);
       scompile(stmp, NULL, 0);
       sprintf(stmp, "%s(t)=%s;", YNAME, argv[4]);
       scompile(stmp, NULL, 0);
       sprintf(stmp, "%s(t)=%s;", ZNAME, argv[5]);
       scompile(stmp, NULL, 0);
       sprintf(stmp, "%s(t)=%s;", RNAME, argv[6]);
       scompile(stmp, NULL, 0);
       nseg = atoi(argv[7]);
       if (nseg <= 0)
              goto userror;

       fputs("# ", stdout);
       printargs(argc, argv, stdout);
       eclock = 0;

       for (i = 0; i <= nseg; i++) {
              t = (double)i/nseg;
              p[0] = funvalue(XNAME, 1, &t);
              p[1] = funvalue(YNAME, 1, &t);
              p[2] = funvalue(ZNAME, 1, &t);
              r = funvalue(RNAME, 1, &t);
              if (i) {
                     if (lastr <= r+FTINY && lastr >= r-FTINY) {
                            printf("\n%s cylinder %s.c%d\n",
                                          argv[1], argv[2], i);
                            printf("0\n0\n7\n");
                            printf("%18.12g %18.12g %18.12g\n",
                                          lastp[0], lastp[1], lastp[2]);
                            printf("%18.12g %18.12g %18.12g\n",
                                          p[0], p[1], p[2]);
                            printf("%18.12g\n", r);
                     } else {
                            printf("\n%s cone %s.c%d\n",
                                          argv[1], argv[2], i);
                            printf("0\n0\n8\n");
                            f = (lastr - r)/dist2(lastp,p);
                            printf("%18.12g %18.12g %18.12g\n",
                                   lastp[0] + f*lastr*(p[0] - lastp[0]),
                                   lastp[1] + f*lastr*(p[1] - lastp[1]),
                                   lastp[2] + f*lastr*(p[2] - lastp[2]));
                            printf("%18.12g %18.12g %18.12g\n",
                                   p[0] + f*r*(p[0] - lastp[0]),
                                   p[1] + f*r*(p[1] - lastp[1]),
                                   p[2] + f*r*(p[2] - lastp[2]));
                            f = 1.0 - (lastr-r)*f;
                            f = f <= 0.0 ? 0.0 : sqrt(f);
                            printf("%18.12g %18.12g\n", f*lastr, f*r);
                     }
              }
              printf("\n%s sphere %s.s%d\n", argv[1], argv[2], i);
              printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n",
                            p[0], p[1], p[2], r);
              VCOPY(lastp, p);
              lastr = r;
       }
       return 0;

userror:
       fprintf(stderr,
"Usage: %s material name x(t) y(t) z(t) r(t) nseg [-e expr] [-f file]\n",
                     argv[0]);
       return 1;
}

Here is the call graph for this function:


Variable Documentation

const char RCSid[] = "$Id: genworm.c,v 2.8 2004/08/21 11:54:06 greg Exp $" [static]

Definition at line 2 of file genworm.c.