Sei sulla pagina 1di 5

2.

Algorithms While (i ≤ L)

2.1 Line Drawing Algorithm {

2.1.1. Digital Differential Algorithm xnew = xnew+dx


(DDA):
ynew = ynew+dy

Plot (int(xnew,ynew))
Step 1:Input co-ordinates of end points
i = i+1
Point 1: (x1, y1)
}End while
Point 2: (x2, y2)
Step 7:Finish.
Step 2:Calculate Δx and Δy

Δx = x2-x1
2.1.2. Breseham’s Line Drawing
Δy = y2-y1 Algorithm (1stOctant)

Step 3:Calculate length ‘L’

If abs(x2-x1) ≥ abs(y2-y1) Step 1:Input co-ordinates of end points

L= abs(x2-x1) Point 1: (x1, y1)

Else Point 2: (x2, y2)

L= abs(y2-y1) Step 2:Calculate Δx and Δy

Step 4:Calculate incremental factor Δx = x2-x1

(x2−x1) Δy = y2-y1
dx = 𝐿
Step 3:Initialize points and error term
(y2−y1)
dy = 𝐿
x = x1
Step 5: Initializing xnewand ynew
y = y1
xnew= x1+ 0.5 Δ𝑦 1
e = Δ𝑥 − 2
ynew = y1+ 0.5

Plot (int(xnew,ynew))
Step 4: Plotting the points
Step 6: Plotting the points
For i=0 to Δx
Initial ‘i’ to 1
Plot (int(x,y)) Plot (int(x,y))

While (e ≥ 0) While (e ≥ 0)

{ y = y+1 {

e = e -1 y = y+1

}End while e = e - 2Δx

x = x+1 }End while


Δ𝑦 x = x+1
e= +e
Δ𝑥
e = e + 2Δy
Next ‘i’
Next ‘i’
End for loop
End for loop
Step 5:Finish.
Step 5:Finish.

2.1.3. Breseham’s Integer Algorithm


2.1.4. Breseham’s General Purpose
Algorithm
Step 1:Input co-ordinates of end points

Point 1: (x1, y1)


Step 1:Input co-ordinates of end points
Point 2: (x2, y2)
Point 1: (x1,y1)
Step 2:Calculate Δx and Δy
Point 2: (x2,y2)
Δx = x2-x1
Step 2:Calculate Δx and Δy
Δy = y2-y1
Δx = abs(x2-x1)
Step 3:Initialize points and error term
Δy = abs(y2-y1)
x = x1
Step 3:Initialize points
y = y1
x = x1
e = 2Δy - Δx
y = y1
Step 4: Plotting the points
Step 4:Determine sign
For i=0 to Δx
S1=Sign(x2-x1) If (interchange =1) then

S2=Sign(y2-y1) y=y+S2

Step 5:Perform interchange Else

If Δy>Δx then x =x+S1

Temp= Δx End if

Δx=Δy e =e+2 Δy

Δy=Temp Plot (x,y)

Interchange=1 Next ‘i’

Else End for loop

Interchange=0 Step 8:Finish.

Step 6:Initialize error

e=2Δy- Δx 2.2. Midpoint Circle Drawing Algorithm

Plot (x,y)

Step 7: Plotting the points Step 1:Input radius of the circle ‘r’

For i=0 to Δx Step 2:Initiate first pixel

While (e > 0) x=0, y=r

{ Step 3: Finding the M value

If (interchange = 1) 5
M=4 – r
then
Step 4: Plotting the function
x =x+S1
While (x ≤ y)
Else
{
y =y+S2
Plot (x,y)
End if
If M<0 then
e =e-2 Δx
M=M+2x+3
}End while
Else
M= M+2(x-y)+5

y = y-1 2.3.3. Reflection

End if Reflection about x-axis

x = x+1 1 0 0
(x* y*) = 0 −1 0
}End while 0 0 1

Step 5:Finish. Reflection about y-axis

−1 0 0
(x* y*) = 0 1 0
2.3. Transformations 0 0 1

2.3.1. Translation

x* = x + T1 2.3.4. Scaling

y* = y + T2 Sx 0 0
(x* y*) = 0 Sy 0
(x* y*) = (x y) + (T1 T2) 0 0 1

Translation matrix using Homogenous Sx and Sy are scaling factors in x and y


system direction.

1 0 0
(x* y*) = 0 1 0
T1 T2 1

2.3.2. Rotation

For anticlockwise direction

cos θ sin θ 0
(x* y*) = − sin θ cos θ 0
0 0 1
For clockwise direction

cos θ −sin θ 0
(x* y*) = sin θ cos θ 0
0 0 1
Where θ is angle of rotation

Potrebbero piacerti anche