CGR - Chapter 1 To 5
CGR - Chapter 1 To 5
CGR - Chapter 1 To 5
Bhyandar East
CHAPTER 1
CHAPTER 1
1.1
Aspect ratio:
It is the ratio of the number of vertical points to the number of horizontal points
computer graphics, the relative horizontal and vertical sizes. For example, if a
graphic has an aspect ratio of 2:1, it means that the width is twice as large as the
height. or Aspect ratio is the ratio between width of an image and the height of
an image.
Example: The term is also used to describe the dimensions of a display resolution.
1. Text mode
2. Graphics mode
Text mode is a personal computer display setting that divides the display
screen into 25 rows and 80 columns in order to display text without images.
In text mode, each box can contain one character. Text mode contrasts with
graphics device such that the basic unit is the pixel. Lines and characters on the
screen are drawn pixel by pixel. The resolution and complexity of the image
depends on how many pixels there are in total, and how many bits are assigned
to each pixel. The more bits per pixel, the more different colors or shades of gray.
with different resolutions and color selections. A common mode for a desktop PC
would be 1024 by 768 pixels with 256 different colors – chosen from a much
larger number – available for each pixel. See also text mode, computer graphics.
COMPUTER GRAPHICS 22318
1.2
Display Devices
• In this electron beam moves all over the screen one row at a time.
• As electron beam moves across each row, beam intensity is turned ON and OFF
Refresh Buffer or frame buffer. This refresh buffer holds set of intensity values
for all screen points .These stored intensity values are retried from buffer and
• When beam is moved from left to right, it is ON and when moved from right to
left (from end of first row to the start of next row.)it is OFF and is termed as
horizontal retrace. When beam reaches bottom of screen it is made OFF and it
• Raster scan display maintains the steady Image on the screen by repeating
non- interlace , electron beam scans through each line one by one.
• In interlace technique, beam firstly scans through even scan lines and then odd
scan lines thus scanning screen twice, ie . beam scans through alternate line first
copy device.
When operated as a random-scan display unit, a CRT has the electron beam
Random scan monitors draw a picture one line at a time and for this reason are
Here the electron gun of a CRT illuminate’s points and / or straight lines in any
display, we simply drive the beam reflection circuitry, which will cause beam to
displayed.
memory called “refresh display file” or also called as display list or display
To display a given picture, the system cycles through the set of commands in
the display file, drawing each component line by line in turn. After all line
drawing commands have been processed, the system cycles back to the first line
drawing command in the list. And repeats the procedure of scan, display and
retrace.
Random scan system is designed for line drawing applications; hence cannot
Vector displays produces smooth line drawings but raster produces jagged lines
Random scan suitable for applications like engineering and scientific drawings
COMPUTER GRAPHICS 22318
Graphics patterns are displayed by directing the electron beam along the
A scene is then drawn one line at a time by positioning the beam to fill in the
Flat-Panel Devices are the devices that have less volume, weight, and power
the Flat-Panel Display, use of CRT decreased. As Flat Panel Devices are light in
weights that’s why they can be hang on walls and wear them on our wrist as a
watch. Flat Panel Display (FPD) allow users to view data, graphics, text and
images.
COMPUTER GRAPHICS 22318
Emissive Display:
The Emissive Display or Emitters are the devices that convert electrical energy
Non-Emissive Display:
Non-Emissive Display or Non-Emitters are the devices that use optical effects to
which produces a clearer picture than the LCD. LED have wider viewing angle
than the LCD. It have better black level and contrast in comparison to LCD
LCD display. LED delivers better color accuracy in comparison to the LCD.
Advantage:
Disadvantage:
It is more costly.
An LCD is a passive device, which means that it does not deliver any light to
lighten the picture, but can’t provide the clearer picture as LED delivers. It
delivers good color accuracy, but we can notice the difference if we compare
LED and LCD color accuracy. In LCD, the wide angle decreases with 30
COMPUTER GRAPHICS 22318
degrees from the center in the image then the contrast ratio.
Advantage:
Disadvantage:
1.4
programs, animations, projects, and games. You can draw circles, lines,
rectangles, bars and many other geometrical figures. You can change their colors
using the available functions and fill them. Following is a list of functions of
Syntax: line(x1,y1,x2,y2 );
COMPUTER GRAPHICS 22318
Where, (x1,y1) are co-ordinates of startingpoint of line and (x2,y2) are co-
Syntax:Circle(x,y,r);
1.5
Virtual Reality means experiencing things through our computers that don't
really exist.
OR
and
Advantages:
environment.
education,
3.Desktop publishing(DTP)
5.Digital Art.
COMPUTER GRAPHICS 22318
CHAPTER 2
CHAPTER 2
2.1
DDA LINE DRAWING ALGORITHM
This algorithm generates a line from differential equations of line and hence
DDA method is referred by this name because this method is very similar to
the numerical differential equations. The DDA is a mechanical device that solves
Algorithm:
length = dx
else
length = dy
end if
Step 7: i = 1
x = x + dx
y = y + dy
i=i+1
Step 8: End
COMPUTER GRAPHICS 22318
It is the simplest algorithm and it does not require special skills for
implementation.
It is a faster method for calculating pixel positions than the direct use of
applied in the x or v direction to find the pixel positions along the line path
algorithm.
DDA.
Bresenhams algorithm can draw circles and curves with much more
COMPUTER GRAPHICS 22318
The key feature of circle that it is highly symmetric. So, for whole 360 degree of
circle we will divide it in 8-parts each octant of 45 degree. In order to that we will
use Bresenham’s Circle Algorithm for calculation of the locations of the pixels
in the first octant of 45 degrees. It assumes that the circle is centered on the origin.
So for every pixel (x, y) it calculates, we draw a pixel in each of the 8 octants of
Algorithm:
Step 4: do
Plot (x,y)
If(d<0) then
d = d + 4x + 6
Else
d=d + 4(x-y) + 10
y=y-1
}
COMPUTER GRAPHICS 22318
X=x-1
While(x<y)
Step 5: stop
2.4
TYPES OF POLYGAON
Convex Polygon:
It is a polygon in which if you take any two positions of polygon then all the
points on the line segment joining these two points fall within the polygon itself.
Concave Polygon:
polygon then all the points on the line segment joining these two points does not
object, we often need to identify whether particular point is inside the object or
outside it.
There are two methods by which we can identify whether particular point is inside
an object or outside namely, Odd-Even Rule, and Non-zero winding number rule.
1. Odd-Even Rule: In this technique, we count the edge crossing along the
line from any point (x, y) to infinity. If the number of interactions is odd
even then point (x, y) is an exterior point. Here is the example to give you
2. Non-zero Winding Number Rule: This method is also used with the simple
understood with the help of a pin and a rubber band. Fix up the pin on one
of the edge of the polygon and tie-up the rubber band in it and then stretch
the rubber band along the edges of the polygon. When all the edges of the
polygon are covered by the rubber band, check out the pin which has been
fixed up at the point to be test. If we find at least one wind at the point
consider it within the polygon, else we can say that the point is not inside
the polygon.
polygon. Draw a scan line from the point to be test towards the left most
of X direction. Given the value 1 to all the edges which are going to upward
direction and all other – 1 as direction values. Check the edge direction
COMPUTER GRAPHICS 22318
values from which the scan line is passing and sum up them. If the total
sum up the direction values from which the scan line is passing then the
point.
Flood fill
Sometimes it is required to fill in an area that is not defined within a single colour
boundary. In such cases we can fill areas by replacing a specified interior colour
instead of searching for a boundary colour . This approach is called a flood fill
algorithm. Like boundary fill algorithm, here we start with some seed and
examine the neighbouring pixels. However, here pixels are checked for a
specified interior colour instead of boundary colour and they are replaced by new
colour.
positions until all interior point have been filled. The following procedure
Procedure: flood_fill(x,y,old_colour,new_colour)
If(gepixel (x,y)=old_colour)
Putpixel(x,y,new_colour);
flood_fill(x+1,y,old_colour,new_colour);
flood_fill(x-1,y,old_colour,new_colour);
flood_fill(x,y+1,old_colour,new_colour);
flood_fill(x,y-1,old_colour,new_colour);
flood_fill(x+1,y+1,old_colour,new_colour);
flood_fill(x-1,y-1,old_colour,new_colour);
flood_fill(x+1,y-1,old_colour,new_colour);
flood_fill(x-1,y+1,old_colour,new_colour);
}
COMPUTER GRAPHICS 22318
BOUNDRY FILL
Limitations:
There is a problem with this technique. Consider the case following, where we
entire region. Here, the image is filled only partially. In such cases, 4-connected
pixels technique
cannot be used.
COMPUTER GRAPHICS 22318
For each scan line crossing a polygon, the area-fill algorithm locates the
These intersection points are then sorted from left to right, and the
Scan line algorithm works by intersecting scan line with polygon edges and
fills the polygon between pairs of intersections. The following steps depict how
Step 1 : Find out the Ymin and Ymax from the given polygon.
Step 2 : ScanLine intersects with each edge of the polygon from Ymin to Ymax.
As per the Fig. 2.21 shown, they are named as p0, p1, p2, p3. Step 3 : Sort the
intersection point in the increasing order of X coordinate i.e. (p0, p1), (p1, p2),
Step 4 : Fill all those pair of coordinates that are inside polygons and ignore
2.5
Frame Buffer
The frame buffer is the video memory (RAM) that is used to hold or map the
OR
i) Stroke method:
The small series of line segments are drawn like a strokes of a pen to form a
We can build our own strike method. By calling a line drawing algorithm. Here,
it is necessary to decide which line segments are needed for each character and
then drawing these segments using line drawing algorithm. This method supports
scaling of the character. It does this by changing the length of line segments used
characters. As shown in Fig. there are 24 line segments. Out of 24 line segments,
The patterns for particular characters are stored in the form of 24 bits
code.
The bit is set to one to highlight the line segments otherwise it is set to zero.
iii)BITMAP METHOD
method use array of bits for generating a character. These dots are the
In bit matrix method when the dots is stored in the form of array the value 1
in array represent the characters i.e. where the dots appear we represent that
position with numerical value 1 and the value where dots are not present is
represented by 0 in array.
It is also called dot matrix because in this method characters are represented
A 5x7 array is commonly used to represent characters. However 7x9 and 9x13
arrays are also used. Higher resolution devices such as inkjet printer or laser
****************************************************************
COMPUTER GRAPHICS 22318
CHAPTER 3
Overview Of Transformation
COMPUTER GRAPHICS 22318
3.1
1.Translation.
2.Scaling.
3.Rotation.
To translate a two dimensional point one need to add translation distance tx and
x’=x+tx
y’=y+ty
where,
x’ = x tx
y’ = y + ty
i.e P’=P+T
2.Scaling:
Scaling changes size of object along x or y or both axes. New transformed co-
Equations :
X = Sx . X
Y = Sy . Y
Where,
COMPUTER GRAPHICS 22318
• In matrix from :
x' = Sx 0 x
y' = 0 Sy y
P’=S.P
3)Rotation:
y'=x.sin Ɵ + y. cos Ɵ
COMPUTER GRAPHICS 22318
Matrix form:
i.e P'=R.P
COMPUTER GRAPHICS 22318
3.2
way
COMPUTER GRAPHICS 22318
3.3
COMPOSITE TRANSFORMATION
following
coordinate
origin.
3. Translate: Translate object so that arbitrary point P1 is moved back to the its
original position.
Note: Here to do one operation we are doing the sequence of three operations.
So
1) Translate P1 to origin.
2) Rotate
COMPUTER GRAPHICS 22318
Here (x1,y1) are coordinates of point P1 and hence are translation factors tx and
hence
it is translation factor.
COMPUTER GRAPHICS 22318
2D Scaling
Scaling means to change the size of object. This change can either be positive
or negative.
Let us assume that the original co-ordinates are (X, Y), the scaling factors are
(SX, SY), and the produced co-ordinates are (X', Y'). This can be mathematically
The scaling factor SX, SY scales the object in X and Y direction respectively.
It specifies three co-ordinates with their own scaling factors. If scale factors,
Therefore, point after scaling with respect to origin can be calculated as,
P=P . S
3.5TYPES OF PROJECTION
Perspective projection:
project plane is finite and the size of the object varies inversely with
• The distance and angles are not preserved and parallel lines do not remain
There are 3 types of perspective projections which are shown in the figure:
1. One-point:
2. Two-point:
3.Three-point:
Parallel Projection
and it is categorized as
o Top projection
o Front projection
o Side projection
COMPUTER GRAPHICS 22318
Oblique projection – the projection direction is not a normal one to the plane;
o Cavalier projection
o Cabinet projection
****************************************************************
COMPUTER GRAPHICS 22318
CHAPTER 4
4.1
1) The picture is stored in the computer memory using any convenient Cartesian
and lines that form the picture into the appropriate physical device co-ordinate
transformation.
transformation.
1. Construct the scene in world cordinates using the output primitives and
attributes.
5.Define a view port in normalized co-ordinates and map the viewing co-
6.Clip all the parts of the picture which lie outside the viewport.
COMPUTER GRAPHICS 22318
4.2
LINE CLIPPING
2. Read two corners (left-top and right-bottom) of the window,say (Wx1,Wy1 and
Wx2,Wy2).
3. Assign the region codes for two endpoints P1 and P2 using following steps:
a) If region codes for both endpoints P1 and P2 are zero then the line is
completely
b) If region codes for endpoints are not zero and the logical ANDing of
them is also
nonzero then the line is completely invisible, so reject the line and go to
step 9
COMPUTER GRAPHICS 22318
c) If region codes for two endpoints do not satisfy the conditions in 4a) and
a) If region codes for both the end pointe are non-zero, find intersection
points P1'
and P2' with boundary edges of clipping window with respect to point P1
b) If region code for any one end point is non zero then find intersection
point P1' or
P2' with the boundary edge of the clipping window with respect to it.
7.Reject the line segment if any one end point of it appears outsides the clipping
window.
9. Stop.
COMPUTER GRAPHICS 22318
Cyrus Beck Line Clipping algorithm: Cyrus Beck Line Clipping algorithm is used
algorithm.
• The term parametric means that we require finding the value of the parameter t
in the parametric representation of the line segment for the point at that the
• Consider line segment P1P2. The parametric equation of line segment P1P2 is,
P(t) = P1 + t(P2 – P1) … (1) Where, t value defines a point on the line going
through P1 and P2. 0 <= t <= 1 defines line segment between P1 and P2.
• Then we can distinguish in which region a point lie by looking at the value of
then the vector P(t) – f ] is pointed parallel to the plane containing f and
Dot products for three points inside, outside and on the boundary of the clipping
region
• As shown in Fig. if the point f lies in the boundary plane or edge for which n is
the inner normal, then that point t on the line P(t) which satisfies, n.[P(t) – f ] = 0
• The relation should be applied for each boundary plane or edge of the window
to get the intersection points. Thus in general form equation (5) can be written as,
• Here the vector P2 – P1 defines the direction of the line. The direction of the
line is important to correctly identify the visibility of the line. The vector P1 - fi
is proportional to the distance from the end point of the line to the boundary point.
• The equation (9) is used to obtain the value of t for the intersection of the line
with each edge of the clipping window. We must select the proper value for t
2. We know that, the line can intersect the convex window in at most two points
, i.e. at two values of t. With equation (9) , there can be several values of t in the
range of 0<= t <= 1 . We have to choose the largest lower limit and the smallest
upper limit.
3. If (ni . Di) > 0 then equation (9) gives lower limit value for t and if (ni. Di) < 0
tL = – (W.n)/(D.n)
else
tU = – (W.n)/(D.n)
COMPUTER GRAPHICS 22318
end if
Step 10: If maximum lower limit and minimum upper limit do not satisfy
2. Read two corners (left top and right-bottom) of the window, (x wmin ,y wmax
,x wmax ,y wmin )
p 1 = -∆x q 1 =x 1 -x wmin
p 2 = ∆x q 2 =x wmax -x 1
q 1 = -∆y q 3 =y 1 - ywmin
q 2 = ∆y q 4 = y wmax -y 1
Line is completely outside the boundary hence discard the line segment and goto
stop
Else
Check whether the line is horizontal or vertical and accordingly check the line
COMPUTER GRAPHICS 22318
endpoint with corresponding boundaries. If line endpoints lie within the bounded
area then use them to draw line otherwise use boundary coordinates to draw line.
Goto
stop.
t 1 =0 and t 2 =1
2.
9.If (t 1 <t 2 )
xx 1 =x 1 + t 1 ∆x
xx 2 =x 1 + t 2 ∆x
yy 1 =y 1 +t 1 ∆y
yy 2 =y 1 +t 2 ∆y
10.Stop.
MIDPOINT SUBDIVISION
Step 1: Scan two end points for the line P1(x1, y1) and P2(x2, y2).
Step 2: Scan corners for the window as ( x1, y1) and ( x2, y2).
Step 3:Assign the region codes for endpoints P1 and P2 by initializing code with
0000.
If region codes for both end points are zero then the line is visible, draw it
If region codes for end points are not zero and the logical Anding operation
of them is also not zero then the line is invisible, reject it and jump to step
6.
If region codes for end points does not satisfies the condition in 4 (i) and 4
COMPUTER GRAPHICS 22318
Step5: Find midpoint of line and divide it into two equal line segments and repeat
steps 3 through 5 for both subdivided line segments until you get completely
Step 6: Exit.
4.3
POLYGAON CLIPPING
Sutherland-Hodgeman
convex.
clip rectangle boundary in turn beginning with the original set of polygon
vertices, first clip the polygon against the left rectangle boundary to produce a
The new set of vertices could then be successively passed to a right boundary
At each step a new set of polygon vertices us generated and passed to the
algorithm.
The output of algorithm is a list of polygon vertices all of which are on the
visible side of clipping plane. Such each edge of the polygon is individually
This results in four possible relationships between the edge and clipping plane.
and second vertex are added to output vertices set as shown in Fig. 6.13.
If both vertices of edge are inside window boundary, then add only second
Going through above four cases we can realize that there are two key
Assume that we're clipping a polygon’s edge with vertices at (x1, y1) and (x2,
y2) against a clip window with vertices at (xmin, ymin) and (xmax, ymax).
1. The location (IX, IY) of the intersection of the edge with the left side of the
window is:
(i) IX = xmin
(ii) IY = slope*(xmin – x1) + y1, where the slope = (y2 – y1)/(x2 – x1).
2. The location of the intersection of the edge with the right side of the
window is:
(i) IX = xmax
(ii) IY = slope*(xmax – x1) + y1, where the slope = (y2 – y1)/(x2 – x1)
3. The intersection of the polygon's edge with the top side of the window is:
(ii) IY = ymax
4. Finally, the intersection of the edge with the bottom side of the window is:
(ii) IY = ymin
Step 4: Compare vertices of each of polygon, individually with the clipping plane.
Step 5: Save the resulting intersections and vertices in the new list of vertices
clipping boundary.
Step 6: Repeat the steps 4 and 5 for remaining edges of clipping window. Each
clipping window.
Step 7: Stop.
COMPUTER GRAPHICS 22318
4.4
TEXT CLIPPING
particular application. There are three methods for text clipping which are listed
below −
3) Text clipping
In all or none string clipping method, either we keep the entire string or we reject
entire string based on the clipping window. As shown in the abovefigure, Hello2
COMPUTER GRAPHICS 22318
is entirely inside the clipping window so we keep it and Hello1 being only
This clipping method is based on characters rather than entire string. In this
method if the string is entirely inside the clipping window, then we keep it. If it
If the character is on the boundary of the clipping window, then we discard that
This clipping method is based on characters rather than the entire string. In this
method if the string is entirely inside the clipping window, then we keep it. If it
is partially outside the window, then you reject only the portion of string being
***************************************************************
COMPUTER GRAPHICS 22318
CHAPTER 5
Introduction to Curves
COMPUTER GRAPHICS 22318
5.1
CURVE GENERATION
Curve. The differential equations for simple curve such as circle is fairly easy to
solve. The equation for an arc in the angle parameters can be given as:
where (x0,y0) is the center of curvature, and R is the radius of arc. As shown in
From equation (1) and (2) we can solve for R cos Ɵ and R sin Ɵ as
follows:
x= R cos Ɵ + x0
Therefore,
R cos Ɵ=x-x0and…………..(5)
R sin Ɵ= y- y0......................(6)
dy= (x-x0)dƟ…………….(8)
respectively, to
be added in the current point on the arc to get the next point on the arc. Therefore
we can write,
The equation (9) and (10) forms the basis for arc generation algorithm. From
equation (9) and (10) we can see that the next point on the arc is the function of
dƟ. To have a smooth curve, the neighbouring points on the arc should be close
to each other. To achieve this, the value of dƟ should be small enough not to
leave gaps in the arc. Usually, the value of dƟ can be determined from the
following equation:
INTERPOLATION
points, which indicates the general shape of the curve These, control points are
two ways. When polynomial sections are fitted so that the curve passes through
each control point, the resulting curve is said to interpolate the set of control
points. On the other hand, when the polynomials are fitted to the general control-
point path without necessarily passing through any control point, the resulting
curve is said to approximate the set of control points interpolation curves are
5.2
TYPES OF CURVES
Koch Curve
Koch Curve: - In Koch curve, begin at a line segment. Divide it into third and
replace the center by the two adjacent sides of an equilateral triangle as shown
below.
COMPUTER GRAPHICS 22318
This will give the curve which starts and ends at same place as the
original segment but is built of 4 equal length segments, with each 1/3rd of the
original length. So the new curve has 4/3 the length of original segments. Repeat
same process for each of the 4 segment which will give curve more wiggles and
increases the length by a factor of 4/3, the length of the curve will be infinite but
Hibert's curve:
The Hilbert curve is a space filling curve that visits every point in a square
Hilberts curve.
the square into 4 quadrants and draw the curve which connects the
the centre of the finest level before stepping to the next level of
detail.
COMPUTER GRAPHICS 22318
the curve has been so twisted and folded that it exactly fills up a
square.
4 curves of the half scale to build the full sized object so dimension
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
if(j==1)y-=h;
else if(j==2)x+=h;
else if(j==3)y+=h;
else if(j==4)x-=h;
lineto(x,y);
voidhilbert(intr,intd,intl,intu,inti,inth,int x, int y)
if(i>0)
i--;
hilbert(d,r,u,l,i,h,x,y);
COMPUTER GRAPHICS 22318
move(r,h,x,y);
hilbert(r,d,l,u,i,h,x,y);
move(d,h,x,y);
hilbert(r,d,l,u,i,h,x,y);
move(l,h,x,y);
hilbert(u,l,d,r,i,h,x,y);
void main()
int n,x1,y1;
int x0=50,y0=150,x,y,h=10,r=2,d=3,l=4,u=1;
intgd,gm;
initgraph(“&gd,&gm,”c:\\tc\\bgi”);
x=x0;
y=y0;
moveto(x,y);
hilbert(r,d,l,u,n,h,x,y);
getch();
closegraph();
COMPUTER GRAPHICS 22318
Bezier Curves
The simplest Bézier curve is the straight line from the point P0 to P1. A quadratic
• They generally follow the shape of the control polygon, which consists of
• They always pass through the first and last control points.
• They are contained in the convex hull of their defining control points.
• The degree of the polynomial defining the curve segment is one less that
the number of defining polygon point. Therefore, for 4 control points, the
• The direction of the tangent vector at the end points is same as that of the
• The convex hull property for a Bezier curve ensures that the polynomial
• No straight line intersects a Bezier curve more times than it intersects its
control polygon.
• Bezier curves exhibit global control means moving a control point alters
• A given Bezier curve can be subdivided at a point t=t0 into two Bezier
value t=t0.
B-Spline Curves
The Bezier-curve produced by the Bernstein basis function has limited
flexibility.
• First, the number of specified polygon vertices fixes the order of the
function is nonzero for all parameter values over the entire curve.
The B-spline basis contains the Bernstein basis as the special case. The B-
• The sum of the B-spline basis functions for any parameter value is 1.
• Each basis function has precisely one maximum value, except for k=1.
defining polygon.
• B-spline allows the local control over the curve surface because each
vertex affects the shape of a curve only over a range of parameter values
• The curve line within the convex hull of its defining polygon.
THE END