AngleRaysSeg Documentation

The code presented in AngleRaysSeg.cpp is used to generate a postscript file with a drawing of a set of circles reflecting off a given set of segments. The input file contains the number of segments, the coordinates of their endpoints, the number of rays, the coordinates of the source of light, the start angle and the cone spread angle, in degrees. In order to shoot just one ray at a certain angle, one can input "1" for the number of rays, and use the start angle to direction the ray.

Input:

Executing the program

The Makefile:

#-----------------------------------------

AngleRaysSeg: AngleRaysSeg.o
g++ -o AngleRaysSeg AngleRaysSeg.o
AngleRaysSeg.o: AngleRaysSeg.cpp
g++ -c AngleRaysSeg.cpp


#-----------------------------------------
clean:
rm AngleRaysSeg.o AngleRaysSeg
#-----------------------------------------
 

To run:

% AngleRaysSeg < file.input > output.ps

Alternately, one does not have to run the program with an input file but it is necessary that an output postscript file be specified in order to view the saved image. Otherwise, the data is simply output to the screen and not saved.

There is also the option to run the program with debugging output. To do so:

% AngleRaysSeg [d] [D] < file.input > output.ps

 

Sample input file:

This input file will draw four segments in the shape of a square with 5 point gaps at each end. A light source will be generated in the center of the square emitting three rays over a span of ninety degrees, each ray thirty degrees apart. The light rays will bounce only once so that it is clear how the program manipulates the input.

 

Input file (file.input)

4
100 100 100 410
105 100 400 100
405 100 405 410
400 410 105 410
250 250
3
30 90
1

Output Postscript File (output.ps)

%!PS
.002 .002 setlinewidth
% ------------ Color ----------------%
/Rcolor { 1.0 0 0.45 setrgbcolor }def
% Number of segments and their coords:
50.000000 50.000000 translate
1.264198 1.264198 scale
newpath
100.00000 100.00000 moveto
100.00000 410.00000 lineto
105.00000 100.00000 moveto
400.00000 100.00000 lineto
405.00000 100.00000 moveto
405.00000 410.00000 lineto
400.00000 410.00000 moveto
105.00000 410.00000 lineto
stroke
.00 .00 setlinewidth
%Enter source coordinates:
%Enter number of rays:
%Enter positive start angle in degrees:
%Enter positive angle in degrees:
% Maximum number of ray bounces (nbmax):
newpath
250.00000 250.00000 moveto
405.00000 339.48929 lineto
Rcolor
stroke
newpath
250.00000 250.00000 moveto
292.87187 410.00000 lineto
Rcolor
stroke
newpath
250.00000 250.00000 moveto
157.62396 410.00000 lineto
Rcolor
stroke
/Times-Roman findfont % Get the basic font
8.701172 scalefont % Scale the font to 20 points
setfont % Make it the current font
newpath % Start a new path
-19.775391 -19.775391 moveto
(There are 4 segments, 3 rays; starts at point 250.000000, to 0.000000.) show
 
showpage
%EOF

 

The Postscript Image (output.ps)

 

Example Image 2 - Same scenario with ten bounces (shows light rays escaping mirror trap)

 

Example Image Three - Five Randomly Generated Segments

In this example SegGen was used to create an output file containing the coordinates of five randomly generated segments. We modified SegGen's output file so that its format would be compatible with AngleRaysSeg's input format. We chose the coordinates of the light source, the angular spread, ten bounces, and then ran AngleRaysSeg with the modified output file.

SegGen Input file

5

SegGen Output file

Desired number of segments?
5
65 327 59 63
430 353 368 270
492 283 463 497
264 138 391 291
418 83 421 151
213 133
1
499 130
Bounces:
5
 

AngleRaysSeg Result

 

 

Return to main page