#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char **argv) {

/*
  double *curve_x, *curve_y;

  double lambda_c = 1.007;
  double lambda_r = 1.007;
  double lambda_z = 1.007;

  double r0 = 0.5;
  double z0 = 1.9;
  double c0 = 0.5;

  int curve_steps = 10;
  int spiral_steps = 360;

  double *curve_x, *curve_y;
*/

  double lambda_c = 1.007;
  double lambda_r = 1.007;
  double lambda_z = 1.007;

  double r0 = 0.5;
  double z0 = 10;
  double c0 = 0.5;

  int curve_steps = 10;
  int spiral_steps = 360;

  double delta_theta = 10.0 * M_PI/180.0;

  /* make the generating curve */
/*
  curve_x = (double *)calloc(sizeof(double),curve_steps);
  curve_y = (double *)calloc(sizeof(double),curve_steps);

  for (int step=0; step < curve_steps; step++) {
    double theta = step*(2*M_PI - 0.0)/curve_steps;

    curve_x[step] = cos(theta);
    curve_y[step] = sin(theta);
  }
*/

  double curve_x[] = { 0.0, 4.0,  5.0,  4.5,  1.5,  1.0,   0.0, -3.0, -3.5, -3.0 };
  double curve_y[] = { 3.0, 2.0, -1.0, -3.0, -4.0, -9.0, -11.0, -7.0, -2.0,  2.0 };

  //for(int i=0; i<curve_steps;i++) printf("%0.5lf %0.5lf\n",curve_x[i],curve_y[i]);
  
  /* now sweep the generating curve over the logarithmic spiral */

  for (int step=0; step < spiral_steps; step++) {

    /* find the current point on the spiral */

    double theta = step * delta_theta;
    double radius = r0 * pow(lambda_r,step);
    double height = z0 * pow(lambda_z,step);

    /* process the curve path */

    for (int i=0; i<curve_steps; i++) {

      double u = curve_x[i];
      double v = curve_y[i];

      /* scale */

      u = u * c0 * pow(lambda_c,step);
      v = v * c0 * pow(lambda_c,step);

      /* translate */ 

      u = u + radius;
      v = v + height;

      /* rotate (sweep) */

      double x = u * cos(theta);
      double y = u * sin(theta);
      double z = v;
     
      /* output */ 

      printf("%0.5lf %0.5lf %0.5lf\n",x,y,z);
    }
    printf("\n");
  }

  /* all done */

  //free(curve_x);
  //free(curve_y);
  return(0);
}
