UNIT 1 Notes
UNIT 1 Notes
Syllabus
Unit – I (12 hours)
Overview of Graphics System: Video Display Units, Raster-Scan and Random
Scan Systems, Graphics Input and Output Devices. Output Primitives: Line
drawing Algorithms: DDA and Bresenham’s Line Algorithm, Circle
drawing Algorithms: Midpoint Circle Algorithm and Bresenham’s Circle
drawing Algorithm. Two Dimensional Geometric Transformation: Basic
Transformation (Translation, Rotation, Scaling) Matrix Representation,
Composite Transformations, Reflection, Shear, Transformation between
coordinate systems.
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
Computer graphics is an art of drawing pictures on computer screens with the help of
programming. It involves computations, creations, and manipulation of data. In other words, we can say
that Computer graphics is a rendering tools for the generation and manipulation of images. Whereas Image
processing is defined as how to process to a captured image for object detection and identification.
Pixel : Pictorial unit of the image or graph.
Resolution : The number of pixel per unit length i.e. Horizontal as well as vertical direction.
Aspect ratio : The ratio of width to its height, measured in unit length or number of pixel.
Bitmap : One bit for one pixel called as Bitmap.
Pixmap : number of bits for one pixel called as Pixmap.
[I.1]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
RASTER SCAN:
In the raster scan system, the electron beam is
swept across the screen, one row at a time from top to
bottom, As the electron beam moves across each row, the
beam intensity is turns on and off to create a pattern of
illuminated spots.
Picture definition is stored in memory area called
Refresh Buffer or Frame Buffer. The memory area holds
the set of intensity values from the all the screen points. Stored intensity values are then retrieved from the
refresh buffer and pointed on the screen one row (scan line) at a time.
Each screen point is referred to as a pixel or pel. At the end of each scan line, the electron beam
returns to the left side of the screen to begin display the next scan line.
[I.2]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
[I.3]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
ALGORITHM:
Step 1: Input the coordinate of the two end points and for the line
respectively,
Step 2: [Calculate and ]
Step 6: [obtain the new pixel on the line and plot the same]
i
}
Step 7: FINISH
Advantage of DDA:
[I.4]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
Easy to Implement.
It is avoided floating point multiplication.
Disadvantage of DDA:
Poor accuracy at the terminal point.
Still floating point addition is there.
Problem 01:
Consider a line AB with A(5,5) and B(10,9). 10
9
Apply a simple DDA algorithm and calculate
8
the pixel on the line. 7
6
Solution:
5
Step 1: 4
Step 2: 3
2
1
Step 3: 1 2 3 4 5 6 7 8 9 10
Step 4:
5.5 5.5 5 5
1 6.5 6.3 6 6
2 7.5 7.1 7 7
Step 5: 3 8.5 7.9 8 7
4 9.5 8.7 9 8
5 10.5 9.5 10 9
Step 1: [As shown in table]
3. BRESENHAM’S LINE DRAWING ALGORITHM: (MID POINT LINE DRAWING)
As in DDA, floating point addition is used, to avoid it, mid-point line drawing algorithm are
used.
Derivation (Slope <1)
Let be a point so
[I.5]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
By Equation (4)
.
If d <0, select the E point,
Hence next mid-point to evaluate is M2 ) putting this in the
equation of the line
Hence
If d >0, select the SE point, S
Hence next mid-point will be putting this in equation of the line
Hence
Similarly for slope >1
For For
midPoint_line midPoint_line
{ {
int int
[I.6]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
d=2*dy-dx; d=2*dx-dy;
while while
{ {
Putpixel(X,Y,2); Putpixel(X,Y,3);
if if
{ } { }
else else
{ {
}} }}
Problem 02:
Draw a line between (5,5) and (13,9). 10
9
Solution: 8
7
6
5
4
Slope =
3
2
Initial
1
1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 5 5
1 (5,5) 6 6
2 (6,6) 7 6
3 (7,6) 0+2*(-4)=-8 8 7
4 (8,7) -8+2*4=0 9 7
5 (9,7) 0+2*(-4)=-8 10 8
6 (10,8) -8+2*4=0 11 8
7 (11,8) 0+2*(-4)=-8 12 9
8 (12,9) -8+2*4=0 13 9
9 (13,9) 0+2*(-4)=-8 14 10
SCAN CONVERSION OF CIRCLE
A circle is a symmetrical figure. Any circle
generating algorithm can take advantage of circle’s symmetry to
plot eight points for each value that the algorithm calculate. Eight
way symmetry is used by reflecting each calculated point around
each
Defining a circle by second order polynomial equation
[I.7]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
If center is at Origin:
To calculate y we require square root and square function which is time taking.
Trigonometric Function
Here and values are floating point and multiplication of floating point takes more time.
BRESENHAM’S METHOD FOR CIRCLE DRAWING
Method of bresenham’s uses scan conversion with only integer operation like addition,
substation and multiplication rather than trigonometric function. So the method is faster and
efficient for real time implementation. Bresenham’s consider 8-way symmetry of the circle and
generate the point of the circle between to , which increase in and in
direction respectively.
Let be a point on the circumference of the circle. As the direction of the circle
generate is from to , the next point on the circumference can be and
B( To select best of the two pixel. Find out the nearest to the true circle.
Let us assume that the distance of the point A and
B from the origin (0,0) be D(A) and D(B) respectively.
So D(A) =
D(B) =
Let the distance of the pixel from the true circle be
Since
If
If
The decision factor for the next step is
But
As we know is either or
[I.9]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
When
When
The decision factor for determining the next pixel becomes
X=X++;
} }
else else
{ {
} }while( ); }
} }}
Problem 03:
Draw a circle where center is at Origin having a radius of 8.
Solution:
Bresenham’s Algorithm:
i d X Y (X,Y)
0 0 8 (0,8)
1 1 8 (1,8)
2 2 8 (2,8)
3 3 7 (3,7)
4 4 7 (4,7)
5 5 6 (5,6)
Mid-Point’s Algorithm:
[I.10]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
2D GEOMETRIC TRANSFORMATION
Transformation means changing some graphics into something else by applying rules.
Transformation takes an important role in computer graphics to reposition the graphics on the screen and
change their size and orientation. When a transformation takes place on a 2D plane. It is called as 2D
transformation.
There are various types of transformation such as
Translation
Scaling Up and Down
Rotation
Shearing
Reflection etc.
TRANSLATION:
A translation moves an object to a different position on the
screen. We can translate a point in 2D by adding translation coordinate
( ) to the original coordinate to get the new
coordinate .
From the figure,
The pair ( ) is called the translation vector or shift vector. The above equation can also be represented
[OR]
ROTATION:
In rotation, we rotate the object at particular angle from it’s origin. In the figure,
is located at angle from the horizontal X coordinate with distance r from the origin.
Let us rotate it at the angle is at a new location .
By using trigonometric:
Similarity
[I.11]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
OR
SCALING
To change the size of an object, scaling transformation is used. In the scaling process, you either
expand (up) or compress (down) the dimension of the object. Scaling can be achieved by multiplying the
original coordinates of the object with the scaling factor to get the desired result.
Let us assume that the original coordinates:
The scaling factor )
The mathematically represented as
REFLECTION
Reflection is the mirror image of original object. In reflection, the size of the object doesn’t change.
A reflection can also be represented as rotation operation with .
[I.12]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
SHEAR / SKEWING
A transformation that slants the shape of an object is called the shear transformation. Shearing is a
deformation of an object in which parallel planes remain parallel but are shifted in a direction parallel to
them.
Vertical shearing y a factor of
Problem 04:
Rotate a triangle ABC by an angle about a point (-1,1) where the triangle has a coordinate A(5,0),
B(10,2) and C(7,4).
Solution:
The coordinate of triangle ABC are
Step 1: The matrix representation of ABC triangle is
Step 4: Rotation by
Step 5: Move the origin to P(-1,1) or translate the arbitrary point back to its own position.
[I.13]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
HOMOGENOUS COORDINATES:
In a composite transformation, it involves scaling, rotation, reflection, translation but when
we represented the translation (Basic operation for any transformation) in 2x2 matrix. It require
addition and substation operation. But all other translation require matrix multiplication. To make
uniform we use homogenous coordinate. Homogenous coordinate is based on projective geometry.
Where coordinate representation of a point in the homogenous representation is
Where
IN HOMOGENEOUS COORDINATES:
1. Translation Matrix
2. Rotation Matrix:
R=
3. Scaling Matric
R=
4. Reflection
Reflection about X-axis Reflection about Y-axis
5. Shear / Skewing
[I.14]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
X Shear Y Shear
Problem 05:
Rotate a triangle ABC by an angle about a point (-1,1) where the triangle has a coordinate A(5,0),
B(10,2) and C(7,4). [Same as problem 4]
Solution:
Let the transformation matric is T.
T= [Bring (-1, 1) to origin]. [Rotation matric ]. [Bring back (-1, 1) from
Origin]
Problem 05:
Consider a triangle ABC with coordinator A(0,0),B(1,1),(C(4,2) magnify the triangle ABC to its twice by
keeping the point C(4,2) fixed.
Solution:
Translate to bring the fixed point to origin.
Step 1: Scaling by 2.
[I.15]
COMPUTER GRAPHICS | UNIT: 01
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, GIET (AUTONOMOUS), GUNUPUR
COMPUTER GRAPHICS - BCSPC7010 - 3-0-1 4
[I.16]
COMPUTER GRAPHICS | UNIT: 01