CGR Notes
CGR Notes
Computer graphics is one of the most effective and commonly used way to
interact with computer.
It displays information in the form of graphics objects as windows, graphs,
diagrams etc.
Computer graphics is field of computer science concerned with digital
synthesizing and manipulate of visual content.
Image:-image is virtual representation of something. Image is a picture that has
been created or copied and stored in electronic form.
Objects:- is an item within graphic such as circle, square
Pixel:
The image that is displayed on the screen is composed of thousands of small dots,
these are called pixels, it represents the smallest piece of screen that can be
controlled individually.
Resolution:
Total no of pixels contained on display monitor express in terms of number
pixels on horizontal axis and number of pixels on vertical axis.
If an image has m rows and N columns then its resolution can be defined as
MXN.
Image resolution is described in PPI (Pixels per inches) which refers to how
many pixels are displayed per inch of an image.
Higher pixel resolution the higher is quality of image.
E.g 64X480, 1024X768, 800X600.
Aspect Ratio:
It is the ratio of number of X pixels to number of Y pixels. The standard aspect
ratio for PC is 4:3
Text mode Graphics mode
1. when you start a program me under 1. when you start a program under
MS-Das the computer’s screen is in windows the computers screen is in
character (Text) mode. graphic mode.
2. in this every character is drawn as dot 2. in this everything is drawn one dot
pattern. (pixel) at a Time.
3. in text mode display configuration 3. In graphics mode it show 640 pixels
allows 80 characters across each row and horizontally and 480 pixels horizontally
25 lines of characters. and 480 pixels vertically.
4. in this character always have the same 4. In this, each pixel can be any of 16
font and colour of each letter. And its colours and different types of fonts.
background can be changed.
5. the character mode displays are faster 5. Graphics mode displays are slower than
than graphics mode display text mode display.
6. in this there is no way to show pictures 6. In this we can display Pictures, charts,
graphs.
Application:
In this change are made to the scene as required.
Geometry: It is responsible for majority of operations with polygons and their vertices.
It can be divided into 5 tasks.
1 model and camera transformation.
2. Lightning
3. Projection
4. Clipping
5. Window viewpoint transformation,
1. Model and camera transformation:
This converts object coordinates into camera coordinates.
2 lighting:-
Applied to determining its colour
3. Projection: - it transforms 3D area into 2D area.
Clipping: - this removes the parts of image that are not visible in 2D screen view
window viewpoint transformation: - in order to output the image to any target are
(viewpoint) of screen window viewpoint transformation is applied.
Rasterization:-
In this image described in vector graphics format (shapes) is converted into raster
image (pixels) for output on video display or printer or for storage in bitmap file format.
computer
In graphics we typically use at least 3 coordinate systems.
Bitmap graphics can be edited by erasing or changing color of individual pixel using
program me such as adobe photoshop. Bitmap consists of matrix of individual pixels
that all have their own colour .using bits.
vector graphics:
vector images use mathematical formulas to draw lines and curves that can be
combined to create an image from geometric objects such as circles and polygons.
Vector images are edited by manipulating the lines and curves that make up image
using program me such as adobe illustrator.
Vector images tend to be smaller than bitmap image. Since bitmap images store colour
information for each individual pixel. And vector image just stores mathematical
formulas that make up image which take up less space.
Vector images are scalable without losing the quality.
E.g. EPS, PSD etc.
6. Entertainment:
Computer graphics method is used in making music videos, television shows, games,
cartoon movies etc.
Computers are used create realistic special effect digital imaging, animation,
background sound.
7. Education and training:
Teacher use computers to prepare their lectures and being their classrooms real life
examples to provide the framework which is important for learning.
in medical colleges, students are taught to operate a body in stimulated environment
on computer.
8. Communication:
With video conferring two people can communicate with each other without being
physically present at common place.
9. Interactive graphics:
This allows comprehensive, high bandwidth, user computer interaction.
By interacting, graphics produces higher quality and accurate results without
incurring much expenditure on analysis and design phase
Display devices:
The display devices are also known as output devices. The operations of most
monitors is based on standard cathode- ray- tube (CRT) there are two techniques
used for producing images on CRT screen.
1. Vector scan/random scan
2. Raster scan.
1. Vector scan:
Random scan display uses the technology to draw directly the pictures on screen i.e
the beam is displayed on position where pictures has to be displayed.
random scan monitors draw a picture one line at a time and for this reason are also
referred to as vector display file.
refresh rate on random scan system depends on number of lines to be displayed.
Pictures definition is stored as a set of line drawing commands in an area of memory
referred to as refresh display file.
Refresh display file is also called as display list, display program or refresh buffer
To display a specified picture, the system cycles through the set of commands in the
display file, drawing each components line in turn.
After all time drawing commands have been processed, the system cycle. Back to the
first line commands in the list.
Random scan displays are designed to draw all the component lines of picture 30 to
60 times each second.
When the beam is moved from left to right it is ON. The beam is OFF, when it is
moved from the right to left as shown by allotted line
When beam reaches the bottom of screen it is made OFF and rapidly back to top left to
start again.
In raster scan display special area of memory is dedicated to graphics only. This
memory area is called frame buffer. Which holds the set of intensity values are
retrieved from frame buffer and displayed on screen on row at a time.
On black and white system one bit per pixel the frame buffer is commonly called
bitmap. For system with multiple bits per pixel, the frame buffer is other referred to
as pixma.
1. in this beam is moved between the In this beam is moved all over the
end points of graphics primitive screen one scan line at a time from
top to bottom then back to top
2. flickers when the number of The refresh process is independent
primitives in buffer becomes too to complexity of image
large
3. scan conversion is not required Scan conversion is required
4. vector displays draw a continuous Can display mathematically smooth
and smooth lines lines, polygons, and boundaries of
curved primitives.
5. cost is more Cost is less
6. only draws lines and characters. Has ability to display areas filled
with wild colours or patterns
7. only Draws lines of characters Has ability to display area filled with
solid colours or patters .
Emissive displays:
They convert electrical energy into light energy. Plasma panels, thin film electro
luminescent displays and light emitting diodes are examples of emissive display
LED display:
It is flat panel display that uses an array of light emitting diodes as pixels for a video
display.
An LED panel consist of several LEDs, where as an LED display consist of several LED
panels
A light emitting diode is made up of semiconductor chip which is surrounded by
transparent plastic case.
The plastic case allows the light to pass through it.
The emission of different colours including ultraviolet and infrared light depends on
semiconductor material which is used in diode.
Disadvantages of L
ED displays:
LEDs are more expensive than conventional lighting technologies.
LEDs can shift colour due to age and temperature.
Contrast ratio are not consistent.
Application:
Used for signs and billboards.
Used for variable-message sign on highways.
Used in modern electronic devices such as mobile phones, TVs, tablets, computer
monitors, laptops screen etc.
LCD displays:
It has crystalline arrangement of molecules
Two glass plates, each containing light polarizer at right angles to other plate
sandwich the liquid crystal material.
Rows of horizontal transparent conductors are built into one glass plate and columns
of vertical conductor are put into other plate.
The interaction of two conductors defines pixel position
In ON state polarized light passing through material is twisted so that it will be
pass through opposite polarizer to turn off the pixel, we apply a voltage to two
intersecting conductors to align the molecules so that light is not twisted.
Plasma displays:
Plasma panel display writes images on display surface point by point, each point
remains bright after it has been intersected
it consists of two plates of glass with thin, closely spaced gold electrodes.
The gold electrodes are attached to inner faces and covered with a dielectric
material.
These are attached as series of vertical conducting ribbons on one glass plate and set
of horizontal ribbons on another glass plate.
The space between two glass plates is filled with neon gas and sealed.
By applying voltage between electrodes gas is made to behave if it Is divided into
tiny cells.
Advantages:
Refreshing is not required.
Produces a very steady images, flicker free
Less bulky than CRT.
Allows selective writing and selective erasing at speed of about 20 sec per cell.
It has flat screen and it is transparent, so the displayed image can be superimposed
with pictures from slides or other media projected through the rear panel.
Disadvantages:
Radially poor resolution of about 60 dots per inch.
It requires complex addressing and writing
Costlier than CRTs
Touch screen:
When you place fingertip directly on computer screen, touch screen accepts input.
Generally, this method is used to make a choice from menu.In this the sensors are
used on screen’s surface to detect the touch of finger it needs dirt free environment.
Application:
Automated teller machines(ATM)
Public information kiosks.
Fast food restaurants.
Department store.
Drug store
Supermarkets.
Lottery centers
Output primitives:
The basic attributes of straight line segment are its types Output primitive: line,
polygon, marker, text line. The basic attributes of straight line segment are its
width, its color.
Line Line polygon, market, text line.
(x1, y1, x2, y2)
Where x1, y1 are starting point and x2, y2 are ending points.
Polygons:
It is closed figure where sides are line segment.
Rectangle (x1, y1, x2, y2)
Triangle (x1, y1, x2, y2, x3, y3,)
Marker symbol is single character that can be displayed in different colors in different
sizes.
Text, there are many text option that can be made available to graphics programmers.
There is the choice of font which is set of character with particular design style such as
character with particular design such as courier, areal, times new roman and so on. We
can select text colour also.
GKS:
GKS stands for graphical kernel system
It is accepted as international standard for two-dimensional graphics.
Designed to be portable across different programming language, graphic devices
and hardware.
Functions:
The GKS function for drawing line segments is called polyline
The polyline function takes an array of X-Y coordinates and draws line segments
connecting them primitives in GKs
Poly marker function marks sequences of points with same symbol.
TEXT function draws a string characters
semantics:
Extract the meaning from data and context and use it for better insight.
fusion:
Combine multiple techniques, data streams and models to solve complex problems.
interaction:
Combine multiple and iniquitous input devices to create ergonomic user interfaces
Acquisition:
Process data from various impact sources to deal with missing data contradictor and
uncertainty.
Scene database includes geometric representations and attributes for all objects
within the environment
The graphic engine generates the image that seen by user. While doing so the scene
database, viewer’s current position and orientation is taken into consideration,
The stimulation engine performs main task i.e it concerns about dynamic of
environment over time and how it responds to user’s actions.
The user interface controls the user navigation and interaction with virtual
environment. It acts as buffer between virtual world software and input devices
being used.
With the help of specialized equipment user can be enjoy the environment and
gaming as VR system enables the user to feel VR system enables the user to feel
his/her presence in virtual world.
Help and healing:
VR system are very much helpful in rehabilitation of patients suffering from any
kind of phobia or chronic disease.
A VR system attempts for totally immersive virtual environment in which the user
is performing his task. An AR system combines the real and virtual in order to assist
the user in performing his task.
Augmented reality is halfway point between non-immersive and fully immersive VR
system.
The application of AR system in surgery include visualization and training support
as well as the collection of 3D patient data.AR system are used in military
applications tracking systems, medical surgeries etc.
Line is straight object with no curves, no thickness and it extend in both directions
without end if it does not ends it is called line segment.
The process of turning on the pixels for a line segment is called vector generation or line
generation. The algorithm for them are known as vector generation algorithm or line
drawing algorithms.
Line drawing algorithm.
xi +1 = xi + x
x2 − x1
= xi + y
y2 − y1
yi + 1 = yi + y
y2 − y1
= yi + x
x2 − x1
If x y then
x = 1
else
y = 1
If x = 1
xi + 1 = xi + 1
y2 − y1
yi + 1 = yi +
x2 − x1
If y = 1
yi + 1 = yi + 1
x2 − x1
xi + 1 = xi +
y2 − y1
DDA line algorithm.
1. real the line end points (x1,y1) and (x2,y2) such that they are not equal.
2. x = x2 − x1 & y = y2 − y1
3. if ( x y ) then
Length= y
End if
4. x = ( x2 − x1 ) / length
5. y = ( y2 − y1 ) / length
[The sign function makes the algorithm to work in all quadrant. it returns -1, 0, 1
depending whether the arguments is <0, =0,> 0 respectively.]
Plot (integer (x), integer (y).
6. i=1
[begins the loop in this loop points are plotted while (i length)]
x = x + x
y = y + y
Plot (integer (x), integer (y).
I = i+1
}
7. Stop:
Consider the line from (0, 0) to (4,6) use simple DDA algo to rasterize this line.
:-- x1=0 y1= 0 x2=4 y2=6
Together
x = x2 − x1 = 4 − 0 = 4
y = y2 − y1 = 6 − 0 = 6
y x Length= y − 6
x = ( x2 − x1 ) / Length = 4/6=2/3
y = ( y2 − y1 ) /
Length = 6/6=1
I X Y Plot (x,y)
1 0.5 0.5 (0,0)
2 1.66 1.5 (1,1)
3 1.83 2.5 (1,2)
4 2.5 3.5 (2,3)
5 3.16 4.5 (3,4)
6 3.83 5.5 (3,5)
7 4.5 6.5 (4,6)
Disadvantages:
Floating point arithmetic in DDA algorithm is time consuming
The algorithm is orientation dependent hence end point accuracy is poor.
putpixel(x,y,15);
i=1;
while (I<=length)
x=x+dx;
y=y+dy;
putpixel(x,y,15)
i=i+1;
delay (100);
}
getch
closegraph ();
}
Y= mx+b
I E x y Plot (x,y)
0 5 5 5,5
1 -8 6 6 6,6
2 0 7 6 7,6
3 -8 8 7 8,7
4 0 9 7 9,7
5 -8 10 8 10,8
6 0 11 8 11,8
7 -8 12 9 12,9
8 0 13 9 13,9
Algorithm:
1. Read the radius r of circle and calculate value of E
2. start x=0
Start-y=x
3. x1=start x
Y1=start –y
4. do
{x2=x1+y1
Y2=y1-x2
X1=X2;
Y1=y2
} while (y1-start_y)< or (start_x-x1)>
5. stop.
B = D 2 B − r 2
A = ( Xi + 1) 2 + ( yi − 1) 2 − r 2
A will always be positive and B will always be negative
Di=A+B
=(xi+1)2+yi2-r2+(xi+1)2+(yi-1)2-r2
=2(Xi+1)2+yi2+(yi-1)2-2r2
To find initial value of decision parameter at starting point Xi=0, yi=r
d0 = 2(0+1)2+r2+(r-1)2-2r2
= 2+r2+r2-2r+1-2r2
= 2+2r2-2r+1-2r2
= 3-2r
For di< 0 Xi+1 = Xi+1 yi+1 =yi
For di > 0 Xi + 1 yi+1 =yi-1
i = 2( xi + 1) 2 + yi 2 + ( yi − 1) 2 − 2r 2
di+1 = 2(Xi+1+1)2+y2i+1+(yi+1-1)2-2r2
for di< 0 Xi+1=Xi+1 yi+1=yi
di=2(xi+1+1)2+yi2+(yi-1)2-2r2
= 2(xi+2)2+yi2+(yi-1)2-2r2
= (xi2+4xi+4)+yi2+yi2-2yi+1-2r2
= 2xi2+8xi+8+2yi-2yi+1-2r2
=2xi2+4Xi+2+6+4xi+2y2i-2yi+1-2r2
=2(xi2+2xi+1) + 6+4xi+2(yi-1)2-2r2
=2(Xi+1)2+6+4xi+2(yi-1)2-2r2
=di +4Xi + 6
x=x+1=2+1=3
y=y=10
plot (x,y)
d0 13>0
d = d + 4(x-y) +10
=13+4(-7)+10
=13-28+10
D =-5
X=x+1=3+1=4
Y=y-1=10-1=9
Plot (x,y) (4,9)
d<0 -5<0
d =d+4x+6
=-5+4x4+6
=-5+16+6
=17
X=x+1 = 4+1=5
Y=Y=9
Plot (x,y) (5,9)
d0 170
d=d+4(x-y) + 10
=17+4(5-9) + 10
=17-16+10
=11
X=x+1=5+1=6
Y=y-1=9-1=8
Plot x, y (6,8)
d0 110
d=d+4(x-y) + 10
= 11+4(6-8) + 10
=11-8+10
=13
X=x+1=x+1=6+1=7
Y=y-1 =8-1=7
Plot (x,y) (7,7)
X Y d
0 10 -17
1 10 -11
2 10 -1
3 10 13
4 9 -5
5 9 17
6 8 11
7 7 13
Polygons:
When starting point and terminal point of any polyline is same i.e. when polyline is
closed then it is called polygon.
Types of polygon:
There are two types of polygon.
Convex
Concave
Convex:
A convex polygon is polygon in which in which the line segment joining only two points
within the polygon lies completely inside the polygon.
Concave:
A concave polygon is polygon in which the line segment joining any two points within
the polygon may not lie completely inside polygon.
If the intersection point is vertex of polygon then we have to look at other end points of
the two segments which meet at this vertex. If these points lie on same side of
constructed line, then the points in question counts as an even number of intersections
I they lies on opposite side of constructed line, then the point is counted as single
intersect
Winding number method:-
In winding
number method, we have to picture a line segments running from outside the polygon
to the points to the point in equation and consider sides which it crosses.
Draw the edge.
We must select a line that should not pass through any vertices. Polygon edges crossed
by this line could be drawn staring below the line could be drawn starting below the
line, cross it and end above the line or starting above the line, cross it and end below
the line.
In first case we have to give direction number as -1 and in sectioned case we have give
direction number as 1.
The sum of the direction numbers for the sides that the constructed horizontal line
segments is called winding number for point in question.
For polygon or two dimensional objects.
The points is said to be inside when the value of winding number is non zero.
Non zero – inside.
Zero –outside (0).
Polygon filling:
Polygon filling algorithm and scan line algorithm. Are classified as seed algorithm and
scan line algorithm.
Stroke method:
This method uses small line segments to generate a
character. The small series of line segments are drawn
like a strokes of pen forms character is shown in fig.
Starburst method:-
In this method fix pattern of line
segments are used to generate
characters. As shown in fig. there
are 24 line segments.
Bitmap method:
It is also called dot matrix because in this method characters are represented by an
array of dots in matrix form.
It is two dimensional array having columns and rows. an 5x7 array is commonly
used to represent characters.
3.Overview of transformations
We can make changes in an image by performing mathematical operations on
coordinates is known as transformation
2D transformation:
Translation:
It is process of changing the position of an object in a straight line path from one
coordinate location to another
we can translate two dimensional point by adding translation distances tx and ty to
the original coordinate position (x, y) to move the point to new position (x’ , y’)
X’=x+tx y’=y+ty
P’=P+T
x ' x tx
y ' = y + ty
1 0 0
Tx = 0 1 0
tx ty 1
Rotation:
A two dimensional rotation is applied to an object by repositioning it along a circular
path in the xy plane is known as rotation.
x = r cos y = r sin
x ' = r cos( + ) y = r sin( + )
= r cos cos − r sin sin y = r sin cos + r cos sin
= r cos − y sin y = y cos + x sin
P’=P.R
Where
cos sin
R=
− sin cos
For negative value of i.e for clockwise rotation, the rotation matrix becomes
cos(− ) sin(− )
R=
− sin(− ) cos(− )
cos − sin
R=
sin cos
A point (4,3) is rotated counter clockwise by an angle of 450. Find the rotation matrix
and the resultant point.
cos sin
R=
− sin cos
=450
cos 45 sin 45 1/ 2 1/ 2
R= =
− sin 45 cos 45 −1/ 2 1/ 2
P’=P.R
1/ 2 1/ 2
=[4 3]
−1/ 2 1/ 2
1 3 1 3
4 2 − 2 4 +
2
2
1 7
= ,
2 2
1 7
P' = ,
2 2
A' A
B ' = B .S
C '
C
2 5 4 10
7 10 2 0
0 2 = 14 20
10 2 20 4
A’ =(4,10) B’=(14,20) C’=(20,4)
1 0 0
T = 0 1 0
0 2 1
C) Here tx=1 ty=-1/2
1 0 0
T = 0 1 0
1
0 − 1
2
d) Here tx=-4 ty=-2/3
1 0 0
T = 0 1 0
2
−4 − 1
3
Find transformation matrix that transforms given square ABCD to half its size with
center will still remaining at same position the coordinates of the square are:
A(1 ,1), B(3 ,1) C (3 ,3) D(1 ,3) and center at (2, 2). Also find resultant coordinates of
square.
This transformation is carried out in following steps.
1. Translate square so that its center coincides with origin
2. Scale square with respect to origin,
3. Translate square back to original position.
1
2 0 0
1 0 0 1 0 0
T1.S .T . = 0 1 0 0
1
0 0 1 0
2
−2 − 2 1 0 2 2 1
0 1
1
2 +0+0 0+0+0 0
1 0 0
0+ 0 +0 0+ 1 +0 0 0 1 0
2
2 2 1
−2 1 + 0 + 0 0 − 2 1 + 0 1
2 2
1
2 0 0
1 0 0
0 1
0 0 1 0
2
−1 2 2 1
− 1 1
1.5 1.5 1
2.5 1.5 1
2.5 2.5 1
1.5 2.5 1
A’= (1.5, 1.5) B’= (2.5,1.5) C’= (2.5,2.5) D’= (1.5 , 2.5
Find transformation of triangle A (1,0), B (0,1) c ( 1, 1) by.
a) rotating 450 about the origin and then translating one unit in x and y direction.
B) translating one unit in x and y direct and then rotating 450 about origin.
The rotation matrix is
cos sin 0 cos 45 sin 45 0
R = − sin cos 0 = − sin 45 cos 45 0
0 0 1 0 0 1
1 1
2 0
2
1 1
− 2 2
0
0 0 1
The translation matrix is
1 0 0 1 0 0
0 1 0 = 0 1 0
tx ty 1 1 1 1
1 1
2 0
2 1 0 0
1 1 0 1 0
a) R.T = − 0
2 2
1 1 1
0 0 1
1/ 2 1/ 2 0
−1/ 2 1/ 2 0
=
1 1 1
1 1
2 0
2
A ' A
B ' = B 1 1
− 2 2
0
C ' C
1 1 1
1 1
2 0
2
1 0 0
1
= 0 1 1
1
− 2 2
0
1 1 1
1 1 1
1 1
2 +1 2
+1 1
1 1
− 2 +1 2
+1 1
1 2 +1 1
1 1
2 0
2
1 0 0
1
b)T.R= 0 1 0
1
− 2 2
0
1 1 1
0 0 1
1 1
2 0
2
1 1
− 2 2
0
0 2 1
1 1
2 0
2
A ' A
B ' = B 1 1
− 2 2
0
C ' C
0 2 1
1 1
2 0
2
1 0 1
0 1 1 1 1
− 2 2
0
1 1 1
0 2 1
1 3
1
2 2
1 3
− 1
2 2
2
0 1
2
Rotation about an arbitrary point
To rotate an object about an arbitrary point (xp , yp) we have to carry out 3 steps..
Translate point (xp , yp)to origin
Rotate it about origin
Translate the center of rotation back where it belongs.
(XY,YP)
- Rotation matrix
cos sin 0
R = − sin cos 0
0 0 1
Translation matrix to move centre point back to its original position is given as
1 0 0
R = 0 1 0
xp yp 1
Therefore overall transformation matrix for counter clockwise rotation by an angle
question about point (xp , yp) is given at.
1 0 0 cos sin 0 1 0 0
T1 .R.T2 = 0 1
0 − sin cos 0 0 1 0
− xp − yp 1 0 0 1 xp yp 1
cos sin 0 1 0 0
= − sin cos 0 0 1 0
− xp cos + yp sin − xp sin − yp cos 1 xp yp 1
cos sin 0
= − sin cos 0
− xp cos + yp sin + xp − xp sin − yp cos + yp 1
Perform counter clockwise 450 rotation of triangle A (2 ,3) B (5 ,5) C(4,3) about point
(1,1)
cos sin 0
T1RT2 = − sin cos 0
− xp cos + yp sin + xp − xp sin − yp cos + yp 1
=450 Xp=1 Yp=1
cos 45 sin 0
T1RT2 = − sin 45 cos 0
−1cos 45 + yp sin 45 + 1 − 1.sin 45 − 1.cos 45 + 1 1
1 1
0
2 2
1 1
− 0
2 2
1 1 1 1
− + +1 − − +1 1
2 2 2 2
1 1
2 0
2
1 1
− 2 2
0
2
1 − +1 1
2
1 1
2 0
2
A ' 2 3 1
B ' = 5 5 1 − 1 1
0
2 2
C ' 4 3 1
1 − 2 +1 1
1 3
− +1 +1 1
2 2
8
1 +1 1
2
1 5
+1 +1 1
2 2
Consider the square A(1 ,0), B (0 , 0), C(0 ,1) and D(1 ,1) rotate the square by 450
anticlockwise direction followed by reflection about x-axis.
cos sin 0 1 0 0
T = − sin cos 0 0 − 1 0
0 0 1 0 0 1
cos − sin 0
T = − sin − cos 0
0 0 1
=450
1 1
2 − 2 0
cos 45 − sin 45 0
T = − sin 45 − cos 45 0 = −
1 1
− 0
2 2
0 0 1
0 0 1
1 1
− 0
A ' 1 0 1 2 2
B ' 0
= 0 1 1 1
− − 0
C ' 0 1 1 2 2
D ' 1 1 1 0 0 1
1 1
2 − 0
2
0 0 1
1 1
− − 1
2 2
0 − 2 1
1 1 1 1
A' =
2
,−
2
B ' = ( 0, 0 ) C' = −
2
,−
2
(
D ' = 0, − 2 )
Reflection:
A reflection is transformation that produce a mirror image of an objects relative to an
axis of reflection.
Reflection about y −1 0 0
axis 0 1 0
0 0 1
Reflection about x 1 0 0
axis 0 −1 0
0 0 1
Reflection about − 1 0 0
origin 0 − 1 0
0 0 1
Reflection about 0 1 0
y=x 1 0 0
0 0 1
Reflection about 0 −1 0
y=-x −1 0 0
0 0 1
Shear:
A transformation that slants the shape of an object is called shear transformation there
are two transformation of shear.
X-shear:
In this x - coordinates are shifted and y coordinates are preserved. It changes x values
which causes vertical lines to tilt right or left.
1 0 0
X-shear with y-ref.= Ysh = shx 1 0
− shx. yref 0 1
1 shy 0
Y-shear with X-ref. = 0 1 0
0 − shyxref 1
Apply the shearing transformation to square with A (0,0), B(1 ,0), C(1,1), D(0,1) as
given below.
a) shear parameter value of 0.5 relative to line yref = -1
b) shear parameter value of 0.5 relative to line xref=-1
Xsh=0.5 yref=-1
A' A
B ' B 1 0 0
= shx 1 0
C ' C
− shx. yref 0 1
D ' D
−1 0 0
0 1 0 1 0 0
0.5 1 0
1 1 1
− 1 − 1 0 1
0 1 1
0 0 1
1 0 1 1 0 0
0.5 1 0
1 1 1
1 0 1
0 1 1
0.5 0 0
1.5 0 1
2 1 1
1 1 1
b) shy =0.5 and Xref=-1
A' A
B ' B 1 shy 0
= 0 − xrefshy1 0
C ' C
0 − Xrefshy 0 1
D ' D
0 0 0
1 1 0
0 1
0.5
0 1 0
1 1 1
0 − 1 −1 1
0 1 1
1 0.5 0
1 1 1
1 2 1
0 1.5 1
show how shear transformation may be expressed in terms of rotating and scaling.
Shear transformation matrix for x and y can be given as
1 shy 0
shx 1 0
0 0 1
1 0 0 0
0 1 0 0
T=
0 0 1 0
tx ty tz 1
P’=P.T
1 0 0 0
0 1 0 0
X 'Y ' Z '1 = X Y Z 1
0 0 1 0
tx ty tz 1
[X+TX Y+TY Z+TZ 1]
Scaling:
Three dimensional transformation matrix for scaling is
sx 0 0 0
0 sy 0 0
0 0 sz 0
0 0 0 1
P’=P.T
sx 0 0 0
0 sy 0 0
X 'Y ' Z '1 = X Y Z 1
0 0 sz 0
0 0 0 1
[X.SX Y.SY Z.SZ 1]
Rotation:
Three dimensional transformation matrix for each coordinate axis rotation is
1. Rotation about X-axis.
1 0 0 0
0 cos sin 0
Rx =
0 − sin cos 0
0 0 0 1
2. rotation about y- axis.
cos 0 − sin 0
0 1 0 0
Ry =
sin 0 cos 0
0 0 0 1
3. rotation about z-axis.
cos sin 0 0
− sin cos 0 0
Rz =
0 0 1 0
0 0 0 1
Types of projection:
We can project the 3 dimensional object onto the two dimensional view plane there are
two basic ways of projecting objects onto the new plane.
Parallel projection.
Perspective projection.
Parallel projection:
In parallel projection, Z coordinate is discarded and parallel lines form each vertex on
the object are extended until they intersect the view plane.
Parallel projections are basically categorized into two types, depending on relation
between the direction of projection and normal to view plane.
When the direction of projection is normal (perpendicular) to view plane, we have an
orthographic parallel projection.
When the direction of projection is normal (perpendicular) to view plane we have an
oblique parallel projection.
Orthographic parallel projection is subdivided into 2 types
Axonometric orthographic and multi view orthographic projection.
The orthographic projection can display more than one face of an object such on
orthographic projection is called axonometric orthographic projection.
1. Isometric:
All 3 principles axes are foreshortened equally
2. Diametric:
Two principle axis are foreshortened equally.
3. Trimetric:
All three principles axis are foreshortened unequally.
Perspective projection:
It produces realistic views. In this the lines of projections are not parallel they all
converge at single point called centre of projection or projection reference point
The perspective projection of any set of parallel lines that are not parallel to projection
plane converge to vanishing point
The vanishing point for any set of lines that are parallel to one of 3 principle axis of an
object is referred to principle vanishing point.
The perspective projection is classified into 3 types
1. One point projection
2. Two point projection
3. Three point projection
Viewing transformation:
The mapping of coordinates from world coordinate system to physical device coordinate
system is called viewing transformation.
MC-
Determine MC Coupon world VC Normalize NYC Convent
would coordinate to viewing normalized
coordinate of viewing coordination viewing
scene using coordination coordinates
modeling to device
coordinate coordination
transformation
Window:
A world coordinate are selected for display is called window.
View part:
An area on display device to which a window is mapped is called view part.
Types of clipping:
Line clipping
Point clipping
Area clipping
Curve clipping
Text clipping.
Line clipping:
Deciding visible portion of line is known as line clipping.
The lines are said to be interior to clipping window and hence visible if both end points
are interior to window.
If both end points of line are exterior to window, the line is not necessarily completely
exterior to window
If both the end points are completely to right of, completely to left of completely above,
completely below the window, then the line is completely exterior to window and hence
invisible.
6
= ( 50 − 40 ) + 15
7
6
= (10) + 15
7
= 23.57
1
YT X = (YT − Y1 ) + X 1
m
7
= ( 40 − 15) + 40
6
7
= ( 25 ) + 40
6
= 69.16
y −y 10 − 20 −10 −1
m= 2 1 = = =
x2 − x1 100 − 70 30 3
X R , Y = m( X R − X 1 ) + Y1
−1
= ( 80 − 70 ) + 20
3
1
= (10 ) + 20
3
= 16.66
I 2 = ( 80.16.66 )
Use outside based line clipping method is clip a line starting from (-13, 5) and ending at
(17,11) against the window having its lower left corner at (-8, -4) and upper right corner
at (12, 8).
Point endcode Anding Position
P1 0001 0000 Partially
P2 1010 Visible
y = m ( X L − X 1 ) + y1
= ( −8 − ( −13) ) + 5
1
6 1
Slop of line m = = XL,y 5
30 5 1
= ( −8 + 13) + 5
5
=6
1
yT , X = (YT − Y1 ) + X 1
m
= 5 ( 8 − 5 ) + (−13)
= 5 3 + (−13)
=2
I1 = ( X L , y) = (−8, 6)
I 2 = ( X T , YT ) = (2,8)
D=P2-P1= [6 3] - [-2 1]
= [8 2]
For boundary point f (3,0)
W=P1-f= [-2 1] - [3 0]
= [-5 1]
For the edge V1V2 the inner normal is
N [1 1]
hence D.n=[8 2][1 1]
= [8x1]+2x1]
=[10]
We have
Maximum lower limit tL=4/10
Minimum upper limit tu=7/8
Substituting these values of t in parametric equation.
P ( 4 /10 ) = P1 + ( P2 − P1 ) .(4 /10)
= [−2 1] + [8 2] (4 /10)
= [−2 1] + [3.2 0.8]
= [1.2 1.8]
P ( 7 / 8 ) = P1 + ( P2 − P1 ) .(7 / 8)
= [−2 1] + [8 2] (7 / 8)
= [−2 1] + [7 1.75]
= [5 2.75]
The intersection points to line P1P2 are [1.2 1.8] and [5 2.75] with edge are [1.2 1.8]
and [5 2.75] with edges V1V2 and V5V6 respectively.
X w min x1 + t x X w max
Yw min y1 + t y Yw max
Liang-barsky express and inequalities with two parameter P and Q as follows.
tpi qi i = 1, 2,3, 4
Where
P1 = x q1 = x1 − xw min
P2 = x q2 = xco max − x1
P3 = −y q3 = y1 − yw min
P4 = y q4 = yco max − y1
{
Check whether the line is horizontal or vertical according ly check the endpoint with
corresponding boundaries.
If line endpoints lie within the bounded area then use them to draw line otherwise use
boundary use boundary coordinates to draw line go to stop.
}
}
5. Initialize values for t1 and t2 as t1=0 and t2=1
6. Calculate values for qi/pi for i=1,2,3,4
7. Select values for qi/pi where Pi>0 and assign minimum out of them as t2
8. Select values of qi/pi where pi>0 and assign minimum out of them t2
9. If (t1<t2)
}
Calculate the endpoints of clipped line as follows
XX 1 = X 1 + t1x
XX 2 = X 1 + t2 x
yy1 = y1 + t1y
yy2 = y1 + t2 y
Draw line (XX1,YY1,XX2, YY2)
}
10. stop
Find clipping coordinates to clip the line segments AB against the windows liang Bars
lay line clipping algo A(20,20), B(80,110) and window coordinates are lower left corner
of windows (40,40) and upper right corner is (100,90)
q1 = X w min
= 20 − 40
X w min = 40 yw min = 40
= −20
X w max = 100 ywax = 90
q2 = X w max − X 1
X 1 = 20 y1 = 20
= 100 − 20 = 80
y2 = 80 y2 = 110
q3 = Y1 − Yw min
P1 = −x = −( x2 − x1 )
= 20 − 40 = −20
= −(80 − 20)
q4 = Yw max − Y
= −60
= 90 − 20
= 70
P2 = x = ( x2 − x1 )
= (110 − 20)
= −90
P4 = y = 90
P1 = −60 P2 = 60 P3 − 90 P4 = 90
q1 = −20 q2 = 80 q3 = −20 q4 = 70
qi / pi
qi / pi = −20 / −60 = 0.33
q2 / P2 = 80 / 60 = 1.33
q3 / p3 = −20 / −90 = 0.22
q4 / P4 = 70 / 90 = 0.778
For P < 0 values. That is for P1 and P3
t1 = max(q1 / P1 , q3 / P3 ) = max (0.33, 0.22)t1 = 0.33
for P 0 values that is for P1 andP2
for P 0 values that is for P2 and P4
t2 = min (q2 / P2 , q4 / P4 ) = min(1.33, 0.778)
t2 = 0.778.
t1 t2
XX 1 = X 1 + t1x
= 20 + 0.33(60)
= 40
XX 2 = X 1 + t2 x
= 20 + 0.778(60)
= 66.7
YY1 = Y1 + t1y
= 20 + 0.33(90)
= 50
YY2 = Y1 + t2 y
= 20 + 0.778(90)
= 90
( XX 1 , YY1 , XX 2 , YY2 ) = ( 40,50, 66, 7,90 )
Polygon clipping: -
Wherever a polygon is clipped as collection of line it is known as polygon clipping. After
clipping polygon remain closed.
The polygon can be clipped by processing its boundary as a whole against each window
edge. This is achieved by processing all polygon vertices against each clip rectangle
boundary in term.
Beginning with original set of polygon vertices, we could first clip the polygon vertices,
we would first clip the polygon against the left rectangle boundary to produce a new
sequence of vertices.
The new set of vertices could then be successively passed to right boundary clipper a top
boundary clipper and bottom boundary clipper.
At each step a new set of polygon vertices is generated and passed to the next window
boundary clipper.
There are four possible relationship between edge and clipping boundary or plane.
1. if first vertex of edge is outside window boundary and second vertex of edge is inside.
Then intersection point of is inside. Then intersection point of polygon with window
boundary and second vertex are added to output vertex list.
2. if both vertices of edge are inside the window boundary, only second vertex is called
to output vertex list.
3. if first vertex of edge is inside the window boundary and second vertex is outside,
only edge intersection with the window boundary is added to output list
4. if both vertices of edge are outside the window, nothing is added to output list.
Midpoint subdivision algorithm:
The Sutherland Cohen subdivision line clipping algorithm requires the calculation of
intersection of the line with window edge. This calculations can be avoided by repeated
until we get completely visible and completely invisible line segments.
Midpoints subdivision algorithm:
1. read two endpoints of line say P1(x1, y1) and P2(x2, y2)
2. read two corners (left top and right bottom) of window, say
3. Assign region codes for two end points using following steps:
Initialize code with bits 0000
Set Bit 1 - if (x<wx1)
Set Bit 2 –if (x>wx2)
Set Bit 3 – if (y<wy1)
Set Bit 4 –if (y>wy2)
Check for visibility of line
A) if region codes for endpoints are zero then the line is completely visible. Hence draw
the line and go to step 6
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 6
c) if region codes for two endpoints do not satisfy the conditions in (4a) and (4b) the line
is partially visible.
5) Divide the partially visible line segment in equal parts and repeat step 3 through 5
for both subdivided line segments until you get completely visible and completely in
visible line segment.
6) STOP
Apply the liong- barsky algorithm to line with coordinates (30,60) and (60,25) against
the window.
q1 = X 1 − X w min = 30 − 10 = 20
q2 = X w max − X 1 = 50 − 30 = 20
q3 = X w max − X 1 = 50 − 30 = 20
q4 = yw min − y1 = 50 − 60 = −10
q1 / p1 = 20 / 30 = 0.667
q2 / p2 = 20 / 30 = 0.667
q3 / p3 = 50 / 35 = 1.4285
q4 / p4 = (−10) / (−35) = 0.2857
forP 0 i.e P1 & P3
t1 = max(−0.667, 0.2857)
t2 = min(0.667, 0.2857)
XX 1 = X 1 + t1x
= 30 + 0.2857 x 30
= 38.571
YY1 = Y1 + t1y
= 60 + 0.2857 −35
= 50
XX 2 = X 1 + t2 x
= 30 + 0.667 30
= 50
YY2 = Y1 + t2 y
= 60 + 0.667 −35
= 36.655
Text clipping:
There are 3 different types of methods used for character/text clipping
5.Introduction to curves
Curve Generation: -
We can use two approaches to draw curved lines.
One approach is to use a curve generation algorithm such as DDA. In this
approach true curve is created.
In second approach the curve is approximated by number of small straight line
segments. This can be achieved with the help of interpolation techniques.
Circular Arc generation using DDA algorithm.
It uses the differential equation of curve which is given as.
(xo,yo) X=RCOSO+XO 1)
X-XO=RCOSO 2)
X = R cos + X …………1.
Y = R sin + Yo ………..2.
Differentiate eg 1 and 2
n
dx = - Rsind ………….. 3
dy = Rcosd …………… 4
x-xo = Rcos ………….. 5
y-yo = Rsin …………. 6
put 5 & 6 in eg 3 and 4
n
dx = - (Y-Yo) d
dy = (x-x2) d
The values of dx & dy indicate the increment in x & y increment respectively.
Next point on are can be calculated as
x2 = x1 + dx = x1 - (y1-yo) d
y2= y1+dy = y1 + (x2– xo) d
d = min (o.o1, 1/ (3.2* (1x-xo1 + 1y-yo1))
Algorithm:
1. Read the center of curvature say (X0 , Y0)
2. Read the arc angle, say .
3. Read the starting point of arc(x,y)
4. calculate d
d=min(0.01,1/(3.2*(1x-x01+1y-y0)))
initialize Angle = 0.
6. while (Angle<)
do
{ plot (x,y)
X=X-(y-y0)*d
Y=y+(x-x0)*d
Angle= Angle + d7. Stop.
Interpolation:
To deal with same complex curves for which no direct mathematical function is
available. Such curves can be drawn using approximation methods.
If we have set of sample points which lie on the required curve, then we can draw the
required curve by filling portion of curve with the pieces of known curves which pass
through nearby sample points. The gap between sample points can be filled by finding
the coordinates of points along the known approximately curve and connecting these
points with line segments.
The main task in this process is to find the suitable mathematical expression for known
curve. There are polynomial, trigonometric, exponential and other classes of functions
that can be used to approximate the curve
X=fx(u)
Y=fy(u)
Z=fz(u)
We will construct the function as the sum of terms, one terms, one term for sample
point. These functions can be given as,
𝑛
fx(u)= ∑𝑖=1 𝑥𝑖 𝐵𝑖 (𝑢)
n
fy(u)= y B (u)
i =1
i i
n
fz(u)= z B (u)
i =1
i i
Hilbert’s curve: -
Can be constructed by following successive approximations. if a square is divided into
four quadrants. we can draw first approximation to Hilbert curve by connecting Centre
point of each quadrant.
The second approximation to Hilbert’s curve can be drawn by further subdividing each
of the quadrant and connecting their centers before moving to next major quadrant
The third approximation subdivides quadrant again. We can draw third approximation
to Hilbert’s curve by connecting the Centre of finest level of quadrants. Before stepping
to next level of quadrants.
Koch curve:
Koch curve can be drawn by dividing line into 4 equal segments with scaling factor 1/3
and middle two segments are so adjusted that they form adjacent sides of an equilateral
triangle as shown in figure.
Bezier curves: -
It is determined by defining polygon.
They are easy to implement. Bezier curve section can be fitted to any number of control
points. As number of control points increases, the degree of Bezier polynomial also
increases. Three control points generate parabola, 4 control points generate cubic curve
and so on.
Bernstein polynomials:
The Bezier blending functions BEZ k, n (u)
are the Bernstein polynomial. They are
specified as
BEZ k,,n =(cn,k) uk (1-u)n-k
Where ((n,k) are binomial coefficients.
n!
C (n,k) =
k !(n − k )!
The position vector represents a set of 3
parametric equations for individual curve coordinates.
n
X (u) = X
k =0
k BEZ k ,n (u )
n
Y (u) = y BEZ
k =0
k k ,n (u )
n
Z (u) = Z BEZ
k =0
k k ,n (u)
Midpoint approach:
In this approach Bezier curve can be constructed simply by taking midpoints
In these midpoints of lines connecting 4 control points (A B C D) are determined
(AB, BC, CD)
These midpoints are connected by lines segments and their midpoints ABC and BCD
are determined.0
Finally, these two midpoints ABCD is determined.
Algorithm.
get four control. Points say A (XA, YA), B (XB, YB), C (Xc, Yc ), D(X0Y0)
Divide the curve presented by points A, B, C, D in two sections.
XAB=(XA+XB)/2
YAB=(YA+YB)/2
XBC=(XB+XC)/2
YBC=(YB+YC)/2
XCD=(XC+XD)/2
YCD=(YC+YD)/2
XABC=(XAB+XBC)/2
YABC =( YAB+YBC)/2
YBCD=(XBC+XCD)/2
YBCD=(YBC+YCD)/2
XABCD=(XABC+XBCD)/2
YABCD= (XABC+XBCD)/2
3. Repeat the step 2 for section A, AB, ABC ABCD and section ABCD, BCD, CD, D.
4. Repeat step 3 until we have sections so short they can be replaced by straight lines
5. Replace small sections by straight lines
6. Stop.
B-spline:
The Bezier curve produced by Bernstein basis function has limited flexibility.
The second limiting characteristics is that the value of blending function is nonzero
for all parameter values over entire curve.
Another basis function called B-spline bans.
It is non global because each vertex Bi is associated with unique basis function.
Each vertex affects the shape of curve only over the range of parameter values
where its associated basis function is nonzero.
It allows the order of the basis function hence degree of resulting curve is
independent of number of vertices.
The position vector is given by
n +1
P(u ) = BiNik (u)U min u umax , 2
i =1
(𝑢−𝑥1 )𝑁𝑖,𝐾−1 (𝑢) (𝑥𝑖+1 −𝑢)𝑁𝑖+1,𝐾−1(𝑢)
𝑁𝑖𝐾(𝑢) = 𝑋𝑖+𝐾−1 −𝑋𝑖
+ 𝑋𝑖+𝑘 −𝑋𝑖+1