Implement bresenhams line algorithm

Assignment Help Visual Basic Programming
Reference no: EM131977216

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

Reference no: EM131977216

Questions Cloud

How long will take to pay off the mortgage : Your friend tells you he has a very simple trick for taking one-third off the time it takes to repay your mortgage: Use your Christmas bonus to make an extra.
Determine velocity that water flows out of the larger hose : The 4.0cm diameter hose is connected to the original hose. Determine the velocity that the water flows out of the larger hose
Identify and create a data flow diagram : Identify and create a Data Flow Diagram (DFD) relating the tables of your database schema through the use of graphical tools in Microsoft Visio.
Horizontal and vertical velocities of the ball : What are tge final horizontal and vertical velocities of the ball? Assume that there is no air friction.
Implement bresenhams line algorithm : 300029 ENGINEERING VISUALIZATION - Laboratory Practical - 2D GRAPHICS - Scan-convert lines using the mid-point line algorithm - Implement Bresenhams line
What would the annual yield to maturity be on the bond : Fresh Fruit, Inc. has a $1,000 par value bond that is currently selling for $1, 459. It has an annual coupon rate of 16.33 percent, paid semiannually.
Find the force constant of the spring : A 210 g block is attached to a horizontal spring and executes simple harmonic motion with a period of 0.400 s. If the total energy of the system is 3.50 J.
What rate of return need in order to achieve the goal : Franklin Templeton has just invested $9,560 for his son (age one). This money will be used for his son's education 17 years from now.
What is the mechanical advantage of a screwdriver : What is the mechanical advantage of a screwdriver used as a wheel and axle if its blade is 0.1 in. wide and the diameter of its handle is 0.3 in.?

Reviews

len1977216

5/9/2018 7:18:25 AM

5. Self- The aim is innovative and significant. The task is very challenging. Extensive 4 – 5 selected task observations and connections are made. Extensive results are presented and (Maximum 5 explained. The conclusion is significant and will be appreciated by practitioners raw marks) in the field. The aim and rationale are stated. The task is challenging when compared to 2 – 3 the set tasks. The method and implementation are described. Results are presented and explained. The conclusion is stated. The student makes observations and connections regarding the underlying task. The aim is

len1977216

5/9/2018 7:18:14 AM

At least 50% of the requirements for this task are addressed with correct answers. 2 At least 30% of the requirements for this task are addressed with correct answers. 1 Less than 30% of the requirements for this task are addressed with correct answers. 0 4. 2D Transformati ons (Maximum 4 raw marks) 100% of the requirements for this task are addressed with correct answers. 4 At least 90% of the requirements for this task are addressed with correct answers. 3 At least 70% of the requirements for this task are addressed with correct answers. 2 At least 40% of the requirements for this task are addressed with correct answers. 1 Less than 40% of the requirements for this task are addressed with correct answers. 0

len1977216

5/9/2018 7:18:07 AM

2. Scan- 100% of the requirements for this task are addressed with correct answers. 3 converting circles (Maximum 3 raw marks) At least 90% of the requirements for this task are addressed with correct answers. 2 At least 50% of the requirements for this task are addressed with correct answers. 1 Less than 50% of the requirements for this task are addressed with correct 0 answers. 3. Filling polygons (Maximum 5 raw marks) 100% of the requirements for this task are addressed with correct answers. 5 At least 90% of the requirements for this task are addressed with correct answers. 4 At least 70% of the requirements for this task are addressed with correct answers. 3

len1977216

5/9/2018 7:17:58 AM

IV. Marking criteria and standards The highest possible score for this lab practical is 20 in the form of raw marks. Then it will be scaled to normalise its contribution to 13.333% of the final grade for the unit. Task/Criteria Standards Raw Marks Awarded 1. Scan- 100% of the requirements for this task are addressed with correct answers. 3 converting lines (Maximum 3 raw marks) At least 90% of the requirements for this task are addressed with correct answers. 2 At least 50% of the requirements for this task are addressed with correct answers. 1 Less than 50% of the requirements for this task are addressed with correct 0 answers.

len1977216

5/9/2018 7:17:49 AM

Details for report submission are given below. i. Submit an electronic copy of your report to your lecturer through the ‘Lab Assignments’ section of the unit’s vUWS site (Lab Assignments ? Lab 2 ? ‘Browse My Computer’ to attach your report ? Submit). Please compress your report using WinZip to save space. Please DO NOT use ‘RAR’ to compress your files. ii. Submit an electronic copy of your complete C++ source code through the ‘Lab Assignments’ section of the unit’s vUWS site. Please delete the ‘Debug’ or ‘Release’ folder, and then compress your whole program using WinZip to reduce the file size. Please DO NOT use ‘RAR’ to compress your files. Your source code should compile and run under the Visual Studio 2017 development environment. If you do not submit your source code or your source code does not compile/run, your report may not be marked and you may be given a zero mark for this lab practical.

Write a Review

Visual Basic Programming Questions & Answers

  Create visual logic files to execute each of the tasks

Create a Word document for each of the tasks. The document should contain: a brief description of the task the pseudocode associated with the task Create Visual Logic files to execute each of the tasks.

  Code an application that calculates a customers discount

Code an application that calculates and displays a customer's discount and the total amount the customer owes. Create a Visual Basic Windows application.

  Attached is a form using visual basic.

For the Location the form should calculate the # of days for the class X the lodging fees for the city. Here are a list of lodging fees for the different cities.

  Write a program that uses an array of state objects

Write a program that uses an array of state objects and raises an event whenever the population density exceeds 10 million.

  Develop a bankaccount windows form project

Develop a "BankAccount" windows form project, which will allow user to

  Gas pumpa gas pump calculates the cost of gas at a local

gas pumpa gas pump calculates the cost of gas at a local gas station. the station charges 2.69 per gallon for regular

  Write the code to open the file and copy the raw data

Write the code to open the file and copy the ‘raw' data from the file into a ListBox. Write the code to save the data in the ListBox to a new file.

  Design a windows application and write the code

Design a Windows application and write the code that will execute according to the program requirements given below. Before designing the user interface, create a Use Case Definition. Before writing the code, create an event planning document for ..

  Calculate and display total number of cell phones ordered

The scottsville cellular solution needs to be coded so the calculate order button should calculate and display the total number of cell phones ordered and the total price of the order. Each phone costs $85.

  Develop a visual basic system to sell and print tickets

Design conditional and iteration constructs appropriate to a given programming task - Design well-written and readable programs

  Write a visual basic program

Write a Visual Basic program that inputs two integer numbers using Inputbox dialogs and computes the sum and average of the numbers after a click of a button

  Help an elementary school student learn multiplication

Write a program that will help an elementary school student learn multiplication. Use a Random object to produce two positive one-digit integers. The program should prompt the user with a question, such as "How much is 6 times 7?"

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd