Here is an example program with output:
--------------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
/*
* Program to generate a VRML file for a line given by
* a functional form. In this case x = z = 2**y.
*
*/
main()
{
int y;
float x,z;
printf("#VRML V1.0 ascii\n\n");
printf("Separator {\n");
printf(" Coordinate3 {\n");
printf(" point [\n");
/* Insert your favorite function here */
for (y = -10; y <= 10; y++) {
x = z = pow(2, y);
printf(" %f %f %f,\n", x, (float) y, z);
}
printf(" ]\n");
printf(" }\n");
printf(" IndexedLineSet {\n");
printf(" coordIndex [\n ");
for (y = 0; y < 21; y++) { /* This also depends on your function */
printf("%d, ",y);
}
printf("-1,\n");
printf(" ]\n");
printf(" }\n");
printf("}\n");
return 0;
}
Output:
--------------------------------------------------------------------------------
#VRML V1.0 ascii
Separator {
Coordinate3 {
point [
0.000977 -10.000000 0.000977,
0.001953 -9.000000 0.001953,
0.003906 -8.000000 0.003906,
0.007812 -7.000000 0.007812,
0.015625 -6.000000 0.015625,
0.031250 -5.000000 0.031250,
0.062500 -4.000000 0.062500,
0.125000 -3.000000 0.125000,
0.250000 -2.000000 0.250000,
0.500000 -1.000000 0.500000,
1.000000 0.000000 1.000000,
2.000000 1.000000 2.000000,
4.000000 2.000000 4.000000,
8.000000 3.000000 8.000000,
16.000000 4.000000 16.000000,
32.000000 5.000000 32.000000,
64.000000 6.000000 64.000000,
128.000000 7.000000 128.000000,
256.000000 8.000000 256.000000,
512.000000 9.000000 512.000000,
1024.000000 10.000000 1024.000000,
]
}
IndexedLineSet {
coordIndex [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19
, 20, -1,
]
}
}