Scan Conversion
Scan Conversion
Since picture positions are at integer values, line can not be drawn from one addressable
point to another addressable point. Here we need to make certain approximation as to
which as pixel is to be fitted up at a time. Thias is called Rasterization/ Antialiasing/
Jaggies. The process of rasterization in scan-line order is called scan conversion. In other
words “the process of representing graphics object as a collection of pixel is called scan
conversion.”
0 1 2 3 X
(2) Unequal intensity : The unequal intensity problem occurs because human
perception of light is dependent on both the density and the intensity of a light
source. Thus, on a raster display with perfect squareness, a diagonal line of pixels
will appear dimmer than a horizontal or vertical line. As can be seen in figure, the
pixels on the horizontal line are placed 1 unit apart, while the pixels on the
diagonal line are approximately 1.414 unit apart. This difference in density
produces the perceived difference in brightness. Software designers can respond
to this problem in one of three ways :
(a) If speed of scan conversion is of primary importance, the unequal intensity
problem can be ignored.
(b) The unequal intensity of the lines can be corrected by increasing the
number of pixels used to generate the diagonal line.
(c) The unequal intensity problem can be corrected by increasing the intensity
of pixels plotted on the diagonal.
Figure:
Y
√2
1 X
(3) Overstriking : Overstriking means same pixel is written to more than once. As a
result of overstriking, the speed of output is slightly degraded because time is
spent in scan converting the same point two or more times.
(4) Local or Global aliasing (the picket fence problem) : The picket fence problem
occurs when a user attempts to scan convert an object that will not fit exactly onto
the raster.
The computer graphics software designer must decide whether to use local
or global aliasing. With local aliasing, the distance between pickets in the picket
fence will be kept as close to their true relative distances as possible. However,
the overall length of the fence will be distorted.
When the global aliasing is used, the overall length of the picket fence will
be approximately correct but the spacing between pickets will be distorted.
The ever-increasing resolution of graphics system is slowly evolving
“backdoor” solution to the problem of aliasing. That is, pixel density is rapidly
approaching the resolution of the human eye at normal viewing distance, thus
making it impossible for a person to perceive aliasing.
Figure :
Antialiasing of lines :
Many displays allow only two pixel states, on or off. For these displays, line may
have Jagged or stair-step appearance when they step from one row or column to the next.
The lower the resolution, the more apparent the effect. This is one aspect of a
phenomenon called aliasing.
Displays allow setting pixels to gray levels between black and white provide a
means to reduce this effect. The technique is called antialiasing, and it uses the gray
levels to gradually turn off the pixels in one row as it gradually turns on the pixels in the
next.
For gentle slop lines, we in effect examined the line position for each column
index and decided which row was closest. The line segment would lie between two
pixels, and we picked one. Suppose instead of picking the closest, we turned them both
on. We should choose the intensity values according to a function of distance between the
pixel index and the linre segment so that the pixel closest to the line receives most of its
intensiyty. The sum of the intensity values for the two pixels should match the total
intensity value for the line. The function used can be a simple or a complex expression
based on intensity patterns, pixel shapes and how lines cover them. In general, we want
the pixel’s intensity to match the amount of the line which covers its area.
Figure:
Y
1-H 1-H
H H
1-H
H
LINE-DRAWING
Bresenham’s Line Drawing Algorithm
Assumptions:
(ii) Suppose, the pixel position (xi, yi) is already determined. The next pixel
position to be approximated is either (xi+1,yi) or (xi+1,yi+1).
(iii) Let d1 and d2 be the pixel position of y1 and y1+1 with a y value of actual
line. If d1<d2 the next pixel point is(xi+1,yi) otherwise it is (xi+1,yi+1).
Derivation:
We know that equation of line is y = mx+c.
Now,
yi=m(xi+1)+c
d1=y-y1
d1=m(xi+1)+c-yi ………………..(i)
d2=yi+1-y
d2=yi+1-m(xi+1)-c ………………(ii)
d1-d2=( m(xi+1)+c-yi)-( yi+1-m(xi+1)-c)
consider yi+1=yi+1
d1-d2=2m(xi+1)-2 xi +2c-1
Since m=∆y/∆x
d1-d2 =2∆y/∆x(xi+1)+2c-2yi-1
∆x(d1-d2)=2∆y(xi +1)+2∆xc-2∆x yi -∆x
∆x(d1-d2)=2∆yxi +2∆y+2∆xc-2∆xyi-∆x
consider L.H.S, our decision parameter(Pi) for the ith step ∆x and ∆y will remain
the same throughout.
Pi =2∆y xi -2∆x yi+b …..………..(iii)
Pi+1=2∆y(xi+1)-2∆x yi+1+b ………...…..(iv)
Pi+1 -Pi=2∆y-2∆x(yi+1- yi)
Now,
Pi =2∆yxi-2∆xyi+2∆y+2∆xc-∆x ……….(viii)
Since yi=mxi+c
y1=∆y/∆xx1+c
y1∆x=∆yx1+c∆x
Putting it in (viii)
P1 =2∆yx1-2(∆yx1+c∆x)+2∆y+2∆xc-∆x
P2=P1+2∆y (P1<0)
P2=P1+2∆y-2∆x (P1>=0)
Justification:
Eg. Plot a line between two points (1,1) and (8,5) by using BLDF
Soln
∆x=8-1=7
∆y=5-1=4
P1 = 2*4-7=1
P2 =1+2*4-2*7=-5
P3 =-5+2*4=3
P4 =-3+8-14=-3
P5 =-3+8=5
P6 =5+8-14=-1
P7=-1+8=7
(1,1) 1 1 1
(2,2) 2 2 -5
(3,2) 3 2 3
(4,3) 4 3 -3
(5,3) 5 3 5
(6,4) 6 4 -1
(7,4) 7 4 7
(8,5) 8 5
Y
1 2 3 4 5 6 7 8 9 X
Algorithm:
Step 1 Input the two line endpoints and store the left endpoint in (x1,y1).
Step 2 Load (x1,y1) in the frame buffer, ie, plot the first point.
Step 5 The calculation for each points P depends on the last P (previous).
If Pi <0 then Pi+1 =Pi +2∆y otherwise it is Pi +2∆y+2∆x.Repeat the
procedure in Step 4 untill x coordinate reaches x1.
Algorithm:-
Step 1: Input end-points;store left end point as (x1,y1) and right end point as (x2,y2).
Step 2: Compute dx = x2 - x1 and dy = y2 - y1.
Step 3: Now,compare absolute values of dx and dy.
Put l = max (abs(dx), abs(dy)).
Step 4: Calculate xincrement = dx/l and yincrement = dy/l.
Step 5: Put x = x1, y = y1.
Step 6: Set-pixel(x,y).
Step 7: for k=1 to l
x=x1+xincrement
y=y1+yincrement
Set_pixel(x,y)
End
Example:-
Draw a line between points (0,0) and(6,4).
dx = 6-0 = 6
dy = 4-0 = 4
l = max (abs(6),abs(4)) = 6
xincrement = 6/6 = 1
yincrement = 4/6 = 0.6
Plot X Y
(0,0) 0 0.0
(1,1) 1 0.6
(2,1) 2 1.2
(3,2) 3 1.8
(4,2) 4 2.4
(5,3) 5 3.0
(6,4) 6 3.6
0 1 2 3 4 5 6 7 8 X
(2) Symmetrical DDA :
The DDA generates lines from their differential equations. The equation of the
straight lines is :
The DDA works on the principle that we simultaneously increment x and y by small
steps proportional to the forst derivatives of x and y. In the case of the straight lines, the
first derimvative are constant and are proportional to ∆x and ∆y. Thus in the ideal case of
an infinite precision display we could generate a line by incrementing x and y by ε∆x and
ε∆y, where ε is some small quantitiy.
In the real world of limited precision display we must generate only addressable
points. This can be done by rounding to the nearest integer after each incremental step,
after rounding we display a dot at the resultant x and y.
An alternative to rounding is the use if arithmetic overflow; x and y are kept in
register that have two parts- integer and fractional. The incrementing values, which are
both less than unity, are repeatedly added to the fractional parts, and whenever the result
overflows, the corresponding integer part is incremented.
The integer parts of the x and y registers are used in plotting the line. This woulod
normally have the effect of truncating rather than rounding, so we initialize the DDA
with the value 0.5 in each of the fractional parts to achieve true rounding.
The appearance of line generated by the DDA depends on the value chosen for ε.
In the case of the symmetrical DDA, we choose ε = 2-n ,
In fact ε is the reciprocal of the DDA’s line-length estimate, in this case 2n.
+ +
ε∆x ε∆y
The symmetrical DDA generates accurate lines since displacement of a displayed dot
from the true line is never greater than one half ‘a screen unit. Logically, the symmetrical; DDA
is simple, the use of a negative power of 2 for ε m,eans that the incrementing value can be
determined by shifting the ∆x and ∆y registers rather rhan by a division. Each step in the line is
computed with just two additions.
Assumption
The symmetrical DDA uses a power of 2 as a line estimate, since it simplifies the logic.
Algorithm
Step 1: Input end points,store left point as (x1,y1) and right point as (x2,y2).
Step 6: Setpixel(x1`,y1`)
CIRCLE-DRAWING
Bresenham’s circle-drawing Algorithm
Assumption :
Eight-way symmetry is used by reflecting each calculated point around each 45o
axis (reflecting about Y-axis and X-axis). The best approximation of the true circle will
be described by those pixels in the raster that fall the least distance from the true circle. If
points are generated from 90o and 45o, each new point closest to the true circle can be
found by taking the either of two actions:
(1) Move in the x-direction 1 unit
(2) Move in the x-direction 1 unit and move inthe (-) ve Y-direction 1 unit
d1 distance is defined as
d1= yi2 – y2
and d2 = y2 – (yi-1)2
(xi,yi) next point -> (xi+1,yi) or (xi + 1, yi, - 1)
We know that equation of the circle is
x2 + y2 = r2
y2 = r2 – x2
y2 = r2 – (xi + 1)2 ( because x has to increment)
d1 = yi2 – y2 = yi2 – r2 + (xi + 1)2 -(1)
& d2 = y2 – (yi – 1) = r2-(xi+1)2-(yi-1)2 - (2)
Pi = d1 – d2 = 2(xi+1)2 – 2r2 + 2yi2 – 2 yi + 1 - (3)
Pi+1 = Pi + 4 xi + 6 -(5)
Plot x y P=3-2r
(0,3) 0 3 -3
(1,3) 1 3 7
(2,2) 2 2 17
0 1 2 3 4 X
Mid-point Circle Algorithm:
Assumption :
To apply the midpoint method, we define a circle function:
fcircle (x,y) = x2 + y2 - r2
Any point (x,y) on the boundary of the circle with radius r satisfies the
equation fcircle (x,y) = 0. If the point is in the interior of the circle, the circle function is
negative. And if the point is outside the circle, the circle function is positive. To
summarize, the relative position of any point (x,y) can be determined by checking the
sing of the circle function.
0 -9 (1,10) 2 20
1 -6 (2,10) 4 20
2 -1 (3,10) 6 20
3 6 (4,9) 8 18
4 -3 (5,9) 10 18
5 8 (6,8) 12 16
6 5 (7,7) 14 14
Y X=Y
10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 X