
#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 the Extrusion cross section (a rectangle in this case) */

			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 for our example) */

			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 );

					/* TASK2 */

					/* Insert a duplicate point to get a an arrow head */
					/* at the tail end of the extrusion */
					if ( step == steps-2 )
						printf( "\t\t\t%f %f %f,\n", x, y, z );


				}
			printf( "\t\t]\n" );


			/* Build Extrusion orientation (to make it twist) */

			printf( "\t\torientation [\n" );
				for ( step=0; step<steps; step++ )
				{
					theta = (float) step * delta;
					printf( "\t\t\t0.0 1.0 0.0  %f,\n", theta );
				}
			printf( "\t\t]\n" );


			/* TASK2 */

			/* Make the end of the ribbon an arrow (use the scale field) */

			printf( "\t\tscale [\n" );
				for ( step=0; step<steps-1; step++ )
				{
					printf( "\t\t\t1.0 1.0,\n" );
				}
				printf( "\t\t\t1.5 1.5,\n" );
				printf( "\t\t\t0.0 0.0,\n" );
			printf( "\t\t]\n" );


		printf( "\t}\n" );

	printf( "}\n" );

}

