From dc706c62864441d6df73ee7ec0847daf18b16236 Mon Sep 17 00:00:00 2001 From: SuriyaKrishnan Date: Tue, 2 Mar 2021 15:10:38 +0530 Subject: [PATCH] Added DDA with 3 points --- DDA3POINTS.C | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 DDA3POINTS.C diff --git a/DDA3POINTS.C b/DDA3POINTS.C new file mode 100644 index 0000000..1b188b1 --- /dev/null +++ b/DDA3POINTS.C @@ -0,0 +1,60 @@ +#include +#include +#include +#include +void main(){ + + int gd = DETECT ,gm, i; + float x, y,dx,dy,steps,steps1,x3,y3,dx1,dy1; + int x0, x1, y0, y1,x2,y2; + initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); + x0 = 100 , y0 = 200, x1 = 400, y1 = 200,x2=600,y2=400; + dx = (float)(x1 - x0); + dy = (float)(y1 - y0); + dx1=(float)(x2-x1); + dy1=(float)(y2-y1); + if(dx>=dy) + { + steps = dx; + } + else + { + steps = dy; + } + dx = dx/steps; + dy = dy/steps; + x = x0; + y = y0; + i = 1; + while(i<= steps) + { + putpixel(x, y, WHITE); + x += dx; + y += dy; + i=i+1; + } +if(dx1>=dy1) + { + steps1 = dx1; + } + else + { + steps1 = dy1; + } + dx1 = dx1/steps1; + dy1 = dy1/steps1; + x3 = x1; + y3 = y1; + i = 1; + while(i<= steps1) + { + putpixel(x3, y3, BLUE); + x3 += dx1; + y3 += dy1; + i=i+1; + } + getch(); + closegraph(); +} + +