0% found this document useful (0 votes)
6 views

3-Scan Conv Algorithms

Scan

Uploaded by

yasynsegawy55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

3-Scan Conv Algorithms

Scan

Uploaded by

yasynsegawy55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DDA algorithm

// Assume m<1 , x0 < x1

Step1: input two line end points (x0,y0) and (x1,y1)

Step2: calculate initial values

dx = x1-x0

dy = y1 – y0

m= dy/dx

y = y0

x = x0

WritePixel (x,Round (y))

step3: while (x<x1)

{ x = x+1

y = y+m

WritePixel (x,Round (y))

Step4: Repeat step3 dx steps.


Midpoint Algortim

// Assume m<1 , x0 < x1

Step1: input two line end points (x0,y0) and (x1,y1)

Step2: calculate initial values

dx = x1-x0

dy =y1 – y0

d= dy – dx/2

∆𝐸 = 𝑑𝑦

∆𝑁𝐸 = 𝑑𝑦 − 𝑑𝑥

y = y0

x = x0

WritePixel (x, y)

step3: while (x<x1)

{ x = x+1

if (d<0)

{d = d + ∆𝐸}

else { d = d + ∆𝑁𝐸

y = y+1

WritePixel (x, y)

Step4: Repeat step3 dx steps.


Bresenham algorithm

// Assume m<1 , x0 < x1

Step1: input two line end points (x0,y0) and (x1,y1)

Step2: calculate initial values

∆x = x1-x0

∆y =y1 – y0

P= 2∆y – ∆x

y = y0

x = x0

WritePixel (x, y)

step3: while (x<x1)

{ x= x+1

if (P<0)

{P = P + 2∆𝑦}

else { P = P + 2(∆𝑦 − ∆𝑥)

y = y+1

WritePixel (x, y)

Step4: Repeat step3 dx steps.


Cohen Sutherland algorithm

1) Assign a 4 bit code to each end point x0,y0 C0 , x1,y1 C1


2) If C0/C1 = 0000 completely accepted (inside window)
Elseif C0/C1 ≠ 0000 rejected
Else clip
If line crosses xwmin or xwmax
𝑦1−𝑦0
y = y1 + m(x – x1) ( here x = xwmin or xwmax) , m=
𝑥1−𝑥0

else line crosses ywmin or ywmax


x= x1 + (y – y1) /m ( here y = ywmin or ywmax)
verify 𝑥𝑤𝑚𝑖𝑛 ≤ 𝑥 ≤ 𝑥𝑤𝑚𝑎𝑥 , 𝑦𝑤𝑚𝑖𝑛 ≤ 𝑦 ≤ 𝑦𝑤𝑚𝑎𝑥

If not satisfied repeat clip

You might also like