Yan Tran
Joseph Giardina

Lab 7
The Laser Cutter

In this lab, we were supposed to choose from a number of options to work with the laser cutter.
We choose to make an algorithm that made a family of shapes. In our case, we made a number of
circles to approximate a sphere. Our algorithm would use the equation of x2 + y2 = r2 to choose
various y points given their corresponding x points along a sphere of a fixed radius. Each y point
would become a circle. For example, if the radius of the sphere was 5 and you wanted to make a
circle at x=4 or four units away from the center of the sphere, you would end up with a circle of
radius one. If you were to make enough of these circles, a sphere could be approximated. An example of
this is given in the following figure:

We used C code to generate these circles and then translate them into HPGL code. The following is the
main part of the code:
int main(void){
int delta_x = 125; //half inch
float sphere_radius = 3.0; //sphere radius in inches //start at
largest radius and whittle down to smallest
float start_radius = sphere_radius*250.0;
float original_radius = start_radius;
int cross_sections = start_radius/delta_x;
float pi = 3.1415926535;
for (int x = 0; x != cross_sections; x++){
//create hpgl files that represent a circle with a given radius
//calculate local radius
float local_radius = sqrt((original_radius*original_radius) - ((delta_x*(x+1))*(delta_x*(x+1))));
if(!local_radius)
continue;
FILE *fd = NULL;
char filename[13];
sprintf(filename, "circle%d.plt",x);
fd = fopen(filename, "w");
if (fd == NULL){
perror("open_port: Unable to open temp file - ");
return 0;
}
fprintf(fd,"IN;SC0,2000,0,2000;SP1;PA;");//initialize
printf("local_radius %f, ",local_radius);
printf("delta_x*(x+1) %f\n", delta_x*(x+1));
fprintf(fd,"PU1000,1000;");
fprintf(fd,"CI%d;\n",(int)local_radius);
fclose(fd);
}
return 0;
}


The entire code can be found at http://www.cs.uml.edu/~fredm/courses/91.548-spr04/student/jgiardin/lab7/laser_circle2.txt

This code was then imported into CorelDraw for the generated circles to be displayed. Here is a screenshot:


The various circles were then cut out and spaced out on a pole, completeing the project.