Bresenham's Line Drawing Algorithm | Computer Graphics

July 29, 2019 posted by



hello everyone welcome to my channel in this video I will explain your presence line drawing algorithm in the previous video we learn video line drawing algorithms if you haven't watched it yet I will provide the link in the description box first of all let's draw a computer screen in order to understand how computer draws a line on screen as I explained in the previous video computer screen consists of many pixels in order to draw a line on computer screen we should consider pixel and its computations we can show each pixel as X Y we should give endpoints and computer will draw a line between these endpoints but in order to do this computer should calculate which pixels to choose if slope is less than 1 then it should decide lower or upper pixels if slope is more than 1 then it should decide left or right pixels now let's draw a line on screen1 slope is less than 1 then x coordinates will change with unit interval it means that at every iteration the next coordinate of X will increase by 1 in this case computer should calculate y coordinate the intercept point will be between YK & YK plus 1 computer should decide YK or YK plus 1 which pixel is nearest to intercept point let's draw a parallel line to x coordinate in intercept point and call it as Y let's call the distance between y and y KS v1 the distance between YK plus 1 and y sp2 as you now the general line equation is y equal and X plus C here M is slope C is intercept point if M is less than one it means that X will change with unit interval so computer doesn't need to calculate the value of x because at every iteration it will increase by 1 as I said if we put the value of XK plus 1 in general line equation we can get this equation y equal m xk plus 1 plus e this is one of our equation which we will use in our further calculations now let's calculate the value of p1 v1 equals as you see in the graph y minus YK if we put the value of y from the previous equation we can write that y 1 equals M XK plus 1 plus t minus YK v2 equals YK plus 1 minus y again we put the value of y from the previous equation then v2 equals by K plus 1 – m xk plus one minus C now we should calculate the difference between t1 and t2 because the result will decide which pixel is nearer to intersect point if d1 minus d2 is a less than zero it means that the distance between intercept point and YK is less than the distance between intercept point and YT plus 1 so in this case computer will choose the lower pixel white case the next coordinate will be YK if T 1 minus T 2 is more than equal zero and computer will choose upper pixel and the next coordinate of life will be YK plus 1 let's have with t1 minus t2 we will replace the values of d1 and d2 based on previous equations as a result b1 minus b2 will be M XK plus 1 plus C minus YK minus YK minus 1 plus M X K plus 1 plus C now let's simplify this equation the 1 minus b2 equals to M XK plus 1 minus 2 YK plus 2 Z minus 1 here M be slope which equals Y Delta Y divided by Delta X we can replace the value of M by Delta Y divided by Delta X after replacing it we need to multiply each side by Delta X in order to avoid fractionally because it is really expensive computations for computer so if we multiply each side by Delta X our equation will be Delta X into T 1 minus T 2 equals Delta X into 2 Delta Y divided by Delta X into XK plus 1 minus 2 YK plus plus K minus 1 Delta X into D 1 minus T 2 is our decision parameter we can call our decision parameter f PK so PK equals Delta X V 1 minus V 2 the sine of PK will depend on the sine of p1 minus p2 because Delta X will be positive in this case the difference between t1 and t2 will determine the sine of PK now let's calculate the value of PK let's calculate after multiplier operation we will get PK equals to Delta Y XK plus 2 Delta Y minus 2 Delta X YK plus Delta X comma 2 si minus 1 now let's find PK plus 1 we will just replace X K and white key with XK plus 1 and YK plus 1 after this operation a let's find difference between PK plus 1 and PK so we will get 2 Delta Y XK plus 1 plus 2 Delta Y minus 2 Delta X bar k plus 1 plus Delta x2 C minus 1 minus 2 Delta Y XK minus 2 Delta y plus 2 Delta X YK minus Delta X 2 C minus 1 which removed it this and this one so we will after simplification we will get 2005 XK plus 1 minus XK minus two Delta X YK plus 1 minus K Y K so PK plus 1 equals PK plus 2 to the Y XK plus 1 minus XK minus 2 Delta X YK plus 1 minus YK so PK plus 1 is our decision parameter for next Courtney we already know that when slope is less than one then XK plus 1 will be XK plus 1 the next coordinate of X will increase by 1 if we put the value of XK plus 1 in our general formula we will get this new equation for PK plus 1 our new decision parameter will be PK plus 2 Delta Y because we will move XK and minus 6 K minus 2 Delta X YK plus 1 minus YK this is our new decision parameter for next coordinate when slope is less than 1 if slope is more than 1 we will just change X Y parameters so it will be PK plus 2 Delta X minus 2 Delta Y XK plus 1 minus X K this is our decision parameter for next coordinate van slope is more than 1 now let's find the initial decision parameter so first of all we should consider that in the initial point the value of x and y will be XK and YK now let's write the formula of PJ which we got in our previous calculation just to remind you I'm going to show you P initial equals to Delta Y XK plus 2 Delta Y minus 2 Delta X YK plus Delta X 2 Z minus 1 here we can replace C with y minus and X now let's continue our calculation for PK we are going to get this equation here we will replace em with Delta Phi divided by Delta X and PK equals to Delta Y XK plus 2 Delta Y minus 2 Delta X YK plus Delta x times 2y minus 2 X Delta Y divided by Delta X oh sorry minus 1 should be inside yes equal to Delta Y XK plus 2 Delta Y minus 2 Delta X YK plus if we multiply it it will be 2 Delta X Y minus 2 X 2 Delta Y X minus Delta X so here we will simplify our equation first of all we should replace x + y with XK and YK after replacing we will simplify our equation and for P initial we will get 2 Delta Pi minus Delta X this is our initial decision parameter so initial decision parameter will be 2 Delta Y minus Delta X when slope is less than 1 if slope is more than 1 we will again change the X Y parameter so we will get the initial equals to Delta X minus Delta Y when slope is more than 1 now let's see our conditions first of all let's see what happens when slope is less than 1 we know that when slope is less than 1 the next coordinate of X will be XK plus 1 so computers should decide y-coordinate in this case if PK decision parameter is more than an equal zero then the next coordinate of 5 will be YT plus 1 so in this case YT plus 1 will be nearer to intercept point and computer will choose YK plus 1 pixel next coordinate will be XK plus 1 YK plus 1 if PK is less than 0 then next coordinate of Y will be Y K so computer will choose lower pixel because YK will be nearer to intercept point and next coordinate will be XK plus 1 YK when slope is more than 1 then y coordinate will change with unit interval so next coordinate of Y will be YK plus 1 at every iteration so computer should decide for x coordinate in this case now let's see conditions when slope is more than 150 K more than and equals zero then the next chord leaf of X will be XK plus 1 next coordinates will be XK plus 1 YK plus 1 if the K is less than zero then next coordinate of X will be XK oh sorry XK plus 1 will be XK and next coordinate will be XK YK plus 1 okay guys all those on mathematical operation services for understanding the relation of person has a line drawing algorithm and to get the logic behind this algorithm however in exams all you need is to memorize these equations because I don't think that you will have enough time to calculate all those equations from the beginning I believe that you will definitely pass the exam also I will move paper script in description box so you can download it easily if you found this video helpful and want more videos like this please let me know bye bye

11 Comments

11 Replies to “Bresenham's Line Drawing Algorithm | Computer Graphics”

  1. ANIL KUMAR says:

    Your nails looking awesome😘😘😘
    &

    Way of explaining👍👍👍👍

  2. Jananie Balaji says:

    Thanks for explaining it patiently and clearly, especially the derivation part!

  3. pramit nath says:

    Great ! Very lucid way of teaching.

  4. Muhammed Ibrahim says:

    awesome job

  5. Nerd WithNoLife says:

    Best tutorial on this subject on Youtube, keep going! ( i can't stand other tutorials accent )

  6. Mzs Munna says:

    you just save my grade…. Thanks a lot !! keep it up….

  7. Kunal Singh says:

    Thanks

  8. Last Moment Tutorial says:

    And Background music too …😊👌

  9. Last Moment Tutorial says:

    Awesome explanation………. !😊😊

  10. rahul sharma says:

    Very helpful!!

  11. Renan Rosa says:

    Despite the difficulty of this task, it was a very nice explanation!

Leave a Comment

Your email address will not be published. Required fields are marked *