If you want to be powerful, Educate yourself better.
--Your friends at LectureNotes

Note for Computer Graphics - CG by Art World

  • Computer Graphics - CG
  • Note
  • Kamla Nehru College - RTMNU
  • Computer Science Engineering
  • B.Tech
  • Uploaded 3 months ago
Art World
Art World
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-2

11/24/2018 Computer Graphics Line Generation Algorithm For example, as shown in the following illustration, from position 2, 3 you need to choose between 3, 3 and 3, 4 . You would like the point that is closer to the original line. At sample position X k + 1, the vertical separations from the mathematical line are labelled as d From the above illustration, the y coordinate on the mathematical line at x k Y = m$X So, d upper and d lower k$ + 1 + 1 upper and d lower . is − +b are given as follows − https://www.tutorialspoint.com/cgi-bin/printpage.cgi 2/5

Text from page-3

11/24/2018 Computer Graphics Line Generation Algorithm d lower = y − yk = m(X k + 1) + b − Y k and d upper = (yk + 1) − y = Y k + 1 − m(X k + 1) − b You can use these to make a simple decision about which pixel is closer to the mathematical line. This simple decision is based on the difference between the two pixel positions. d lower − d upper = 2m(xk + 1) − 2yk + 2b − 1 Let us substitute m with dy/dx where dx and dy are the differences between the end-points. dy dx(d lower − d upper ) = dx(2 dx (xk + 1) − 2yk + 2b − 1) = 2dy. xk − 2dx. yk + 2dy + 2dx(2b − 1) = 2dy. xk − 2dx. yk + C So, a decision parameter P for the kth step along a line is given by − k pk = dx(d lower − d upper ) = 2dy. xk − 2dx. yk + C The sign of the decision parameter P is the same as that of d k lower − d upper . If p is negative, then choose the lower pixel, otherwise choose the upper pixel. k Remember, the coordinate changes occur along the x axis in unit steps, so you can do everything with integer calculations. At step k+1, the decision parameter is given as − pk+1 = 2dy. xk+1 − 2dx. yk+1 + C Subtracting p from this we get − k pk+1 − pk = 2dy(xk+1 − xk ) − 2dx(yk+1 − yk ) But, x k+1 is the same as (xk) + 1 . So − pk+1 = pk + 2dy − 2dx(yk+1 − yk ) Where, Y k+1 – Yk is either 0 or 1 depending on the sign of P . k The first decision parameter p is evaluated at (x 0 0, y0 ) is given as − p0 = 2dy − dx Now, keeping in mind all the above points and calculations, here is the Bresenham algorithm for slope m < 1 − https://www.tutorialspoint.com/cgi-bin/printpage.cgi 3/5

Text from page-4

11/24/2018 Computer Graphics Line Generation Algorithm Step 1 − Input the two end-points of line, storing the left end-point in (x 0, Step 2 − Plot the point (x 0, y0 ) y0 ) . . Step 3 − Calculate the constants dx, dy, 2dy, and 2dy– 2dx and get the first value for the decision parameter as − p0 = 2dy − dx Step 4 − At each X along the line, starting at k = 0, perform the following test − k If p < 0, the next point to plot is (x k k + 1, yk ) and pk+1 = pk + 2dy Otherwise, (xk , yk + 1) pk+1 = pk + 2dy − 2dx Step 5 − Repeat step 4 dx– 1 times. For m > 1, find out whether you need to increment x while incrementing y each time. After solving, the equation for decision parameter P will be very similar, just the x and y in the equation gets interchanged. k Mid-Point Algorithm Mid-point algorithm is due to Bresenham which was modified by Pitteway and Van Aken. Assume that you have already put the point P at x, y coordinate and the slope of the line is 0 ≤ k ≤ 1 as shown in the following illustration. Now you need to decide whether to put the next point at E or N. This can be chosen by identifying the intersection point Q closest to the point N or E. If the intersection point Q is closest to the point N then N is considered as the next point; otherwise E. https://www.tutorialspoint.com/cgi-bin/printpage.cgi 4/5

Text from page-5

11/24/2018 Computer Graphics Line Generation Algorithm To determine that, first calculate the mid-point Mx + 1, y + ½ . If the intersection point Q of the line with the vertical line connecting E and N is below M, then take E as the next point; otherwise take N as the next point. In order to check this, we need to consider the implicit equation − Fx, y = mx + b - y For positive m at any given X, If y is on the line, then Fx, y = 0 If y is above the line, then Fx, y < 0 If y is below the line, then Fx, y > 0 https://www.tutorialspoint.com/cgi-bin/printpage.cgi 5/5

Lecture Notes