CCL Home Page
Up Directory CCL mapcont.c
/* program to translate cylindrical coords to cartesian coords */

#include 
#include 
#include 

#define CART 1       /* convert to true cartesian */
#define PERS 2       /* use perspective mode as output by steric */
#define ROTA 0.0     /* default rotation about phi to perform */

#ifndef PI
#define PI       3.14159265358979323846
#endif
#ifndef PI_2
#define PI_2     1.57079632679489661923
#endif

int main(int argc, char *argv[])
{
  char line[255];
  double x,y,z;
  double xo=0.0,yo=0.0,zo=-1000.0;
  double phi,theta;
  double rotation=ROTA;
  char mode=CART;
  int i;
  for(i=1;i2*PI) rotation=ROTA;
  do
  {
    if(fgets(line,254,stdin)==NULL) break;
    if(line[0]=='q') break;
    if(strlen(line)>4)
    {
      if(sscanf(line,"%lf%lf%lf",&z,&phi,&theta)==3)
      {
        phi+=rotation;
	if(mode!=CART)
        {
          x=sin(theta)*cos(phi);
          y=sin(theta)*sin(phi);
	}
	else
	{
          x=z*tan(theta)*cos(phi);
          y=z*tan(theta)*sin(phi);
        }
        if(z!=zo)
        {
          if(zo>-1000.0) fprintf(stdout,"%10.6f %10.6f %10.6f\n\n",xo,yo,zo);
          xo=x; yo=y; zo=z;
        }
        fprintf(stdout,"%10.6f %10.6f %10.6f\n",x,y,z);
      }
    }
  } while(!feof(stdin));
  if(zo>-1000.0) fprintf(stdout,"%10.6f %10.6f %10.6f\n",xo,yo,zo);
  return(1);
}

Modified: Fri Dec 8 17:00:00 1995 GMT
Page accessed 4851 times since Sat Apr 17 21:59:45 1999 GMT