Header Ads

DDA line drawing algorithm (Qt creator)

Qt Creator is a cross-platformC++, JavaScript and QMLintegrated development environment which is part of the SDK for the QtGUIApplication development framework.It includes a visual debugger and an integrated GUI layout and forms designer. Qt Creator uses the C++
compiler from the GNU Compiler Collection on Linux and FreeBSD. On Windows it can use
MinGW or MSVC with the default install and can also use Microsoft Console Debugger
when compiled from source code.

Problem Statement :


Write C++ program to draw the following pattern using DDA line drawing algorithm



DDA algorithm:


Input to the algorithm:

(x1,y1) and (x2,y2):  the end co-ordinates of a line.
Output of the algorithm:

Bring on pixels closest to the line.
Data Variables

(x1,y1) & (x2,y2) :  are real numbers representing end co-ordinates of line segment.
length : stores the length of line segment.
dx, dy :stores increment in x and y direction.
Sign : a function returning 1,0, -1 if argument to the function is > 0; = 0; < 0;
Algorithm :

1. Start
2. if |x2-x1| >= |y2-y1| then length = |x2-x1| 
   else length = |y2-y1|
3. dx = (x2-x1) / length.
4. dy = (y2-y1) / length.
5. x = x1 + 0.5 * sign(dx) /*x1 assumed to be at the leftmost*/
6. y = y1 + 0.5 * sign(dy).
7. Let i = 1
8. if i> length then go to step no 14
9. Plot (trun(x), trunk(y))
10. x = x + dx;
11. y = y + dy;
12. Increment i
13. go to step no 8
14. Stop.



You can download full project from here

No comments:

Powered by Blogger.