Internal Code: 1HCJG
C++ Assignment Help:
Task:
Aim
Computer-generated graphics consist of objects, such as trees and buildings. An object can be described by fundamental elements, which are often called output primitives. Essential 2D output primitives include lines, circles and polygons. This laboratory practical aims to implement relevant algorithms to display essential primitives on a raster screen. Specifically, you will implement algorithms to convert ideal lines and circles into sequences of pixels, fill polygons and perform geometrical transformations on 2D objects.
II. Tasks
1. Scan-convert lines using the mid-point line algorithm.
a. Implement Bresenham’s line algorithm. The line algorithm discussed in Lecture 2 is designed for drawing a line with a slope between 0 and 1. You need to modify the algorithm so that a line with a slope of any value can be drawn. Place your drawing code in the drawing function of Display_1 (Display_1::Draw(...)) in the sample program ‘EV_Shell_GL_CV’. Your drawing results should show when the key ‘1’ on the keyboard is pressed. You may need to add more member functions to Display_1 to make your code easy to read.
Hints: The algorithm in the textbook may be used to draw a line with an arbitrary slope if the line can be transformed into a new line with a slope between 0 and 1. For a line with a slope between -1 and 0, the following changes may be necessary: (1) set y = -y at the beginning of the algorithm; (2) illuminate a pixel at (x, -y) instead of (x, y). For a line with a slope greater than 1, you may (1) swap x for y at the beginning and (2) illuminate a pixel at (y, x) instead of (x, y). For a line with a slope less than -1, you may (1) set x = -y, y = x at the beginning and (2) illuminate a pixel at (y, -x) instead of (x, y).
b. Draw lines specified below using Bresenham’s line algorithm. All lines should show when the key ‘1’ on the keyboard is pressed.
1. A line from (0, 0) to (300, 200).
2. A line from (0, 200) to (300, 0).
3. A line from (0, 0) to (200, 300).
4. A line from (0, 300) to (200, 0).
Listed below are the requirements for Task 1, which should be addressed in your report.
i. Explain how Bresenham’s line algorithm works and why it is efficient when compared to other algorithms/methods.
ii. Summarise the C++ source code that you have written for the task using a sequence of steps, a flow chart or pseudo-code.
iii. Explain each step of your C++ source code clearly so that an experienced reader can repeat the task to obtain the same result without the need of your C++ code.
iv. Include the drawing result of the task in your report.
v. Explain the drawing result you have obtained (e.g., what has been drawn? Have you drawn what you are asked to draw?).
2. Scan-convert circles using the mid-point circle algorithm.
a. Implement the mid-point circle algorithm discussed in Lecture 2. Place your drawing code in the drawing function of Display_2 (Display_2::Draw(...)) in the sample program ‘EV_Shell_GL_CV’. Your drawing results should show when the key ‘2’ on the keyboard is pressed. You may need to add more member functions to Display_2 to make your code easy to read.
b. Draw circles specified below using the mid-point circle algorithm. All circles should show when the key ‘2’ on the keyboard is pressed.
1. A circle centred at (200, 80) with a radius 40.
2. A circle centred at (80, 80) with a radius 60.
3. A circle centred at (230, 210) with a radius 70.
4. A circle centred at (90, 205) with a radius 55.
Listed below are the requirements for Task 2, which should be addressed in your report.
i. Explain how the mid-point circle algorithm works and why it is efficient when compared to other algorithms/methods.
ii. Summarise the C++ source code that you have written for the task using a sequence of steps, a flow chart or pseudo-code.
iii. Explain each step of your C++ source code clearly so that an experienced reader can repeat the task to obtain the same result without the need of your C++ code.
iv. Include the drawing result of the task in your report.
v. Explain the drawing result you have obtained (e.g., what has been drawn? Have you drawn what you are asked to draw?).
a. Write a C++ program for polygon filling by scan conversion (Lecture 3). Your code should be able to fill a polygon with an arbitrary number of vertices. Place your drawing code in the drawing function of Display_3 (Display_3::Draw(...)) in the sample program ‘EV_Shell_GL_CV’. Your drawing results should show when the key ‘3’ on the keyboard is pressed. You may need to add more member functions to Display_3 to make your code easy to read.
Hints: A sample program is given in the following book: D. Hearn, M.P. Baker, Computer Graphics C Version, 2e, pp. 122 – 125, Prentice-Hall, 1997. A scanned copy of the program is posted to vUWS.
b. Fill polygons shown below in red using the above filling algorithm. You can decide the actual coordinates of the vertices of each polygon while the shape of the polygon must be preserved. Filled polygons should show when the key ‘3’ on the keyboard is pressed.
Listed below are the requirements for Task 3, which should be addressed in your report.
i. Explain how the polygon filling algorithm works with the aid of relevant illustrations.
ii. Summarise the C++ source code that you have written for the task using a sequence of steps, a flow chart or pseudo-code.
iii. Explain each step of your C++ source code clearly so that an experienced reader can repeat the task to obtain the same result without the need of your C++ code.
iv. Include the drawing result of the task in your report.
v. Explain the drawing result you have obtained (e.g., what has been drawn? Have you drawn what you are asked to draw?).
4. Transform 2D objects.
a. Implement 2D transformation matrices for translation, rotation and scaling in homogeneous coordinates discussed in Lecture 5. Place the translation code in the drawing function of Display_4 (Display_4::Draw(...)), the rotation code in Display_5::Draw(...) and the scaling code in Display_6::Draw(...) in the sample program ‘EV_Shell_GL_CV’. Your transformation results should show when the keys ‘4’, ‘5’ and ‘6’ on the keyboard are pressed. You may need to add more member functions to make your code easy to read.