30029 engineering visualization - laboratory practical -


I. 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.

• A line from (0, 0) to (300, 200).
• A line from (0, 200) to (300, 0).
• A line from (0, 0) to (200, 300).
• 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.

• A circle centred at (200, 80) with a radius 40.
• A circle centred at (80, 80) with a radius 60.
• A circle centred at (230, 210) with a radius 70.
• A circle centred at (90, 205) with a radius 55.

An example of the drawing result is given below.

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?).

3. Fill polygons.

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.

Polygon 1 Polygon 2 Polygon 3 Given below is an example showing the filling result of these polygons.

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.

b. Perform transformation operations specified below using the above implementation.
• Translate ‘Polygon 1' shown above to a new position. Move the polygon in steps so that a viewer can see it moving. You need to clean previous drawings for each new position of the polygon. The transformed result should show when the key ‘4' on the keyboard is pressed.

You may freeze the display for each position for a while so as to show the movement of the polygon clearly.

• Rotate ‘Polygon 2' shown above by a total of 90 degrees anticlockwise about one of the vertices of the polygon. Rotate the polygon in steps so that a viewer can see it rotating. The transformed result should show when the key ‘5' on the keyboard is pressed.
• Scale ‘Polygon 3' shown above by a factor of 1.5 in the horizontal direction and a factor of 2 in the vertical direction about one of the vertices of the polygon. Scale the polygon in steps so that a viewer can see it scaling. The transformed result should show when the key ‘6' on the keyboard is pressed.

Listed below are the requirements for Task 4, which should be addressed in your report.
i. Explain the basic concepts of 2D translation, rotation and scaling with the aid of relevant mathematical equations.
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?).

5. Perform a task of your choice, which can be used to distinguish you from others. This is a required task and it must be directly related to this unit of study. Use Display_9 of the sample program ‘EV_Shell_GL_CV' to show the result of this task. Examples of the task are given below.

Example 1: You find a problem during this lab practical. You decide to tackle the problem. You propose a method to solve the problem and implement the method using C++. You show results to verify your proposal.

Example 2: You find an interesting algorithm in the textbook, which has not been (and will not be) discussed in this unit of study. You decide to implement the algorithm in C++. You show results to verify your implementation.

Example 3: You find an interesting algorithm in visualisation in an IEEE journal. You decide to implement the algorithm in C++. You show results to verify your implementation.

The requirements for this task are listed below.
i. Please respond to the following questions in your report.
• What is the aim of the task? In other words, what do you want to do?
• Why do you want to do it?
• What are the challenges of this task when compared to the tasks above?
• How do you do it? In other words, can you explain your method or implementation?
• What are your results? Can you explain them?
• What can you conclude from the results?
• Have you achieved your aim?
• Is your conclusion significant and why?

III. Lab report

You need to write a report for this lab practical. You may exchange ideas and techniques with others. However, you must write your report independently. The requirements for your lab report are listed below.

i. Attach an assignment cover sheet that you have completed for this lab practical.
ii. State the aim of the lab practical.
iii. Include your response to the requirements for each task. Your report should be divided into sections such that each task is discussed individually in one section.
iv. Include the conclusion of this lab practical.

Attachment:- lab.rar

Request for Solution File

Ask an Expert for Answer!!
Visual Basic Programming: 30029 engineering visualization - laboratory practical -
Reference No:- TGS02771685

Expected delivery within 24 Hours