Back to index

radiance  4R0+20100331
Functions | Variables
gencat.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

Go to the source code of this file.

Functions

double Newton (double bl)
static void printhead (int ac, char **av)
int main (int argc, argv)

Variables

static const char RCSid [] = "$Id: gencat.c,v 2.6 2007/09/20 21:28:35 greg Exp $"
char * cmtype
char * cname
double z0
double z1
double k
double D
double d
double z
double h

Function Documentation

int main ( int  argc,
argv   
)

Definition at line 81 of file gencat.c.

{
   double x0, y0;
   double x1, y1;
   double b;
   double delh;
   double f, fprim;
   double hb, hc, fb, fc;
   int  n;

   if (argc != 11) {
      fprintf(stderr, "Usage: %s  material name x0 y0 z0 x1 y1 z1 k d\n",
              argv[0]);
      exit(1);
   }      

   cmtype = argv[1];
   cname = argv[2];
   x0 = atof(argv[3]); y0 = atof(argv[4]); z0 = atof(argv[5]);
   x1 = atof(argv[6]); y1 = atof(argv[7]); z1 = atof(argv[8]);
   k = atof(argv[9]); d = atof(argv[10]);
   D = sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
   b = Newton(0.0); 
   z = z0 - k * cosh(b);
   printhead(argc, argv);

   n = 0;
   for (h=0; h<=D; ) {
      f =  k * cosh(k*h+b) + z;
      fprim = k* k * sinh(k*h+b);
      delh = d / sqrt(1+fprim*fprim); 
      fprim = k * k * sinh(k*(h+delh/2)+b); 
      hb = sqrt(.01*fprim*fprim/(1+fprim*fprim));
      fb = sqrt(.01/(1+(fprim*fprim)));
      hc = sqrt(.04/(1+fprim*fprim));
      fc = sqrt(.04*fprim*fprim/(1+fprim*fprim));

      printf("\n%s polygon %s.%d\n", cmtype, cname, ++n);
      printf("0\n0\n9\n");
      printf("%f %f %f\n", h*(x1-x0)/D+x0, h*(y1-y0)/D+y0, f);
      if (fprim < 0)
      {
         printf("%f %f %f\n", (h+hc)*(x1-x0)/D+x0, (h+hc)*(y1-y0)/D+y0, f-fc);
         printf("%f %f %f\n", (h+hb)*(x1-x0)/D+x0, (h+hb)*(y1-y0)/D+y0, f+fb);
      }
      else if (fprim > 0)
      {
         printf("%f %f %f\n", (h+hc)*(x1-x0)/D+x0, (h+hc)*(y1-y0)/D+y0, f+fc);
         printf("%f %f %f\n", (h-hb)*(x1-x0)/D+x0, (h-hb)*(y1-y0)/D+y0, f+fb);
      }
      else 
      { 
         printf("%f %f %f\n", (h+.2)*(x1-x0)/D+x0, (h+.2)*(y1-y0)/D+y0, f);
         printf("%f %f %f\n", h*(x1-x0)/D+x0, h*(y1-y0)/D+y0, f+.1);
      }
      h += delh;
   }
   return 0;
}

Here is the call graph for this function:

double Newton ( double  bl)

Definition at line 50 of file gencat.c.

{
       double b;
       int n = 10000;

       while (n--) {
              b = bl- (cosh(k*D+bl)-cosh(bl)-(z1-z0)/k)/(sinh(k*D+bl)-sinh(bl));
              if (fabs(b-bl) < .00001)
                     return(b);
              bl = b;
       }
fprintf(stderr, "Interation limit exceeded -- invalid K value\n");
       exit(1);
}

Here is the caller graph for this function:

static void printhead ( int  ac,
char **  av 
) [static]

Definition at line 68 of file gencat.c.

{
       putchar('#');
       while (ac--) {
              putchar(' ');
              fputs(*av++, stdout);
       }
       putchar('\n');
}

Variable Documentation

char* cmtype

Definition at line 31 of file gencat.c.

char * cname

Definition at line 31 of file gencat.c.

double D

Definition at line 33 of file gencat.c.

double d

Definition at line 34 of file gencat.c.

double h

Definition at line 35 of file gencat.c.

double k

Definition at line 33 of file gencat.c.

const char RCSid[] = "$Id: gencat.c,v 2.6 2007/09/20 21:28:35 greg Exp $" [static]

Definition at line 2 of file gencat.c.

double z

Definition at line 35 of file gencat.c.

double z0

Definition at line 32 of file gencat.c.

double z1

Definition at line 32 of file gencat.c.