Interactive and Passive Graphics
Interactive and Passive Graphics
Non-interactive Graphics involves only one-way communication between the computer and
the user, User see the produced image, and he cannot make any change in the image.
Advantages:
1. Higher Quality
2. More precise results or products
3. Greater Productivity
4. Lower analysis and design cost
5. Significantly enhances our ability to understand data and to perceive trends.
Frame Buffer: A digital frame buffer is large, contiguous piece of computer memory used
to hold or map the image displayed on the screen.
o At a minimum, there is 1 memory bit for each pixel in the raster. This amount of
memory is called a bit plane.
o A 1024 x 1024 element requires 220 (210=1024;220=1024 x 1024)sq.raster or
1,048,576 memory bits in a single bit plane.
o The picture is built up in the frame buffer one bit at a time.
o ∵ A memory bit has only two states (binary 0 or 1), a single bit plane yields a black
and white (monochrome display).
o As frame buffer is a digital device write raster CRT is an analog device.
2. Resolution: Use to describe the number of pixels that are used on display image.
3. Aspect Ratio: It is the ratio of width to its height. Its measure is unit in length or
number of pixels.
Aspect Ratio =
The circuitry of the video display device of the computer is capable of converting binary
values (0, 1) into a pixel on and pixel off information. 0 is represented by pixel off. 1 is
represented using pixel on. Using this ability graphics computer represent picture having
discrete dots.
Any model of graphics can be reproduced with a dense matrix of dots or points. Most human
beings think graphics objects as points, lines, circles, ellipses. For generating graphical
object, many algorithms have been developed.
Advantage of developing algorithms for scan
conversion
1. Algorithms can generate graphics objects at a faster rate.
2. Using algorithms memory can be used efficiently.
3. Algorithms can develop a higher level of graphical objects.
The process of converting is also called rasterization. The algorithms implementation varies
from one computer system to another computer system. Some algorithms are implemented
using the software. Some are performed using hardware or firmware. Some are performed
using various combinations of hardware, firmware, and software.
Pixel or Pel:
The term pixel is a short form of the picture element. It is also called a point or dot. It is the
smallest picture unit accepted by display devices. A picture is constructed from hundreds of
such pixels. Pixels are generated using commands. Lines, circle, arcs, characters; curves are
drawn with closely spaced pixels. To display the digit or letter matrix of pixels is used.
The closer the dots or pixels are, the better will be the quality of picture. Closer the dots
are, crisper will be the picture. Picture will not appear jagged and unclear if pixels are
closely spaced. So the quality of the picture is directly proportional to the density of pixels
on the screen.
Pixels are also defined as the smallest addressable unit or element of the screen. Each pixel
can be assigned an address as shown in fig:
Different graphics objects can be generated by setting the different intensity of pixels and
different colors of pixels. Each pixel has some co-ordinate value. The coordinate is
represented using row and column.
P (5, 5) used to represent a pixel in the 5th row and the 5th column. Each pixel has some
intensity value which is represented in memory of computer called a frame buffer. Frame
Buffer is also called a refresh buffer. This memory is a storage area for storing pixels values
using which pictures are displayed. It is also called as digital memory. Inside the buffer,
image is stored as a pattern of binary digits either 0 or 1. So there is an array of 0 or 1
used to represent the picture. In black and white monitors, black pixels are represented
using 1's and white pixels are represented using 0's. In case of systems having one bit per
pixel frame buffer is called a bitmap. In systems with multiple bits per pixel it is called a
pixmap.
2. Lines should terminate accurately: Unless lines are plotted accurately, they may
terminate at the wrong place.
3. Lines should have constant density: Line density is proportional to the no. of dots
displayed divided by the length of the line.
4. Line density should be independent of line length and angle: This can be done by
computing an approximating line-length estimate and to use a line-generation algorithm
that keeps line density constant to within the accuracy of this estimate.
Example: A line with starting point as (0, 0) and ending point (6, 18) is given. Calculate
value of intermediate points and slope of line.
Solution: P1 (0,0) P7 (6,18)
x1=0
y1=0
x2=6
y2=18
put value of x from initial point in equation (1), i.e., (0, 0) x =0, y=0
0=3x0+b
0 = b ⟹ b=0
Step4: Calculate dx = x2- x1
Step5: Calculate dy = y2-y1
Step6: Calculate m =
Step7: Calculate b = y1-m* x1
Step8: Set (x, y) equal to starting point, i.e., lowest point and xendequal to largest value of
x.
If dx < 0
then x = x2
y = y2
xend= x1
If dx > 0
then x = x1
y = y1
xend= x2
Step9: Check whether the complete line has been drawn if x=xend, stop
Step13: Go to Step9.
DDA Algorithm
DDA stands for Digital Differential Analyzer. It is an incremental method of scan conversion
of line. In this method calculation is performed at each step but by using results of previous
steps.
m=
yi+1-yi=∆y.......................equation 3
yi+1-xi=∆x......................equation 4
yi+1=yi+∆y
∆y=m∆x
yi+1=yi+m∆x
∆x=∆y/m
xi+1=xi+∆x
xi+1=xi+∆y/m
yi+1=y1+m, x=x+1
Until x = x2</x
x= x1,y=y1 set ∆y=1
xi+1= , y=y+1
Until y → y2</y
Advantage:
1. It is a faster method than method of using direct use of line equation.
2. This method does not use multiplication theorem.
3. It allows us to detect the change in the value of x and y ,so plotting of same point
twice is not possible.
4. This method gives overflow indication when a point is repositioned.
5. It is an easy method because each step involves just two additions.
Disadvantage:
1. It involves floating point additions rounding off is done. Accumulations of round off
error cause accumulation of error.
2. Rounding off operations and floating point operations consumes a lot of time.
3. It is more suitable for generating line using the software. But it is less suited for
hardware implementation.
DDA Algorithm:
Step1: Start Algorithm
Step4: Calculate dx = x2-x1
Step5: Calculate dy = y2-y1
Step7: xinc=dx/step
yinc=dy/step
assign x = x1
assign y = y1
Step9: x = x + xinc
y = y + yinc
Set pixels (Round (x), Round (y))
Step11: End Algorithm
Example: If a line is drawn from (2, 3) to (6, 15) with use of DDA. How many points will
needed to generate such line?
Solution: P1 (2,3) P11 (6,15)
x1=2
y1=3
x 2= 6
y2=15
dx = 6 - 2 = 4
dy = 15 - 3 = 12
m =
The DDA works on the principle that we simultaneously increment x and y by small steps
proportional to the first derivatives of x and y. In this case of a straight line, the first
derivatives are constant and are proportional to ∆x and ∆y . Therefore, we could generate a
line by incrementing x and y by ϵ ∆x and ϵ ∆y, where ϵ is some small quantity. There are
two ways to generate points
1. By rounding to the nearest integer after each incremental step, after rounding we display
dots at the resultant x and y.
2. An alternative to rounding the use of arithmetic overflow: x and y are kept in registers
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 results overflows,
the corresponding integer part is incremented. The integer parts of the x and y registers are
used in plotting the line. In the case of the symmetrical DDA, we choose ε=2-n,where 2n-
1
≤max (|∆x|,|∆y|)<2π
In this method, next pixel selected is that one who has the least distance from true line.
Assume a pixel P1'(x1',y1'),then select subsequent pixels as we work our may to the night,
one pixel position at a time in the horizontal direction toward P2'(x2',y2').
The line is best approximated by those pixels that fall the least distance from the path
between P1',P2'.
To chooses the next one between the bottom pixel S and top pixel T.
If S is chosen
We have xi+1=xi+1 and yi+1=yi
If T is chosen
We have xi+1=xi+1 and yi+1=yi+1
This difference is
s-t = (y-yi)-[(yi+1)-y]
= 2y - 2yi -1
Special Cases
Advantage:
1. It involves only integer arithmetic, so it is simple.
3. It can be implemented using hardware because it does not use multiplication and
division.
4. It is faster as compared to DDA (Digital Differential Analyzer) because it does not involve
floating point calculations like DDA Algorithm.
Disadvantage:
1. This algorithm is meant for basic line drawing only Initializing is not a part of
Bresenham's line algorithm. So to draw smooth lines, you should want to look into a
different algorithm.
Step4: Calculate dx = x2-x1
Calculate dy = y2-y1
Calculate i1=2*dy
Calculate i2=2*(dy-dx)
Calculate d=i1-dx
Step5: Consider (x, y) as starting point and xendas maximum possible value of x.
If dx < 0
Then x = x2
y = y2
xend=x1
If dx > 0
Then x = x1
y = y1
xend=x2
Step9: Increment x = x + 1
Step11: Go to step 7
Step12: End of Algorithm
Example: Starting and Ending position of the line are (1, 1) and (8, 5). Find intermediate
points.
Solution: x1=1
y1=1
x2=8
y2=5
dx= x2-x1=8-1=7
dy=y2-y1=5-1=4
I1=2* ∆y=2*4=8
I2=2*(∆y-∆x)=2*(4-7)=-6
d = I1-∆x=8-7=1
x y d=d+I1 or I2
1 1 d+I2=1+(-6)=-5
2 2 d+I1=-5+8=3
3 2 d+I2=3+(-6)=-3
4 3 d+I1=-3+8=5
5 3 d+I2=5+(-6)=-1
6 4 d+I1=-1+8=7
7 4 d+I2=7+(-6)=1
8 5
Defining a Circle:
Circle is an eight-way symmetric figure. The shape of circle is the same in all quadrants. In
each quadrant, there are two octants. If the calculation of the point of one octant is done,
then the other seven points can be calculated easily by using the concept of eight-way
symmetry.
For drawing, circle considers it at the origin. If a point is P1(x, y), then the other seven
points will be
So we will calculate only 45°arc. From which the whole circle can be determined easily.
If we want to display circle on screen then the putpixel function is used for eight points as
shown below:
Example: Let we determine a point (2, 7) of the circle then other points will be (2, -7), (-2,
-7), (-2, 7), (7, 2), (-7, 2), (-7, -2), (7, -2)
These seven points are calculated by using the property of reflection. The reflection is
accomplished in the following way:
There are two standards methods of mathematically defining a circle centered at the origin.
y2=r2-x2
Where x = the x coordinate
y = the y coordinate
r = the circle radius
With the method, each x coordinate in the sector, from 90° to 45°, is found by stepping x
from 0 to & each y coordinate is found by evaluating for each step of x.
Algorithm:
Step1: Set the initial variables
r = circle radius
(h, k) = coordinates of circle center
x=o
I = step size
xend=
Step3: Compute y =
Step4: Plot the eight points found by symmetry concerning the center (h, k) at the current
(x, y) coordinates.
Step5: Increment x = x + i
By this method, θ is stepped from 0 to & each value of x & y is calculated.
Algorithm:
Step1: Set the initial variables:
r = circle radius
(h, k) = coordinates of the circle center
i = step size
θ_end=
θ=0
Step3: Compute
x = r * cos θ y=r*sin?θ
Step4: Plot the eight points, found by symmetry i.e., the center (h, k), at the current (x, y)
coordinates.
Plot (x + h, y +k) Plot (-x + h, -y + k)
Plot (y + h, x + k) Plot (-y + h, -x + k)
Plot (-y + h, x + k) Plot (y + h, -x + k)
Plot (-x + h, y + k) Plot (x + h, -y + k)
Step5: Increment θ=θ+i
The best approximation of the true circle will be described by those pixels in the raster that
falls the least distance from the true circle. We want to generate the points from
90° to 45°. Assume that the last scan-converted pixel is P1 as shown in fig. Each new point
closest to the true circle can be found by taking either of two actions.
Let D (Si) is the distance from the origin to the true circle squared minus the distance to
point P3 squared. D (Ti) is the distance from the origin to the true circle squared minus the
distance to point P2 squared. Therefore, the following expressions arise.
D (Si)=(xi-1+1)2+ yi-12 -r2
D (Ti)=(xi-1+1)2+(yi-1 -1)2-r2
Since D (Si) will always be +ve & D (Ti) will always be -ve, a decision variable d may be
defined as follows:
Therefore,
di=(xi-1+1)2+ yi-12 -r2+(xi-1+1)2+(yi-1 -1)2-r2
If it is assumed that the circle is centered at the origin, then at the first step x = 0 & y = r.
Therefore,
di=(0+1)2+r2 -r2+(0+1)2+(r-1)2-r2
=1+1+r2-2r+1-r2
= 3 - 2r
Step2: Declare p, q, x, y, r, d variables
p, q are coordinates of the center of the circle
r is the radius of the circle
Step3: Enter the value of r
Step4: Calculate d = 3 - 2r
Step5: Initialize x=0
&nbsy= r
Step7: Plot eight points by using concepts of eight-way symmetry. The center is at (p, q).
Current active pixel is (x, y).
putpixel (x+p, y+q)
putpixel (y+p, x+q)
putpixel (-y+p, x+q)
putpixel (-x+p, y+q)
putpixel (-x+p, -y+q)
putpixel (-y+p, -x+q)
putpixel (y+p, -x+q)
putpixel (x+p, -y-q)
Step9: Go to step 6
Step10: Stop Algorithm
Solution: Let r = 10 (Given)
Step5: Plot (4, 9)
d = -1 + 4x + 6
= -1 + 4 (4) + 6
= 21
Step6: Plot (5, 8)
d = d + 4 (x-y) + 10 (∵ d > 0)
= 21 + 4 (5-8) + 10
= 21-12 + 10 = 19
So P1 (0,0)⟹(50,50)
P2 (1,10)⟹(51,60)
P3 (2,10)⟹(52,60)
P4 (3,9)⟹(53,59)
P5 (4,9)⟹(54,59)
P6 (5,8)⟹(55,58)
MidPoint Circle Algorithm
It is based on the following function for testing the spatial relationship between the arbitrary
point (x, y) and a circle of radius r centered at the origin:
Now, consider the coordinates of the point halfway between pixel T and pixel S
If Pi is+ve ⟹midpoint is outside the circle (or on the circle)and we choose pixel S.
We have yi+1=yi
We have yi+1=yi-1
We can put ≅1
∴r is an integer
So, P1=1-r
Algorithm:
Step1: Put x =0, y =r in equation 2
We have p=1-r
Step3: End