You are on page 1of 36

Computer Application in Design

Today
• Window, viewport
• Clipping transformation
• Antialiasing
• Line/circle drawing algorithm
*Selecting a box and zoom it to see
2D viewing
2D viewing
Clipping Algorithm

p9
Before Clipping After Clipping

p4 p10 p2
p2
p1
p1
p8 p6 p 8
p6 p 5
p3 p5
p 7
p7
Types of Clipping algorithms
• Cohen-Sutherland Line Clipping Algorithm
• Sutherland-Hodgman Polygon Clipping
• Liang-Barsky Line Clipping Algorithm
• Nicholl-Lee-Nicholl Line Clipping Algorithm
Antialiasing disabled

Antialiasing enabled
DDA line algorithm
(digital Differential analyser)
• Step 1 − Get the input of two end points (X0,Y0) and (X1,Y1).
• Step 2 − Calculate the difference between two end points.
dx=x1-x0;dy=y1-y0
• Step 3 − Based on the calculated difference in step-2, you need to identify
the number of steps to put pixel. If dx > dy, then you need more steps in x
coordinate; otherwise in y coordinate.
• Step 4 − Calculate the increment in x coordinate and y coordinate.
Xinc = dx/steps ; Yinc = dy/steps
• Step 5 − Put the pixel by successfully incrementing x and y coordinates and
rounding them accordingly and complete the drawing of the line.
DDA line
• Create a line between (1,2) and (5,5)
DDA line
• Create a line between (1,2) and (5,5)
• Points
• (2,3)
• (3,4)
• (4,4)
Bresenham’s Line
Bresenham’s Line
• Step 1 − Calculate the constants dx, dy, 2dy, and (2dy – 2dx) and get the first value
for the decision parameter as p0=(2*dy)−dx
• Step 2 − At each Xk along the line, starting at k = 0, perform the following test −
If pk< 0, the next point to plot is (xk+1,yk) and
pk+1=pk+(2dy*pk)+1=pk+2dy
Otherwise plot (xk+1,yk+1),
pk+1=pk+2dy−2dx

Repeat till last point. For m > 1, find out whether you need to increment x while
incrementing y each time.
After solving, the equation for decision parameter Pk will be very similar, just the x
and y in the equation gets interchanged.
Bresenham’s Line
• Create line between (0,1) and (6,4)
Bresenham’s Line
• Create line between (0,1) and (6,4)
• Points : (0,1)(1,1)(2,2)(3,2)
(4,3)(5,3)(6,4)
Bresenham’s Circle
Bresenham’s Circle
Cont.

You might also like