Transcript for:
DDA Line Algorithm Implementation Guide

we are going to uh discuss about the DDA line using the QT creator so first of all what we have to do we have to just create a project with the name of the DDA line or you can rename by yourself whatever you would like to have so I have just created a project with the DDA line so so this is the DDA in this we have the header file dda.cpp file main.cpp and da line dot UI so first of all what we have to do we have to just click on the UI form so you will get this particular environment so what you have to do for the DDA line uh line drawing algorithm you have to take the input from the user as for the line segment that means the starting point and the ending point of the line segment X1 y1 and X2 Y2 so we have created here the four labels that means the X1 y1 X2 Y2 and with respect to the X1 we have we required the text edit box so what we have to use we have to use the text edit box so we are going to use the plain text edit box like this you can able to drag and drop here you will get a text edit box in the similar way I have already drawn the four text edit box for the respective X1 y1 and X2 Y2 and I have considered here a push button push button you can directly find out here on the left hand side here so we have to take the push button drag and drop you will get the push button here how to rename this push button you have to just click on this or you can rename here the DDA so in this way you can rename uh for the push button and for the click event we have to perform the action that you have to do the right click on the DDA button go to the slot you have to select the go to slot after the selecting the code is locked you will open a pop-up window the through the pop-up window you have to select the clicked button by applying the clicked event you will be able to perform that DDA has been already performed the click event and whose declaration and definition will be redirected towards our code so this is the push button to clicked event which we have performed on the UI form so no need to uh Define or declare uh indirect way you have you don't have to write here uh manually it will be redirected directly okay so I don't require this push button because I have already have this so I have to just delete all the uh data which they have created because I have already created it so I am just deleting this so you have to just delete all those which will be reflected and can be referenced for each and every file okay so I have already created a DDA line button by clicking on this button only we can able to draw a line segment uses using the DDA line algorithm so after clicking on this go to the slot and click will be redirected towards our main CPP file that is the DDA line cpv file where we are going to code it okay so here you can able to identify we avoid DDA line on which a push button click event has been performed and the same this reference will be there in the header file as well that is the void on push click button that is okay so what we have to do we have to perform a function for the DDA line so I have created a function as well void DDA in which I have given X1 y1 X2 Y2 as a float okay so what we have to do we have to first of all define the definition for the push button click event what we have to do we have to take the input from the UI form from where we have to take the input from here here and here so we have to take the X1 value X Y 1 x 2 and Y2 so what we have to do we have to receive the value from there so if I am entering a value in the text edit box it should be in the form of a string then we have to convert it into the integer form so what we have done here we have converted plain text to the integer form and we have taken this value from the text edit box and which is already created on the UI form so in this way in this syntax we have to write this so in the similarly a similar way y1 X2 and Y2 value will be taken so we have to focus on this we have to write the text edit box name from where you can able to identify if I am going to write here for example okay for example you can able to see here on the right hand side if I am going to click on the X1 this is the text edit if I am going to click on the second block that is the text edit underscore 2 if I am going to click on the third button that is text edit underscore 3 okay in this way you can able to identify the name of the block so here we have written here the same thing okay now I have called a DDA function on which I have passed the value of X1 y1 X2 Y2 which we have taken from the user this particular syntax is used to draw the line with the color that means at what position so this is a pixel which I have plotted here just for the trial image dot set pixel 50 comma 50 with the white color so you can able to find out the pixel is already plotted there if I am going to recommend it the pixel will not be seen here just for the trial purpose I have done UI the label underscore 5 is used setpix map qpix map from the image because we have created a queue map that means what we have done this is our complete uh Visual Studio screen this text label we have to consider at the initial basis because I have already discussed in the previous uh video this particular text label is used as a output screen on which we can able to find out the console screen so we have taken here so on this what we have to do we have defined that it is a 500 cross 500 in which we have defined a q label five so you can able identify the label name this label is label underscore 5. if it is label underscore 2 or something label 1 is q1 Label 2 is y1 Label 3 is X2 label 4 is Y2 and this label for using for the output screen is label underscore five so you have to name here with the name with the same that means in the UI form we have to provide the output screen on the label underscore 5 on which we are going to set or plot the pixels okay this is the complete for the plotting and what we have to do we have just called the DDA line function so we have to define the DDA line function algorithm for plotting so what we have done here we have given here what we have to do don't have uh declared the function here so you have to just click uh sorry you have to just click here on right click you have to choose the refactor and you have to select the definition okay just a second called void sorry void DDA end comma end comma and comma end okay and after this this so what we have to do we have to choose here and it will ask you for the definition so you have to just choose the add definition in DDA line dot CPP so it will directly redirect to the ddl line.cpp space okay so after clicking here we will get this so we have to write the complete algorithm under the DDA function so I have already created okay so I'm just deleting here or I'm just going to comment here just for the trial or the practice I have shown this okay so here I have already created in the same way flow text one float y1 float X2 and Float y two so what we have to do here we have to write the algorithm so as we have studied the algorithm so we have to write the same int X and Y float Del X Del y length and X increment y increment okay so here Del X is used for Del X and Del Y is used for the calculation of the slope as well as for the further calculations so Del X is x 2 minus X1 and delva is Y2 minus y1 if the absolute of Del X is greater than absolute of Del y then the length will be considered the greater value will be considered as a length so here we have performed the if condition if the D X is greater the length will be equivalent to that if the Y is greater then the length will be equivalent to Del y okay so now we have to find out the X incremental which will be calculated by the Del x divided by length or Y increment will be calculated by Del by upon length so we will get the some final value of x increment and Y increment okay so we have to perform here the loop because this increment continuously will be going on till what till the length will not be ah get okay so I equals to 0 x equals to x 1 y equals to Y one so first of all we have to plot the X1 and Y 1 starting point of the line segment so it we have already assigned the same value in X and Y so we have uh used here the while loop for the execution of the program I is less than less than of length that means length is if here it is 8 then the loop will be is going to be from 0 to 7. okay then I have plotted that image dot set pixel X Y that is the starting point of the pixel x y and with the color that means here I have given a white color if I would like to change here that means I would like to use some red and green color combination will be get here okay so red intensity I'm going to reduce it it is 150 okay and next value will be calculated with x equals to X Plus of X increment y equals to Y plus of Y increment and I plus plus the loop will be continuously increasing until an unless will not get the length of the uh calculated what we have calculated this is the complete program of the DDA line drawing algorithm then how we are going to run it we have to just select the DDA right click on it and build it so while building we would uh we are going to see here on the right side corner bottom side this program this project is uh in the process of completion that is it is building so after completing the successful build of the project we can able to run it okay just a moment it will take a Time attention I hope you have understood about the DDA line segment in the similar way you can able to implement the bresenham line algorithm as well so this project is completely uh successfully built so we are going to run it so how we are going to run it we can run by two by right clicking and run or we can directly use here on the left hand side that is the Run option so you can use any of them so I have just run the project after successfully run the program I have to just mention here the coordinates that is it is starting from 100 and it is 200 to 200 suppose okay and after clicking on this button the line should be drawn okay this line is of some sort of red and green color combination it is parrot green color okay this line has been drawn if I would like to change any color suppose I would like to hear 300 100 200 or it is p so this line has been drawn okay you can change here and you can draw uh is draw the another line as well because it is already drawn so I am using 300 and it is 250 okay this line has been drawn in this way you can able to draw the DDA line segment you have to just provide the X1 y1 X2 Y2 and by clicking on the DDA button you can able to reflect the line on the output screen I hope you have understood thank you okay