CS430 Homework Assignment 2
Programming Problem:
1. The new input Postscript commands you will be required to implement are:
1. x y moveto
2. x y lineto
3. stroke
moveto command simply moves the
pen to a particular location without drawing anything.
The lineto command draws a line
from the current position of the pen, to the point indicated.
The stroke command can be ignored
in your program, but actually draws the line sequence in Postcript interpreters
(e.g. gv).
The following commands will draw two boxes.
%%%BEGIN
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
100 100 lineto
stroke
300 300 moveto
400 300 lineto
400 400 lineto
300 400 lineto
300 300 lineto
stroke
%%%END
You can assume that a "moveto"/"stroke" pair defines a single closed
polygon
with no holes and with vertices given in counter-clockwise order.
Also that the input file will contain only one polygon.
You do not need to support line reading from HW1.
2. Modify your HW1 program to:
- Accept the "Moveto", "Lineto" and "Stroke" Postscript
commands as input.
- All the command-line options implemented in HW1 should be supported.
- The new default value for the "-f" option should be "hw2_a.ps".
- Read in a polygon from a file, apply 2D transformations to it, clip it
against the world window using the Sutherland-Hodgman algorithm.
- Display the edges of the clipped polygon with the code implemented in HW1.
- Do not just use your HW1 assignment to clip and draw the edges of
the (unclipped) polygon.
- The output of your program should be a set of lines that define a
closed polygon.
- Your new program should be named CG_hw2.
- You can test your program with several files:
hw2_a.ps,
hw2_b.ps,
hw2_c.ps,
hw2_d.ps.
- Input/Output Example: (Dark border is the window boundary)
i. Input:
./CG_hw2 -f hw2_a.ps -s 1.5 > hw2_ex1.ps
ii. Output: Postscript file
- Input/Output Example: (Dark border is the window boundary)
i. Input:
./CG_hw2 -f hw2_a.ps -m -250 -n -200 > hw2_ex2.ps
ii. Output: Postscript file
- Input/Output Example: (Dark border is the window boundary)
i. Input:
./CG_hw2 -f hw2_b.ps -a 170 -b 100 -c 270 -d 400 > hw2_ex3.ps
ii. Output: Postscript file
- Input/Output Example: (Dark border is the window boundary)
i. Input:
./CG_hw2 -f hw2_b.ps -s 2 > hw2_ex4.ps
ii. Output: Postscript file
- Input/Output Example: (Dark border is the window boundary)
i. Input:
./CG_hw2 -f hw2_c.ps -a 200 -b 100 -c 375 -d 400 > hw2_ex5.ps
ii. Output: Postscript file
- Input/Output Example: (Dark border is the window boundary)
i. Input:
./CG_hw2 -f hw2_c.ps -a 275 -b 100 -c 550 -d 502 > hw2_ex6.ps
ii. Output: Postscript file
- Input/Output Example: (Dark border is the window boundary)
i. Input:
./CG_hw2 -f hw2_b.ps -d 270 -c 435 -b 170 -a 100 -r 17 > hw2_ex7.ps
ii. Output: Postscript file
- Input/Output Example: (Dark border is the window boundary)
i. Input:
./CG_hw2 -f hw2_b.ps -a -135 -b -53 -c 633 -d 442 > hw2_ex8.ps
ii. Output: Postscript file
- Input/Output Example: (Dark border is the window boundary)
i. Input:
./CG_hw2 -f hw2_c.ps -a -150 -b -475 -c 123 -d -65 > hw2_ex9.ps
ii. Output: Postscript file
3. Steps in Assignment
- Read in a polygon
- Apply transformations to its vertices in world coordinates
- Clip transformed polygon to world window defined by a, b, c & d
- Write clipped polygon edges to standard out in Postscript format
4. Grading Scheme
- Assignment 1 features : 2 points
- Comand-line argument reading
- Output Postscript format
- Transformations
- Line clipping
- Windowing
- Postscript reading : 1 point
- Polygon clipping : 7 points
5. Submission Guidelines:
- Assignments must be submitted via Bb Learn.
- README file: explain the features of
your program, language and OS used, compiler or interpreter used,
name of file containing main(), and how to compile/link your program.
Text files only. Word and PDF documents will NOT be accepted.
- All source code. Your code must compile and run
on tux (Linux).
- You may program in any language you like as long it can produce
a usable executable named CG_hw2 on tux.
- Your program will be run by the TA. Please do
NOT submit any image files, Visual C++ project files, or anything not requested
in this section. Your program must run on tux without the
installation of "special" libraries.
- Makefile: have the default rule compile your program.
- If you are using a language that doesn't produce an executable file,
e.g. python, then be sure to include a script called CG_hw2 that
accepts arguments and prints PBM to standard out.
- Points will be deducted if submission guidelines are not followed.
- Further details about Bb Learn
- You can reach Bb Learn through DrexelOne.
- Choose Computer Graphics among your list of courses. There is an "assignments" link in
the left frame which will give you the list of assignments in the right frame.
- Click on the assignment you wish to submit.
- Find your file and click Upload button.
- Hit Submit button. DO NOT FORGET TO HIT THE SUBMIT BUTTON AFTER YOU UPLOAD ALL YOUR FILES.
NOTE: Your source code for all programming assignments will be run through
a plagiarism detection system. This program uses compiler techniques which
are invariant of syntax and style. If you are sharing code with other classmates,
you will get caught. Please refer to the student
handbook for actions that will be taken.
Last modified on October 23, 2023.