CG DDA Practical For MU

You might also like

Download as pdf
Download as pdf
You are on page 1of 14
CG, Experiment No. 4. Aim!= Preqram fey DOA Line drowalary eleprithrn. | | | | | | | Page No, \ ts C0) Gnarde~ the Line for doom Coro) < we the sivnple ODM olyori trem — Ge £,70 a Wao Ze = J ten = (Ye V)FE Zz AK = Kak / Jengty = = 4/6 = 0: 66F a in . - : « : Y =O 1) | tongs Z EER ME) SIT ape : 1 C= O05 + aiagn 0-665 20-5 : Yr O45 * son gy sod } Plot ey (0.0) 08 Cont) eres = Sit diPferensiod con ater sare brow Stat of | ____ > ate = ef _atewaigts Sine to not s Ay = Y~% ax i ° ~ | “The obeve difhrentiod eaustion can be wed to oblain a Straight cline for aoy given of initial ater « dine fore ans [Given a Anition Axl along dine ure can compudes th Som pens Y interes! AY from eat Qos Ay= Ye-% (as) _ _. ®. Sa ay cBimilerly we can cblesn dhe Ax Jotened Asx cerres poo. ing slo“ Opecified ‘oy Ax = %-% (AY) © Ye Orce the interved are kneoin She vobre for next S a Joos on dhe edocight dine coin be obtain Ont tls i +Ag Hi + ®o-% Cay) Mo -Ys cc, + 05 ™ aign (Ax) x y n fa Y_+0:5™ sign (AY). Page No, Date :- __initicalice 4 while Cig ste | Advantage tc | DIn to dimples alaerithm and i+ doeinot cequir Special bis ox _implementat'so, D Lesy to understand: Dtnel ODA algeritien jaa faster method fer calleubebing #ned positicn sdhan the direct sere of he equation - Z N= mertb Dissluintagce!~ D Become of croupd aff exces eine Intnodbaced. Cours the colerlated fined. Yellen = Yt ay = Y_ 4+ Yer Ye Ax Ky — Oy. The 20 © $@ represent o crecunasion -relstion for weewresive seobus oa he aecuined ne coll os DOA fu simp A uccther Axe or Ay Whichever ' jmigen is chesee ay the cwpene Limit: je. if lAs) >IAY] hom Ax =! Date :- Pimplification a i gy se op tf Ko MD Yo“) - € hen steps Ox che Step= Ay - ie Ax ~Csa-x) / steps AY = (¥_ -¥) /stees Position to dri ft a cfeom She torte inne joath. Became of Hondiog eink _opeation the chert | is dime Consuming: | Conclusion — ma Th 2 ws Kave Studied Jroplementabon of POA Aine droudga a pe AE Page No. gincludesiostream.h> pinclude gincludecmath.h> sinclude rinclude void dda (int,int,int,int) void dashedline(int, int,int,int) void dottedline(int,int,int,int) void thickline(int,int,intint); void main() { clrser(); int gd=DETECT,gm; initgraph(&gd,&gm, C:\\tc\\bgi"); int x1,y1,x2,y2,dx,x,y,|,length, ch; char ¢; cout<<”Enter any 2 points of line “; cin>>x1>>y1>>x2>>y2; do { SouteeTinplartabon of different lines 1. Simple line \n2. Dotted line \n3. Dashed line \n4. Thick line :”; : Cout<<"enter ur choice”); Cin>>ch; Switch(ch); { Case 1: Cleardevice(); Dda(x1,y1,x2,y2); Break; Case 2: Cleardevice(); dottedline(x1,y1,x2,y2); Break; Case 3: Cleardevice(); dashedline(x1,y1,x2,y2); Break; Case 4: Cleardevice(); thickline(x1,y1,x2,y2)r Break; Default: Co Break uy want to continue”) } coute<"D0 VO" cinn>>chi Cleardevicel)s } oid dati xLint yLint x2,int ¥2) { int dx,dy.xy,leneth.t; dxeabs(x2-x1); while(i=dy) Length=dy; D=(x2d)/length; While(ic=length) M(1%3==0) Putpixel(x,y,10); Delay(100); t } Void dashedline(int x1,int y1,int x2,int y2) { Int dx,dy,xy, length; Dx=abs(x2-x1); Dy=abs{y2-y1); Putpixel(x,y,10); Xextdx; Yey+dy; I; Delay(100)’ t } Void thickline(int x1,int y1,int x2,int y2) { Int w,wy, 1.x; Cout<<”enter the thikness”; Cin>>w; Cleardevice(); Line(xt,y1,x2,y2); HA((y2-y1)/(x2-x1}<2) { Wy=(w-1)*sqrt(pow((x2-x1),2+pow((y2-¥1),2))/(2*fabs(x2-x1)); ronioscwvitt Tintaty 1x22 Lime(x1,y141,x2,y24i); } } Else u 2-y1))i oe w-1)*sqrt(pow((x2-x1),2}+pow((y2-y1),2))/(2*fabsl. For(i=O;i

You might also like