Computer Graphics Lab 3
Computer Graphics Lab 3
Todays Lab:
The objective of todays lab is to implement basic line drawing algorithms like DDA and Bresenhams Line Drawing Algorithm.
Submission Requirements:
Submit your codes, only .cpp files, through LMS. Deadline: 5th March, 2012. Copy cases will be marked zero without any further clarification or discussion. Comments in your code can get you extra credit. Do add proper comments and always be prepared for viva.
Here you can find the coordinates of y for given x provided that slope of line is m and y intercept is b. On the computer screen, you can only plot points in the form of pixels. Pixels are present on screen in the form of rectangular grid. Actual line on screen should be displayed like this,
But as you can see all the pixels are not illuminated on screen. You cannot see the line on screen like this, but pixel by pixel illumination of points makes a line visible on screen. For that you can calculate the y coordinate for each increment in the value of x or vice versa. There are certain line drawing algorithms that calculate the pixels that should be illuminated on screen to draw a straight line. Although that line will not be straight but it will be visible in the form of straight line on screen. (Refer to Class Discussion for complete algorithm) Question 1: Draw a line from the point p1 (10, 10) to p2 (150,100). Also calculate the time to draw that line. Question 2: Draw a line on screen starting from point p3 (10, 15) having slope 0.75. You can draw it till x=150.
4. At each xk along the line, starting it k=0, perform the following test. If p k<0, the next point to plot is (xk+1,yk) and pk+1 = pk +2y Otherwise, the next point to plot is (xk+1, yk+1) and pk+1 = pk + 2y - 2x 5. Perform step 4 x-1 times.
Computer Graphics Using OpenGL Question 3: Draw a line from the point p1 (10, 10) to p2 (150,100). Also calculate the time to draw that line. Question 4: Draw a line on screen starting from point p3 (10, 15) having slope 0.75. You can draw it till x=150. Question 5: Draw a rectangle of height 100 and width 150 using both line drawing algorithms. Also calculate the time elapsed to draw both rectangles. NOTE: Submit your codes with a report of your comments about both algorithms. Evaluate both algorithms on the basis of your results.