CGMUNIT2 - Graphics Primitives
CGMUNIT2 - Graphics Primitives
CGMUNIT2 - Graphics Primitives
Graphics Primitives
10.2.1.Pixel
A pixel is a point of light. It is just one tiny dot on the raster displays.
Though it has no structure, it is definitely a building block and hence it
can be considered as the graphics primitive. The resolution of CRT is
related to the dot size, the diameter of a single dot. A resolution of 100
dots lines/inch implies a dot size of 0.01 inch. The ratio of the distance
between the centres of two adjacent horizontal pixels to that of the
vertical ones is called the pixel ratio. Pixel ratio should be considered in
line-generating algorithms.
10.2.2.Line
Line, especially straight lines, constitute the basic building block of Line
graphs, bar and pie charts, two and three-dimensional graphs of
mathematical functions, engineering drawings and architectural plans.
In computer graphics, straight line is so basic in creating images that we
call it a graphics primitive. Straight lines can be developed in two
different ways. A structural method determines which pixels should be
set before drawing the line; a conditional method tests certain
conditions to find which pixel should be set next.
10.2.3.Polygon
A polygon is a closed area of image bounded by straight or curved lines
and filled with one solid color. Since images are two dimensional, a
polygon is a closed planar figure.A polygon, is an important graphics
primitive. So often we want to handle polygon as a single entity, as
images of objects from the real world consist in large, part of polygons.
10.4.Frame buffer
The video output device which drives a video display from the memory
buffer containing a complete set of data is known as frame buffer. The
image is stored in terms of pixel by pixel. The memory can be discs,
Integrated circuits etc.,
10.5.Display control
This controls the view of the image so that the user can view the mage
fromdesired angle and desired magnification.
10.6.Display Processor
The display processor read the data from the frame buffer and convert it
into corresponding 1's and 0's according to there pixels and then put it
on to a monitor screen.The display processor do this work 30 times per
second to maintain a steady picture on the screen,and if we want to
change the picture on the screen then we have to change the contents
of frame buffer.
10.7.Line generation.
10.8.Graphics software
10.10. Polygons
10.11Filling of polygons
10.12.Text primitive
With the Text graphics primitive, we can insert text at any position in
two- or three-dimensional Mathematical graphics. The text will be given
in the graphic's base style.
In computer graphics any object that is larger than the computer screen
cannot be seen through the monitor i.e., window. So we have to remove
the unseen portions of the image or block out those portions. This
process is known as clipping and making the object to be seen through
the window by using algorithms is known as windowing.
10.14.View port
1. Point
2. Line
3. Sector
4. Arc
5. Ellipse
6. Rectangle
7. Polygon
8. Characters
9. Filled Regions
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.
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.
A straight line may be defined by two endpoints & an equation. In fig the
two endpoints are described by (x1,y1) and (x2,y2). The equation of the
line is used to determine the x, y coordinates of all the points that lie
between these two endpoints.
Using the equation of a straight line, y = mx + b where m = & b = the
y interrupt, we can find values of y by incrementing x from x =x 1, to x =
x2. By scan-converting these calculated x, y values, we represent the
line as a sequence of pixels.
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.
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
put b = 0 in equation (1)
y = 3x + 0
y = 3x
Step6: Calculate m =
Step8: Set (x, y) equal to starting point, i.e., lowest point and x endequal
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.
OUTPUT:
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
Advantage:
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:
Step9: x = x + xinc
y = y + yinc
Set pixels (Round (x), Round (y))
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?
x1=2
y1=3
x2= 6
y2=15
dx = 6 - 2 = 4
dy = 15 - 3 = 12
m=
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
The actual y coordinates of the line at x = xi+1is
y=mxi+1+b
di=△x (2 (xi+1)+2b-2yi-1)
=2△xyi-2△y-1△x.2b-2yi△x-△x
di=2△y.xi-2△x.yi+c
Where c= 2△y+△x (2b-1)
We can write the decision variable di+1 for the next slip on
di+1=2△y.xi+1-2△x.yi+1+c
di+1-di=2△y.(xi+1-xi)- 2△x(yi+1-yi)
Since x_(i+1)=xi+1,we have
di+1+di=2△y.(xi+1-xi)- 2△x(yi+1-yi)
Special Cases
If chosen pixel is at the top pixel T (i.e., di≥0)⟹ yi+1=yi+1
di+1=di+2△y-2△x
If chosen pixel is at the bottom pixel T (i.e., di<0)⟹ yi+1=yi
di+1=di+2△y
Finally, we calculate d1
d1=△x[2m(x1+1)+2b-2y1-1]
d1=△x[2(mx1+b-y1)+2m-1]
Since mx1+b-yi=0 and m = , we have
d1=2△y-△x
Advantage:
1. It involves only integer arithmetic, so it is simple.
2. It avoids the generation of duplicate points.
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.
Bresenham's Line Algorithm:
Step1: Start Algorithm
Step2: Declare variable x1,x2,y1,y2,d,i1,i2,dx,dy
Step3: Enter value of x1,y1,x2,y2
Where x1,y1are coordinates of starting point
And x2,y2 are coordinates of Ending point
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
Step6: Generate point at (x,y)coordinates.
Step7: Check if whole line is generated.
If x > = xend
Stop.
Step8: Calculate co-ordinates of the next pixel
If d < 0
Then d = d + i1
If d ≥ 0
Then d = d + i2
Increment y = y + 1
Step9: Increment x = x + 1
Step10: Draw a point of latest (x, y) coordinates
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
Differentiate between DDA Algorithm and Bresenham's Line Algorithm:
DDA Algorithm Bresenham's Line
Algorithm