0% found this document useful (0 votes)
7 views9 pages

Computer Graphics Unit1

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

COMPUTER GRAPHICS

UNIT-I: GRAPHICS PRIMITIVES AND SCAN CONVERSION

Computer Graphics:
An ability of drawing pictures, lines, charts, etc by means of computers through programming is
defined as computer graphics. It converts data to and/or from visual arrangement using
computers. It uses a computer to create pictures. Algorithms, mathematics, data structures enable
a computer to make Pretty Pictures. Ivan Edward Sutherland is widely regarded as the "father of
computer graphics”
[2]. Computer Graphics has two main aspects namely technical and art. Computer Scientists
create libraries and tools etc for artists or non technical person, so that they can make use of it to
create pretty pictures. Artistic person uses these computer graphics tools to create attractive
pictures [1]. The technical definition of computer graphics includes composition of four
important steps:

 Imaging: It is the process of representing 2D images.



 Modeling: It is the process of creating and representing 3D objects. Mainly deals with the
shape of the object.

 Rendering: It is the process of constructing 2D images from 3D models. It focuses on
light and perspective of objects.

 Animation: It is the process of describing the change in objects in time. I represent
movement of the object [10].

Applications are listed as follows:


1) Graphical User Interface
2) Education and Training
3) CAD (Computer Aided Design)
4) Entertainment (animations, games etc.)
5) Presentation
6) Computer Generated Art
7) Scientific and Business Visualization
8) Image Processing
Important Aspects of Computer Graphics

1) Pixel: In computer graphics, pictures or graphics objects or each screen point is


represented as a collection of discrete picture elements which are called as pixels. It is
also referred to as a pel, as it is a smallest addressable screen element. It is the smallest
piece of screen, which we can control by setting the intensity and color. Each pixel on the
graphics display does not represent the mathematical point but the region which
theoretically can contain an infinite number of points. For instance, if we want to display
point P1 & P2 with coordinates (4.2, 3.8) and (4.8, 3.1) respectively, then points P1 & P2
are represented by only one pixel (4, 3) as shown in fig. below. In general point is
represented by Pixel (int (x), int (y)).

Fig. 9. Pixel display area of 6 × 5

2) Frame Buffer: A special area of memory is dedicated to graphics only, and picture
definition is stored in this memory area which is called frame buffer or refresh buffer.
This memory area holds the set of intensity values for all the screen points and the stored
intensity value are then retrieved from this frame buffer and painted on the screen one
row at a time to display picture.
3) Resolution: It refers to the maximum number of dots or points that can be displayed on
the screen without overlap on the Cathode Ray Tube (CRT). It is expressed as the number
of points per centimeter that can be plotted horizontally and vertically. Resolution
depends on the type of phosphor, the intensity to be displayed and the focusing and
deflection systems used in the CRT. The most commonly used four resolutions today are:
640 × 480, 1024 × 768, 800 × 600, 1280 × 1024.

4) Aspect Ratio: This number gives the ratio of vertical points to horizontal points
necessary to produce equal-length line in both directions on the screen. Sometimes it is
also referred to as the ratio of horizontal to vertical points. An aspect ratio of 5/6 means
that a vertical line plotted with 5 points has the same length as a horizontal line plotted
with 6 points. eg. aspect ratio of
12” × 16” display is 12/16 = 3/4.

5) Persistence: The operation of most video monitors is based on standard Cathode Ray
Tube (CRT). The screen of the video monitors is usually phosphor coated. Different
kinds of phosphors are available for use in a CRT. Besides color, a major difference
between phosphors is their persistence i.e. how long they continue to emit light after the
CRT beam is removed. Persistence is basically defined as the time it takes the emitted
light from the screen to decay to one-tenth of its original intensity. Lower persistence
phosphors required higher refresh rates to maintain a picture on the screen without
flicker. A phosphor with low persistence is useful for animation, a high –persistence
phosphor is used for displaying highly complex static pictures. Although, some
phosphors have persistence greater than 1 second, graphics monitors are usually
constructed with persistence in the range from 10 to 60 microseconds
Plotting Primitives of Computer Graphics

1) Scan Conversion: Display processor digitizes a picture definition given in an


application program into a set of pixel intensity values for storage in the frame
buffer. This digitization process is called scan conversion.

Lines and Line Segments: Point can be specified by giving pair of numbers (x, y), where
x represents horizontal distance and y represents vertical distance. Every line is described
by the equation such that if a point (x, y) satisfies the equation, then that point is on the
line. If the two points used to specify a line are (x1, y1) and (x2, y2) then the equation of
line will be,

Above equation justify that slope between any point on the line and point (x1, y1) is the
same as the slope between (x1, y1) and (x2, y2). Slope is usually denoted by m and is
defined as the change in height divided by the change in width for any two points on the
line. Slope m is defined in equation form as follows:

There is a difference between line and line segment. The lines can extend forever both
forward and backward direction but a line segment is a piece of line lying in between two
end points P1 and P2. If the end points are P1 = (x1, y1) and (x1, y1) = (x2, y2) and these
two points yield a equation y = mx +b then point P3 = (x3, y3) lies on the segment if y3 =
m x3 + b, x3 is in between x1 and x2 and y3 is in between y1 and y2. We can identify where
two lines are intersecting. Two lines are crossing or intersecting means they share
common point. That point satisfies the equation for both the lines. The intersection point
is given by below equation:

Fig.11. Line and Line Segments


3) Vectors and Vector Generation: Vector has a single direction and length. A vector is
denoted by [Dx, Dy], where Dx indicates how far to move in x-axis direction and Dy
indicates how far to move in y-axis direction. Vectors specify how far and in what
direction to move, but don’t specify from where to start. If vector V 1 = [Dx1, Dy1] and
vector V2 = [Dx2, Dy2] then resultant vector can be derived as:
V1 + V2 = [Dx1, Dy1] + [Dx2, Dy2]
= [Dx1 + Dx2, Dy1 + Dy2 ]

v Dy

Dx
We can multiply vector by a number and length of the vector can be given by
Pythagorean theorem.

If we multiply a vector by reciprocal of its length then the resultant vector is of length
equal to 1 and such a vector is called unit vector.

The process of “Turning ON” the pixels for a line segment is called a vector generation.
Whenever we need to draw a line, we need to turn ON the pixels on that line i.e. we need
to change the intensity of the pixels present on the line. Two well known algorithms used
for vector generation are Digital Differential Analyzers (DDA) and Bresenhans Line
Drawing Algorithm. Both the algorithms make use of increment method.
Line Drawing Algorithms

A basic element in graphics is that a line connects two points.. To draw a line, we need two
points between which we can draw a line. In line drawing algorithms, line is drawn between one
point of line as (x0, y0) and the second point of line as (x1, y1).

1) Digital Differential Analyzer (DDA):

DDA algorithm is an incremental scan conversion method. Here we perform calculations at each
step using the results from the preceding step. The characteristic of the DDA algorithm is to take
unit steps along one coordinate and compute the corresponding values along the other
coordinate. The unit steps are always along the coordinate of greatest change, e.g. if dx = 10 and
dy = 5, then we would take unit steps along x and compute the steps along y [14]. Algorithm for
DDA line drawing is described stepwise as follows:

Algorithm [15]
Step 1: Accept the two end points (x0 , y0 ) and (x1 , y1 ) as an input.

Step 2: Calculate the horizontal and vertical difference between two end points.

dx = |x1 - x0|
dy = |y1 - y0|

Step 3: Based on the calculated difference in step 2, identify the number of steps to put pixel. If
dx > dy, then we need more steps in x coordinate; otherwise in y coordinate.

if (dx > dy)


length = abs (dx);
else
length = abs (dy);

Step 4: Calculate the increment in x coordinate and y coordinate.

xincrement = dx / (float) length;


xincrement = dy / (float) length;
Advantages

1. It is the simplest algorithm and it does not require special skills for implementation.
2. It is a faster method for calculating pixel positions than the direct use of equation y = mx + b.
It eliminates the multiplication in the equation by making use of raster characteristics, so that
appropriate increments are applied in the x or y direction to find the pixel positions along the line
path [14].

Disadvantages

1. Floating point arithmetic in DDA algorithm is still time-consuming.


2. The algorithm is orientation dependent. Hence end point accuracy is poor [14].
3.

2) Bresenham’s Line Drawing Algorithm:


The Bresenham’s algorithm is another incremental scan conversion algorithm. The big advantage
of this algorithm is that, it uses only integer calculations. Moving across the x axis in unit
intervals and at each step choose between two different y coordinates. The basis program of
Bresenham’s line drawing algorithm is to select the optimum raster location to represent a
straight line. The increment in the other variable is determined by examining the distance
between the actual line location and the nearest pixel
[17]. This distance is called decision variable or the error. Consider a line with initial point (x1,
y1) and terminal point (x2, y2) in device space. If ∆x = x2 − x1 and ∆y = y2 − y1, we define the
driving axis (DA) to be the x-axis if |∆x| ≥ |∆y|, and the y-axis if |∆y| > |∆x|. The DA is used as
the “axis of control” for the algorithm and is the axis of maximum movement. Within the main
loop of the
algorithm, the coordinate corresponding to the DA is incremented by one unit. The coordinate
corresponding to the other axis (usually denoted the passive axis or PA) is only incremented as
needed [19].
Algorithm

Step 1: Read the line end points (x1, y1) and (x2, y2) such that they are not equal.

Step 2: dx = |x2 – x1| and dy =|y2 – y1|.

Step 3: Initialize starting points; x = x1 and y = y1

Step 4: Initialize the value of error or decision varaiable to compensate for non-zero
interrupts; e = 2 * dx - dy
Step 5:Initialize counter; i = 0

Step 6: Plot(x, y)

Step 7: while(e >= 0)


{
y = y +1;
e = e – 2 * dx
}
x = x + 1;
e = e + 2 * dy;
Step 8: increment counter by 1; i = i +1

Step 9: if (i <= dx) then go to Step 6.

Step 10: Stop

REFERENCES:

1) http://www.webopedia.com/TERM/G/Graphical_User_Interface_GUI.html
2) https://www.wikipedia.org/
3) http://www.computerhope.com/
4) http://study.com/academy/lesson/what-is-a-graphical-user-interface-gui-definition-
components-examples.html
5) http://whatis.techtarget.com/definition/CAD-computer-aided-design
6) http://www.webopedia.com/TERM/C/CAD.html

7) http://brasil.cel.agh.edu.pl/~12sustrojny/en/przykladowe-zastosowania-nowoczesnej-
grafiki-komputerowej/przemysl-rozrywkowy/

8) https://en.wikipedia.org/wiki/Visualization_(graphics)
9) http://www.slideshare.net/aainakatyal/applications-of-computer-graphics
10) http://www.slideshare.net/VishnuRam7/computer-graphics-12567217
11) https://www.tutorialspoint.com/computer_graphics/computer_graphics_basics.htm
12) https://www.cise.ufl.edu/~sitharam/COURSES/CG/kreveldintrolinesegment.pdf
13) http://ecomputernotes.com/computer-graphics/simple-line-drawing-method/write-
short-note-on-digital-differential-analyzer-dda
14) https://www.tutorialspoint.com/computer_graphics/pdf/line_generation_algorithm.pdf
15) https://sites.google.com/site/assignmentssolved/mca/semester3/mc0072/2
16) http://www.eazynotes.com/notes/computer-graphics/programs/program-to-draw-a-line-
using-dda-algorithm.pdf
17) http://mcasjcet.weebly.com/uploads/4/4/7/9/4479347/computer_graphics_first_module_seco
nd. pdf
18) http://graphics.idav.ucdavis.edu/education/GraphicsNotes/Bresenhams-Algorithm.pdf
19) http://www.dailyfreecode.com/code/bresenham-line-drawing-algorithm-694.aspx

You might also like