Bresenham's Line Drawing Algorithm

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the topic for this video is the bresenhem's line drawing algorithm this one of the important algorithm in computer graphics and this is very simple and easy algorithm now the topic is that I have here to discuss in this video is basics that are required for understanding this algorithm I'll discuss the basics then and Nexis drawback of DD algorithm already I have one video on the DD algorithm so there are some drawbacks so that is the reason we require bris an amalgam of Barisan amalgam is a design it to avoid the drawbacks so what are the drawbacks we'll discuss that then problem with flows so that's the problem with the DD so why float is a problem I will explain you that then derivation of bresenham's algorithm so there's lot of mathematics involved for deriving bresenham's algorithm that we will do and then we will see their algorithm and then we will follow the algorithm and solve one problem so these are the topic that I am going to come and one more thing I have to say I have two courses in udemy one on c++ learning C++ from beginners to the advanced level beginners who have never done programming and to the advanced level that is useful for industry or cracking introduced if you are refresher then you should take this course you will get good grip in C++ programming and one more thing learning C++ is learning oops and the way oops is covered is more intuitive and so very easy you can easily understand oops and you can use it practically so I suggest you take that course if you are learning C++ among the courses in data structures using C and C++ and some algorithms are there that are related to data structures so it's not datas algorithms as a subject this data structure along with that some algorithms are also there so it's a 50-yard score so data structure is covered in more and more detail that is useful for academics as well as it is useful for cracking interviews as a fresher right for a job interview mostly companies ask questions from basic core subjects and one of the subject data structures and programming they asked questions from oops so I suggest you take up these courses and you prepare for your interviews and even they are useful for economics now let us start with the basics first thing I will tell you about two line see suppose this is a very classic system and this is the origin this is x axis this is y axis and any line in the system is represented with a formula that is y is equals to M X plus C where m is the slope of a line that is difference in Y by difference in X dy by DX and x and y are the coordinates and series y-intercept at which point the line is intersecting with y-axis so you should be knowing about this basic formula this difference in x and difference in virus suppose this is a line segment between these two points so the difference in this x-value so this is X 1 and X 2 and difference in Y values this is y 1 and y 2 that differences are taken difference in x and difference in Y so this is the line formula next therefore the slope of this line if I draw them again once again here see if the line is going through it this audition and it is having 45 degrees angle 45 degrees angle then the difference in X and the difference in Y will be equal and when the both are equal then it will be 1 so yes the slope of this line is 1 so if a line is of 45 degrees in a coordinate system that is two dimensional coordinate system then that line is having slope value and if the line is having less angle less than this one that if this is a line then it's slope is less than 1 in this the difference in X will be greater than difference in Y so difference in X will be more than difference in Y if the line is less than 45 degrees its slope will be less than 1 and if you have a line that is greater than 45 degrees then its slope will be greater than one see the difference in X will be small right this this is the exponent and this is x2 this difference is small and this difference is more Y difference is more X is difference is very small so that's why this will have the slope greater than one because if the numerator is greater you will get the value greater than one right if the new denominator is greater you will get the value less than one so we are going to learn about bresenham's algorithm for the lines that are having slope less than 1 and for slope greater than 1 also it can be written you can easily convert this algorithm into 4 line greater than 1 slope greater than 1 this is a matter of changing x and y values so this is about the line now next thing see this is our screen right monitor our monitor or the screen will have the collection of pixels so actually origin will be here and this will be the x axis and this is the y axis downwards but for studying purpose we study everything in our world coordinate system world coordinate system is the coordinate system that we use on paper pen and paper when we draw something that coordinate system so in that coordinate system origin will be here so i am starting from 1 onwards right this is the first pixel onwards so origin is here so this is x axis and this is y axis so you'll study everything based on this one right based on this one then we transform it for the monitor or display devices so all monitor you will have collection of pixels these are the Dixons now next important basic point see this is the line equation so any line in the coordinate system can be defined by this line equation and this is called as vector but this equation is not useful directly on the screen because screen is a collection of pixels so that is called as raster it is called as a raster so if I have to draw this line here then I have to define it in terms of pixels let us say this pixel if you take this is defined in terms of 2 comma 3 and the next if I have to take this pixel that is 3 comma 4 so we have to define a line in the form of collection of pixels so from the formula to collection of pixels converting a vector into raster is called as rasterization so we have to draw a line means we have to rasterize a line now next we will learn one more important term so for that I'll remove this and I'll explain now how we get these points for a line from this equation see we have some slope we have some constant then what we don't know here is x and y values so from a single formula can you get two values no you cannot get two values so you need two formulas but from single formula we want X value as well as Y value then for that you have to sample one manual sample means you have to put the value by yourself then you get another value so one value will have to take it by ourselves then from one equation we can get only one value so which value I should assume we should assume this value X value Y see we are trying to draw lines with slope less than 1 means X values will be more and Y values will be less so these more values more number of values for example this X is 2 and this X 2 is 8 then we can sample this x value from 2 to 8 so for every X we will get the Y value so that is called a sampling so let us take one line and sample it suppose I want to draw a line like this right line like this so from 2 to 8 so I want to draw a line from 2 to 8 with the Y value as 3 suppose the line should be between these right I want the line between so for this line if I want to get all the pixels then this is 2 comma 3 the next X is 3 and for that y is again 3 only then for this is also 3 then this is also 3 this is also 3 these are see this line slope is actually 0 right I am NOT writing the formula the slope of this line is 0 so when I am sample the X values X values are changing next every time I am getting incremented but Y is remaining same because slope is less than 1 so in this case we are sampling X values and getting Y values so for all those lines whose angle is less than 45 degrees or slope is less than 1 we can sample x-values and for the lines whose slope is greater than 1 we can sample y-values and get X values so in this way we have more number of X we sample X if you have more number of my the sample y know by sampling if I draw a line with 45 degrees how it looks like let us see see if I have to draw a line from 1 comma 1 to 8 comma 8 this is the line all right so I want to draw a line so I'll remove this I'll remove these points then if I draw a line a line goes like this so all these pixels will be clone all these pixels will be going right and in this case no the important thing X values as many X values same number of Y values so always X will also increment and Y will also increment for the line having slope that is equal to 1 so just check it 1 comma 1 this is 2 comma 2 and this is 3 comma 3 and this is 4 comma 4 this is 5 comma 5 and this is 6 comma 6 so both x and y are increasing now let us take one line whose slope is less than 1 I'll draw it here suppose I want to draw a line from 2 comma 1 to 8 comma 3 so if I draw this line it goes like this now the problem see this for this 2 x x value as 2 y is 1 then x value as 3 y value which one I should take so you can see this line is going from partially from this pixel and this pixel also right it is going from this also and this also in this case okay it's going from here it's going from here ok I can take this pixel I can take this pixel I can take this pixel but again here partial is going from this pixel partial it's going from this pixel shall I take this pixel or this pixel now same problem we are facing here shall I take this pixel or this picture because partially it is in this block and it is in that block so if I show it here it is going like this it's going like this so it's going partially from this pixel also and this pixel also so whether I should take this pixel of the Rickson that is the problem when we draw lines with slope less than 1 X will always be incrementing but Y will not increment so if you see X is implementing from 2 to 8 right total it is 7 pixels but a y-value from 1 to 3 so only 3 pixels so it's moving on the 3 so Y will not increment always so whether to increment Y or not that's what the decision we have to take so these are the important things that I have explained you these are the basic side on you so just let me repeat once more the basics I told you I have given you line equation then I said that the lines with slope equal to 1 less than 1 or greater than 1 then I told you about rasterization converting this into pixels the next thing I told you sampling the values right sampling the values I have told you and the last thing I told you that for the line having slope equal to 1 both x and y will increase always but for lines with slope less than 1 exhale increase always but Y may or may not increase because number of pixels and Y are not equal and when we are drawing a line line is going through partially 1 pixel and partially another pixel so these are the basic things that we have learned now let us go to the drawback of DDL got drawback of DD algorithm so you should be knowing DD algorithm I have written few steps here see we find out which values we should sample either X value or Y value it works for any type of line right for line with slope less than 1 or greater than 1 for all it works so whichever value we should sample we take the maximum and step and here is the problem see we take the X increment value as difference in X by a number of steps and Y also divided by step so division operations used here division operation gives flow results fluid results right so DD algorithm uses float so why it needs float why it is using float on the screen we have only integer see these pixels are all integers only so yes it uses float because here we get the float value for the pixels that we are unable to decide whether to take this one or this one at that places it gets some decimal values and it will round off those values ad D algorithm will round off those values so finally I can say that when there are no decimal values only pixels are in integer form ydd is calculating float and the wild is rounding off again and it is taking out the decimal part so when it is not useful why it is using float this is the problem so we want to avoid floats so for that reason bresenham's algorithm is designed to remove float because there are no floats on the screen now next thing what is the problem with the float see if you have integer values or if you have float values then the processing time for float is more than the time taken for integers for addition of floats or multiplication or division of float whatever the operations you are performing upon flowed the time taken for performing operations on float is more than integers now while float requires more amount of time you have to find out it by yourself right so float processing takes more time so unnecessary we are generating float and again we are truncating it or running of the value that is useless in that the time taken will be more so bresenham's algorithm is used now what is the idea of precedent algorithm we will discuss that and we will derive it so for that I will remove this one and I will use these pictures now the idea behind bresenham's algorithm so we will see the idea based on which it is a devised see I have shown you this line this line is going through partial in this pixel also this picture also which pixels to take in DDA it will round off and take it so that's why it get a crook the line in DDA we don't get a smooth line but here we want to get a smooth line so we want to find out exactly which pixel we should take so when the line is going from this also this also means actually it's not going through one of the pixel it is going through bit in between the pixels so in between the pics there is new space but when it is going partially over to pixels then we should believe that it is going from in between the pixels though there is no gap there on the screen so but we will try to imagine it so for that I have separated these two pixels and I am showing a gap here this is the gap there in real on the screen there is no gap but actual line is going from this gap so I have taken these four pixels these four pixels so these pixels with the gap in between them now from here I will draw a line see the line is going like this this is the line right so we believe that it is going from in between the pixels so the gap in between the pixels if you say this is 1 and this is 2 this is 1 and this is 2 so there is a gap in between 2 comma 1 and 2 comma 2 so that gap is there so when it is going through a gap we have to decide which pixel to take so we say that impression and says that we should take the nearest pixel so how do you know the nearest pixel to that actual line see the actual point that line is giving is this once this is actual X plus 1 XK plus 1 comma Y for an actual line so shall we take this one on this one so for that we will see how much it is away from this pixel and how much away it is from this pixel so we'll find out two values distance 1 and distance 2 so d1 is the distance from the actual point that we are getting to this pixel and the distance the d2 is to the actual point to this pixel now whoever distances less it is closer to whichever point we should take that one now from here our derivation starts for derivation we should keep few things in our mind first thing is we are presently on this pixel remember this this is XK and YK and every time X will increase by 1 so next X will be XK plus 1 and Y whether it will increase or not that's what we have to decide means whether it remains Y key only or it will become increment by 1 and it will become YK plus 1 so what will be next every time X next will always be XK plus 1 but what will be Y next y next can be either same YK or it may be YK plus 1 so that's what we have to decide whether we should keep YK as it is or increment it by 1 this is what the decision we have to take so once again I'll tell you we are on this pixel that is XK YK and we are calculating for this pixel that is XK plus 1 right we have to find out what is y whether to take this one or this one only so as per this line equation so if you find out this Y value Y value is M into XK plus 1 plus C this is the line equation which gives you the exact point here Y value that will be in float but we want integer value so that I said we will be deciding based on the distance between this pixel to the line and this pixel to the lines are the tightest D 1 and D 2 so let us find out D 1 and D 2 so what is a d1 distance 1 distance 1 is actual Y minus YK actual y minus YK and distance 2 what is the distance to YK plus 1 minus actual y YK plus 1 that is incremented when YK plus 1 YK plus 1 minus action Y value these are the distances D 1 and D 2 let us use this Y value and this one so actual line y is this one right so let us put it here so this is ys m xk plus 1 plus c minus YK minus YK i have taken this one then what about this YK plus 1 as it is this is plus 1 whatever Y is suppose this is 5 so this is 6 5 plus 1 then minus y why is this one so minus this is y so that is n into XK plus 1 plus C this is in bracket - on the whole expression so if I open this bracket then this also becomes - I have open so from here also I will remove the bracket so there is no need of bracket now and this is all positive only so now we have distance one and distance 2 now you want to know whichever is closer we should take that pixel so how to know so if you subtract a D 1 and D 2 then you can know which is smaller which is creative so if d1 minus d2 if it is less than 0 it means it is closer to this pixel means the distance one is a smaller if d1 minus d2 is greater than zero means this distance is smaller d2 is a smaller so this pixel is actual line point is closer to this pixel so based on this difference of d1 and d2 we can decide which pixel to take this means YK will be same only and this means we should increment Y we should take this pixel so based on this we can take decision so now we can call this as decision parameter so let us calculate d1 minus d2 and define our decision parameter so first I will find out d1 minus d2 so I will subtract them and write the formula here so this is d 1 this is d1 minus minus and this is d 2 this is d 2 now if you open this bracket as this is minus sign so I'll open this bracket and write down the expression once again so here I have opened the bracket this is minus YK minus 1 and this becomes plus and this becomes plus so I have open the bracket now if you observe and into XK plus 1 I mean 2 XK plus 1 2 times minus YK minus YK 2 x plus C plus C 2 x and this is minus 1 just one time so all these will be 2 times and this is minus 1 I will write down then again by multiplying by 2 so here I write the expression so this is the final formula that is d1 minus d2 but in this formula there is one problem and then what is Emma Emma's difference in Y by difference in X Oh again this gets float result yes we want to get rid from this float value but still this is having M that is float so we should remove that floor how to remove that float remove this denominator how I can remove the denominator x difference in X if you multiply it by difference in X that denominator will get cut off so then same way it will get multiplied with all same difference in X will multiply with all so let us multiply both the side with a difference in X so I will remove this and I will write on this one so if you want to copy you can copy up to here pause the video and copy this one so for this equation I have multiplied both the sides by DX right and here M I have written it as dy by DX so let us open this one multiply that is difference in X with all DX with all so this will be DX D 1 minus D 2 then this will be if I multiply this gets cancel this is 2 Delta Y that is DX XK plus 1 and this will be minus 2 Delta X into y K plus 2 Delta X into C minus Delta X so this is the expansion of this formula now still there is one bracket let us open that one also so this is difference in X into D 1 minus D 2 and this is 2 Delta Y that is X K and this one I will write on first minus 2 Delta X Y K and this portion have a ride on that is 2 Delta Y into 1 so this is plus 2 Delta Y only and this is plus 2 Delta XC minus Delta X so this is the equation we got let us call this equation as a decision variable so will a new name to this one let us call it as pk this is a decision variable so let us give a name that is PK this is PK and in this one if you observe this is constant value that is difference in Y that is a difference in Y for a line and difference in X and constant they all remain same and which the terms are dependent on XK and YK only two terms are dependent so we can skip this portion of a formula and we can write PK as 2 Delta Y XK minus 2 Delta X Y K this is the PK formula as we are using this for taking a decision so this remains constant so constant will not have any effect on the decision so that's why we have removed it now this PK will be keep on changing we are talking about this pixel then again when we move to the next pixel again we need to take a decision so every time for every pixel we have to take a decision X is increasing every time whether to increase Y or not we have to take a decision so for that this formula will tell if this PK value is less than 0 then this is the pixel we have to take if it is greater than 0 we have to take this one but for every pixel we need that one so we need to find out the decision parameter for the next pixels and that will be for the next pixel so let us call it as PK plus 1 and this I will call it as 2 Delta Y X next next picture and minus 2 Delta X Y K so that is why next Y next as I said xn x is always XK plus 1 and Y next we don't know whether it will be Y key or YK plus 1 it will increment or not we don't know so I am calling it as next right and let us call this also as T next so this will be the formula for the next pixel so as I said that we have to go on changing the decision variable for every pixel so then how the change should be so how this can be calculated we can find out B next minus PK so if you subtract this then you can know how much our decision variable should change every time so let us find out P next - Bohemians that is next KP and the current B so let us subtract this we get the difference how much it should change every time so I will remove this and I will find out that one so how much your decision variable should change every time that is next P and the current B so subtract these two so I have subtracted these two formulas right so how I got this formula just instead of xk i wrote x nix and YK y next I wrote that solve a difference in Y and difference in X's as it is and these two formulas I am subtracting this is first one and this is the second one so now if I open the brackets and show you next step so here are the term after opening the bracket disss as it is this is as it is this is minus 2 Delta X and y X K and this has became plus minus into minus plus so this is the expansion of this one now in this if you observe this is Delta Y and here also we have Delta Y and this is Delta X this is Delta X so let us take that common so by taking them common I will write on once again so this is the final formula that is the difference in the decision variable how we should modify decision variable every time this is the formula right so I have derived it from here so if you want to copy you can copy this one all these steps are required if you are writing in academics exam then you have to write on these steps now I will take this again and rewrite from here so I will remove everything I need only this one so this is the formula in this what is X next and Y next already I told you see presently we are on this pixel when we say next X we definitely go to next that is increment X but when we say next y next y may increment Y or may not increment Y so we may have same Y K or Y may increment that is this should be plus 1 Y should increase or it may be same so that's what I said that's what we have to take a decision so for that decision is a decision we so what I should write down in this one if P next minus BK if this is less than 0 if it is less than 0 means we should remain on the same YK then what this formula become that is P next I will call it as P next assign let us write on this portion here PK plus what this should become we should take same by K so I will expand this one to Delta Y this will be XK plus 1 next is XK plus 1 and minus XK minus XK then minus 2 Delta X then what about this one YK as I said if it is less than 0 based on the decision variable it remains same only widely only YK minus YK YK minus YK now this is what we get so this gets cancelled and this term is gone so what is remaining so P next can be calculated every time by current PK plus 2 Delta Y and this xx gets canceled and this is fun so this is the formula so next decision variable you can know it by using this one if it is less than 0 and if it is greater than 0 P next minus PK is greater than or equal to 0 then what it should be P next should be PK now I will try this one 2 Delta Y and this one will be same only so it is 1 I will not write it and this is 2 Delta X this one will be YK plus 1 so when you subtract these 2 one will be remaining so we also get 2 Delta X so as it is so this is what the foreign lies so see here X next and my next one time I have placed Y next as Y J I got this answer this I got because I have kept Y next as YK and this I got because I have taken Y next as YK plus 1 I have not incremented why I have incremented vine depending on the decision variable this is the value of a decision variable so this decision variable as we are calling it as pk let us call it as PK plus 1 and this also as PK plus 1 that is next to pk so it is written like this mostly in the textbooks you find like this I was using the term next so that is easy to understand now we have two formulas this is one formula and this is another one two formulas this is if PK is PK is less than zero and this if PK is greater than or equal to zero we have these two formulas so that's all we have derived how the formulas that are used for taking a decision whether to increment Y or not to increment Y now in this we have to do one more thing we should know what should be the initial value of PK so for that I will define what is the initial value of PK so first I will t write that one then we will be able to write on the algorithm so let us find out what should be the initial value of PK this is the incremental value we have found out when P is less than 0 use this formula otherwise use this formula incremental value we find out but initial value we'll find out so I will remove this and work out on initial value so for T finding out the initial value of decision variable that is for the first pixel x1 y1 let us find out p1 that is initial value so that again we can follow this one for getting the next decision variable every time so forth finding the initial value I have taken the same formula that is the first PK that we got and I said that this is constant and I have removed that one but I will take that one also for finding the initial value so I will take the complete formula right now in this one let us make it for the first pixel so let us call this as P 1 that is the initial value and let us call this as X 1 instead of X K and this is y1 so almost Delta Y X 1 Delta X Y 1 Delta Y Delta X C's there so the constant is there so let us remove that understand so how to remove that see for the first pixel in the line equation if I write this this is what we get so C is nothing but I can take it like this C is equals to Y 1 minus sin decide M what is M Delta X Y by Delta X so this is Delta Y by Delta X and into X 1 so in place of C let us write on this one and then simplify this one so I will write on this C value here and write the next formula so here I have substituted C value from this one that is y 1 minus Delta Y by Delta X into X 1 I have substituted now let me open this one and write on this initial value once again if I open this one then this is 2 Delta X into y 1 minus 2 okay Delta X into Delta X gets cancelled so I'll guess just Delta Y X 1 minus Delta X that is the difference in X so this is the formula I got and in this formula if you observe 2 Delta Y x1 2 Delta Y x1 this is negative this is positive gets cancelled and minus 2 Delta X Y 1 plus 2 Delta X Y 1 these two gets cancelled so what is remaining now so only these two terms are remaining so let us write on p1 that is the initial value that is 2 Delta Y that's to Delta Y minus Delta X that's it so I will move this this may be confusing see the formula is still here only so this is the derivation of initial values so you have to derive initial value also the important thing in initial value is you have to take the complete formula that you got the first time and see you have to substitute for the first pixel from this equation you have to get it and substitute and simplify it so now we have initial value of decision variable and the formula for incremental value also using that I will write down the L square term we can write down the algorithm we will decide whether to take the same way next slide that is increment the Y and we will put all the pixels so let me write on bresenham's algorithm now I will remove this if you want you can take a copy of this one take a snapshot and go through it afterwards so here I write bresenham's algorithm we want X value so X value should start from X 1 and Y value should start from Y 1 see this is for slope less than 1 right if you want to check whether realeased slope is less than 1 or not you have to check it so I am NOT checking that just I am writing how to put the pixels using that decision weight then I will also find out difference in X the difference in X's x2 minus x1 and in the same line I will write down difference in Y that is y2 minus y1 so you need these local variables if you are writing it like a program then also I have to calculate the P that is decision variable that is 2d x minus dy that's what we got initial value so this what we have X Y as well as P now we have to go on putting the pixels so using a while loop or for loop anything you can take and you can put the pixel so how long X is less than equal to x2 because we'll be sampling X values then what to do every time first of all put the pixel put a pixel at X comma Y this what we have that is the first pixel now after putting the pixels X is incremented differently axis we are sampling so X will always increment now whether to increment Y or not that depends on the decision variable if a P is less than 0 if it is less than 0 then just we should calculate the new value of decision variable so simply calculate new value of decision variable that is P assigned B plus C this psi next psi in current P plus 2 Delta Y so this is 2 Delta Y else if it is greater than or equal to 0 then what we have to do find the next decision variable that is 2 Delta Y minus 2 that is 2 Delta Y minus 2 Delta X and also increment Y so Y should be incremented if it is greater than or equal to 0 so this is in the else part so this is if part and this is the else part so this is best Himmel go down that's so simple so just you have to remember this one P initial value and this inside this formula and this formula right and my plus plus should be done here so this is simple this is simple only if you have to write down the algorithm just we have to write all these three lines you should remember then you can write on now I will take an example and I will show you how we can get the pixels using this algorithm now I have an example let us get all the points along the lines so the lines first point is one kawaman and the second point is eight comma five I want to get all the points along the line using this person am algorithm which doesn't have any float value it works only on integers and this is for the line whose slope is less than one so if you check you will find the slope less than one now I will follow this algorithm so here I have written Britain in forces step X assign X 1 so I have a table here to get all the points so exercise X 1 that is 1 then Y assigned Y 1 this is y 1 this is X 1 Y 1 right this is x1 y1 and this is x2 y2 so y1 is 1 next is difference in X let us find out difference in X that is X 2 minus X 1 that is 7 then find out difference in Y that is dy is Phi minus 1 that is 4 then P T is how much 2 into dy minus DX so 2 into dy s 8 so 2 into 4 minus 7 this is a minus 7 that is equal to 1 so this is 1 P is 1 so I have the initial values now the first pixel is 1 comma 1 yes so let us trace this one while loop so this is why Lou so first thing that we are doing is put the pixel so yes will put a picture at 1 comma 1 then X plus plus X will become 2 definitely the next find out the P is less than 0 no piece not less the P is greater than Z so then P assign B plus 2 dy minus DX so that's what I have to find out so let us calculate you already know dy and DX so let us find out how much this is 2 into dy minus 2 into DX how much it is 2 into 4 minus 2 into 7 so this will be 8 minus 14 s minus 6 so this will be minus 6 so P assign P plus minus 6 so 1 plus minus 6 this becomes minus 5 and next step is y plus plus so Y becomes 2 so here I have updated the value of P by following this one by adding minus 6 and also I have incremented Y so this part we may be doing it more than one time so you can find out how much it is and you can keep on adding that one every time now next pixel is 2 comma 2 repeat again put pixel then X plus plus X becomes 3 then P is it less than 0 yes then how much it is P assign P plus 2 dy so what is 2 dy 2 dy is 2 into 4 that is 8 so add 8 to this one so add 8 so it becomes so much 3 so P became 3 now what about the value of y this will not increment it will not go into else part so Y remains 2 only so if you come back put pixel X value was incremented Y values are still 2 only then next again P is less than 0 no P is greater than 0 else part change P by adding this much how much it is minus 6 and minus 6 so this becomes minus 3 and next step is what y plus plus so Y becomes 3 and actually it did not change this one X plus plus X became for this I was supposed to do it here now repeat again it goes back here put pixel this pixel is taken the next plus plus X becomes 5 then P is less than 0 yes less than 0 at 2dy how much is to dy8 add 8 to this one so this becomes 5 then what about why why it's not change why remains 3 only so it has not gone into L spot then repeat put pixel in this one X plus plus 6 so now I will be repeating it this is 6 and this is greater than zero so this becomes so much P is not less than zero it is greater than or equal to zero so this becomes plus minus 6 is done say it is minus 1 and this becomes 4 so these 2 steps so minus 6 I have added the next step put pixels so this becomes 7 now this is less than 0 so Y will not increase and as it is less than 0 only it is added to this one so this becomes 7 now next put pixel this X becomes 8 and y as this is greater than 0 Y becomes 5 and this one so this should be added minus 6 so this is 1 next time put the pixel and get the next values so that is of no use one more turn it will take right I am NOT writing the values so it will put pixel 8 comma 5 then also calculate p-value so that's all these so these are the points along the line sometime in examination they ask us to generate the number of points or all the points by using bresenham's algorithm so you should remember these things if you remember these things how to get it so you should remember the algorithm now derivation is also there I have shown your derivation so that's all in this video you need to practice this one you have to do it once by yourself then you can remember it so if you just by watching if you try to do it you can't get it you can't figure out so you take pen and paper and go on following it now watch it again one more time and practice it and do it along with me so that will help you and you can remember it always it's not that difficult right only mathematical part is more so mathematics a simple thing for the engineering students so that's all industry
Info
Channel: Abdul Bari
Views: 222,113
Rating: 4.9077783 out of 5
Keywords: bresenhams, bresenhams line, bresenhams algorithm
Id: RGB-wlatStc
Channel Id: undefined
Length: 43min 39sec (2619 seconds)
Published: Thu Mar 14 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.