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

#define PI 3.14159

int
main( argc, argv, envp )
int argc;
char * argv[];
char * envp[];
{
	int stepsPerRev = 30;       /* How many steps per revolution to build */
	int revs = 2;                  /* How many helix revolutions to build */
	float radius = 2.0;                     /* Outter radius of the helix */

	int steps = revs * stepsPerRev;               /* Total steps to build */
	int step;                                      /* Current step number */
	float delta = 2.0*PI/(float)stepsPerRev;    /* Step size (in radians) */
	float theta;                     /* Current step's angle (in radians) */
	float x, y, z;                     /* Current step's spine coordinate */

	/* Output a VRML header */

	printf( "#VRML V2.0 utf8\n" );
	printf( "\n" );

	/* Generate an Extrusion representing the function */

	printf( "Shape {\n" );

		printf( "\tappearance Appearance {\n" );
		printf( "\t\tmaterial Material {}\n" );
		printf( "\t}\n" );

		/* Build the Extrusion geometry */

		printf( "\tgeometry Extrusion {\n" );
			printf( "\t\tcreaseAngle 0.7853975\n" );
			printf( "\t\tendCap   TRUE\n" );
			printf( "\t\tbeginCap TRUE\n" );
			printf( "\t\tsolid    TRUE\n" );

			/* Build Extrusion cross section (a rectangle) */

			printf( "\t\tcrossSection [\n" );
				/* Rectangle 1.0 x 0.2 */
				printf( "\t\t\t-0.5 -0.1,\n" );
				printf( "\t\t\t-0.5 +0.1,\n" );
				printf( "\t\t\t+0.5 +0.1,\n" );
				printf( "\t\t\t+0.5 -0.1,\n" );
				printf( "\t\t\t-0.5 -0.1,\n" );
			printf( "\t\t]\n" );

			/* Build the Extrusion spine (a helix) */

			printf( "\t\tspine [\n" );
				/* Helix */
				for ( step=0; step<steps; step++ )
				{
					theta = (float) step * delta;
					x = sin( theta ) * radius;
					y = (float) step / 15.0;
					z = cos( theta ) * radius;
					printf( "\t\t\t%f %f %f,\n", x, y, z );
				}
			printf( "\t\t]\n" );


		printf( "\t}\n" );

	printf( "}\n" );

}

