dt draw Line (3,0 Fe G29
‘he artnet tir gh yi
slope =
2, Ap
ay Be ;
leg se howe bine (2,2) br Died
re
- 3h 2b 028
m2 SE = op
MOVE Oo mes m
by Land copuli
of
Pf am >) Mew Jr! et
x
Son
Cael ms b — Oz
el ems
ew 4,7
DOWAIRan
The dig erent oa
ye (ODA) ean smerny
* *
yamyem ‘SI set ih
ine iepling one
“Solos kak nh
ft ake neg values satin fom or he is pi, ad increas Some
by ble al en po each
¥-Thal we sample unt y mere y =) apd cael eeh ured
1 aed 9 the amumpton tha ins ar 4 be
i soth ght endpant ig 2 ts proces
img emp sate ng then te’ we have
Be, 14,)
6795[Bon Ras wnare mt
ime anton BDAY st 892)
i
Ane
pe Aye ag
wera 5 S*Ie
DDA Example
Hl
eae)
rim,
ead fe form grate han 4
)
rondo icon
1. Draw a line from (1,5) to (9,7) using DDA
im =dyldx = (y2-y1)/(x2-x1) = 218 = 1/4)
xine=1
ic=m
x1
run_steps = x2-x1 =
# Python program for DDA ine generation
‘rom matplotb import eylot as alt
#DDA Funeton fr ne generation
ef DDAWO, 30, x4, 1):
# fd absolve ferences
dhe = absG0 - x1)
dy ~absiy0- 1)
4 fnd maximum diterence
steps = maxids, dy)
‘#caleute the herement nx ans y
ve = axsteps
vine = dyisteps ,
+ start with 1st point
x= float)
y= fal(y0)
‘#make alist for coordinates
soorinates = [,
eoorates =I
Bre 0,2) 48 (4,8) m: CDfe2 ee OF
me) [2H [remind shone ps £
Hl
34
Q2, draw line using DDA from (5,1) to (7,8)
De Jt.
fort in range(steps)
‘append the Xj esordinates in respective list
%_soorinates, appendix)
‘ecornates. appenat))
#inorement he values
yey ye
+ pole line with coordinates st
plot coornates, y_coorirates, mark
mmarhersae=t, earketaceccler=
pitshow()
4 Dever code
name
*# cootinates of fst point
W0,y0~20, 20
# coortnates of and point
Hi,yt =60, 50
+2 Function cal
DDN, yO, xt, yt)
Fone ra
input rer ae)
1 Singer ae)
yiitepemer tk)
batesy0, 91
The ode seine by fat[Computer Graphics: By Raj Kumar Sharma (Aryabhatta College)
# Python program for DDA line generation
from matplotiib import pyplot es pit
def DDA(x0, yO, x1, y1):
# find absolute differences
x = abs(x0- x1)
dy = abs(y0-y1)
# find maximum difference
steps = max(dx, dy)
# calculate the increment in x and y
xine = dx/steps
vine = dy/steps
# start with {st point
# make a list for coordinates
x_coorinates = [J
Y_coorinates = []
fori in range(steps):
# append the x.y coordinates in respective list
x coorinates. appendix)
y_coorinates.appendly)
# increment the values
x=x+xine
=y+yine
# plot the line with coordinates list
pit plot(x_coorinates, y_coorinates, marker="o",
markersize=1, markerfacecolor="green)
pit show()
# Driver code
it_rame_
# coordinates of 1st point
x0 = intfinput("Enter x0 value :"))
yO = int(input("Enter yO value :"))
+# coordinates of 2nd point
x1 = int(input("Enter x1 value :"))
yt = int(input{*Enter yt value -*))
# Funetion call
DDA(xO, yO, x1, y1)
# This code is contributed by 11 tarpittBresenham's
To detemine which fhe wo pa coset the ne pth, wo can ss up an eficint et ta is base on te aifornce betas the he il ssoaratoné 36
owe
BieweAagpes = 2086+) — 43h 1 4? is
¥ Abag.” Apher Min fe FAL daa?"
1 Nowa Ader Min 1g ="
Kat
i Aineet Aap = 2h + 1) — Ppp 42h
i nao BYP, Au
; . : L gite
aes? ABE Gio aBys 3 (omit 6H 5G
1 P= ACen bn)? 249 Mer) Ag Po ine
| . | Di vig aie Bpideont E
| £ 2 DAY H+ 2b y a
Me = Bayi ZaL yeeBy Ray Kumar Sharm (aryabhatia Colege)
Bresenhams Line Algorithm 2
=e
[Computer Graphics
Na
ran Oh —@
=m +) +b ye
rien ly
Sah ome ee,
Thesis mente ho ain seeing int pcan ofc anton ntact bin psn
Ahower ~ deoper = 2% +1) ~ 21m 42h 1 Ag 7 3
¥ Anan” Apter Min fz $F Le reer
1 Aaa Ader Min “y= = Pa Ae
Kt
~ dapper = 2364 +1) — 2 42 —1
m= Ay/Ax,
btn” 12 Be Ga) age Bs (omlPipg, O06 te By Dn)
249 Ch) Ay pab-|
ga y
> Crpretonnt~ e
Rim Aldous ate
(ae 3 urd, Do Be,
Wieser en ie ee
from exe Ppt -*) siting A= ~F x)
ary
+
Pest = Ph + 2Ay —2Ax(u 4s ~ yy)
hz (ry ~“2AK ch ~ — Pe » =e)
= ah 4 Bx
é[Excrser septic —__8y Raj Kumar Sharma (aryabhatia Coleg
Bresenhams
‘MAMPLE 4 BresenhamLine Drawing =
i Flea ey Te ee tied
_Toillustrate the algorithm, we digitize the line with endpoints (20, 10) and
20/12) Tis line has a slope of 0.8, witty 0 M0
| Ar=10, Ay=8
“ rigure i
Fhe pons along the Fw path between 2
edn, 10 and 3,1 ploted mth
Bresenham’ ne sloth, ‘[Computer Graphics: By Raj Kumar Sharma (Aryabhatta College)
# Python3 program for Bresenhams Line Generation
from matpiotiib import pyplot as pit
def plotPixel(x1, 1, x2, y2, dx, dy)
# pk is intial decision making parameter
# Note:x1&y1,x28y2, dx&dy values are interchanged
# and passed in plotPixel function so
pk=2"dy-dx
+# make a list for coordinates
x coorinates
yLcoorinates =f]
{ar iin range(0,dx+1):
x coorinates. append(x1)
¥-coorinates. appendiy1)
print(xt,” “y1)
xtextsd
pk+2*dy-2* de
yiayt+1
# plot the line with coordinates list
pltplot(x_coorinates, y_coorinates, marker="o", markersize=
markerfacecolor="green’)
pltshow/)
# Driver code
if_neme__=="_main_’
int(input("Enter x0 value :"))
1 = int(input("Enter yO value :"))
# coordinates of 2nd point
x2 = int(input("Enter x1 value :"))
dy = abs(y2- y1)
plotPixel(xt, y1, x2, y2, dx, dy)