Core-38-Computer-Graphics-and-Visualization-Sem-VI
Core-38-Computer-Graphics-and-Visualization-Sem-VI
V THREE-DIMENSIONAL VIEWING 84
Page 2 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
UNIT - I
OVERVIEW OF GRAPHICS SYSTEM
Page 3 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Types of Deflection:
1. ElectrostaticDeflection
The electron beam (cathode rays) passes through a highly positively
charged metal cylinder that forms an electrostatic lens. This electrostatic lens
focuses the cathode rays to the center of the screen in the same way like an optical
lens focuses the beam of light. Two pairs of parallel plates are mounted inside the
CRT tube.
2. Magnetic Deflection:
Here, two pairs of coils are used. One pair is mounted on the top and bottom
of the CRT tube, and the other pair on the two opposite sides. The magnetic field
Page 4 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
produced by both these pairs is such that a force is generated on the electron beam
in a direction which is perpendicular to both the direction of magnetic field, and
to the direction of flow of the beam. One pair is mounted horizontally and the
other vertically.
Different kinds of phosphors are used in a CRT. The difference is based
upon the time for how long the phosphor continues to emit light after the
CRT beam has been removed. This property is referred to as Persistence.
The number of points displayed on a CRT is referred to as resolutions (eg.
1024x768).
Raster-Scan
The electron beam is swept across the screen one row at a time from top to
bottom. As it moves across each row, the beam intensity is turned on and
off to create a pattern of illuminated spots. This scanning process is called
refreshing.
Each complete scanning of a screen is normally called a frame. The
refreshing rate, called the frame rate, is normally 60 to 80 frames per
second, or described as 60 Hz to 80 Hz.
Picture definition is stored in a memory area called the frame buffer. This
frame buffer stores the intensity values for all the screen points. Each
screen point is called a pixel (picture element or pel).
On black and white systems, the frame buffer storing the values of the
pixels is called a bitmap. Each entry in the bitmap is a 1-bit data which
determine the on (1) and off (0) of the intensity of the pixel.
On color systems, the frame buffer storing the values of the pixels is called
a pixmap(Though nowadays many graphics libraries name it as bitmap
too). Each entry in the pixmap occupies a number of bits to represent the
color of the pixel. For a true color display, the number of bits for each entry
is 24 (8 bits per red/green/blue channel, each channel 28 =256 levels of
intensity value, ie. 256 voltage settings for each of the red/green/blue
electron guns).
Page 5 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
The CRT's electron beam is directed only to the parts of the screen where
a picture is to be drawn. The picture definition is stored as a set of line-
drawing commands in a refresh display file or a refresh buffer in memory.
Random-scan generally have higher resolution than raster systems and can
produce smooth line drawings, however it cannot display realistic shaded
scenes.
Color CRT Monitors:
The CRT Monitor display by using a combination of phosphors. The phosphors
are different colors.
There are two popular approaches for producing color displays with a CRT are:
Beam Penetration Method
Shadow-Mask Method
Page 6 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Advantages:
Inexpensive
Disadvantages:
Only four colors are possible
Quality of pictures is not as good as with another method.
2. Shadow-Mask Method:
Shadow Mask Method is commonly used in Raster-Scan System because
they produce a much wider range of colors than the beam-penetration
method.
It is used in the majority of color TV sets and monitors.
Construction:
A shadow mask CRT has 3 phosphor color dots at each pixel position.
One phosphor dot emits: red light
Another emits: green light
Third emits: blue light
This type of CRT has 3 electron guns, one for each color dot and a shadow mask
grid just behind the phosphor coated screen. Shadow mask grid is pierced with
small round holes in a triangular pattern.
Page 7 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Working:
The deflection system of the CRT operates on all 3 electron beams
simultaneously; the 3 electron beams are deflected and focused as a group
onto the shadow mask, which contains a sequence of holes aligned with the
phosphor- dot patterns.
When the three beams pass through a hole in the shadow mask, they
activate a dotted triangle, which occurs as a small color spot on the screen.
The phosphor dots in the triangles are organized so that each electron beam
can activate only its corresponding color dot when it passes through the
shadow mask.
Advantage:
Realistic image
Million different colors to be generated
Shadow scenes are possible
Disadvantage:
Relatively expensive compared with the monochrome CRT.
Relatively poor resolution
Convergence Problem
Direct View Storage Tubes:
DVST terminals also use the random scan approach to generate the image
on the CRT screen. The term "storage tube" refers to the ability of the screen to
retain the image which has been projected against it, thus avoiding the need to
rewrite the image constantly.
Function of guns: Two guns are used in DVST
Primary guns: It is used to store the picture pattern.
Flood gun or Secondary gun: It is used to maintain picture display.
Page 8 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Advantage:
No refreshing is needed.
High Resolution
Cost is very less
Disadvantage:
It is not possible to erase the selected part of a picture.
It is not suitable for dynamic graphics applications.
If a part of picture is to modify, then time is consumed.
Flat Panel Display:
The Flat-Panel display refers to a class of video devices that have
reduced volume, weight and power requirement compare to CRT.
Example: Small T.V. monitor, calculator, pocket video games, laptop
computers, an advertisement board in elevator.
1. Emissive Display:
The emissive displays are devices that convert electrical energy into light.
Examples are Plasma Panel, thin film electroluminescent display and LED (Light
Emitting Diodes).
2. Non-Emissive Display:
The Non-Emissive displays use optical effects to convert sunlight or
light from some other source into graphics patterns. Examples are LCD (Liquid
Crystal Device).
Plasma Panel Display:
Plasma-Panels are also called as Gas-Discharge Display. It consists of an
array of small lights. Lights are fluorescent in nature. The essential components
of the plasma-panel display are:
1. Cathode:
It consists of fine wires. It delivers negative voltage to gas cells. The voltage is
released along with the negative axis.
Page 9 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
2. Anode:
It also consists of line wires. It delivers positive voltage. The voltage is supplied
along positive axis.
3. Fluorescent cells:
It consists of small pockets of gas liquids when the voltage is applied to this liquid
(neon gas) it emits light.
4. Glass Plates:
These plates act as capacitors. The voltage will be applied, the cell will glow
continuously.
The gas will slow when there is a significant voltage difference between
horizontal and vertical wires. The voltage level is kept between 90 volts to 120
volts. Plasma level does not require refreshing. Erasing is done by reducing the
voltage to 90 volts.
Each cell of plasma has two states, so cell is said to be stable. Displayable
point in plasma panel is made by the crossing of the horizontal and vertical grid.
The resolution of the plasma panel can be up to 512 * 512 pixels.
Advantage:
High Resolution
Large screen size is also possible.
Less Volume
Less weight
Flicker Free Display
Disadvantage:
Poor Resolution
Wiring requirement anode and the cathode is complex.
Its addressing is also complex.
Page 10 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 11 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Input Devices
The Input Devices are the hardware that is used to transfer transfers input
to the computer. The data can be in the form of text, graphics, sound, and text.
Output device display data from the memory of the computer. Output can be
text, numeric data, line, polygon, and other objects.
Page 12 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
A Mouse is a pointing device and used to position the pointer on the screen.
Page 13 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
It is a small palm size box. There are two or three depression switches on the top.
The movement of the mouse along the x-axis helps in the horizontal movement
of the cursor and the movement along the y-axis helps in the vertical movement
of the cursor on the screen. The mouse cannot be used to enter text. Therefore,
they are used in conjunction with a keyboard.
Advantage:
Easy to use
Not very expensive
Trackball
It is a pointing device. It is similar to a mouse. This is mainly used in
notebook or laptop computer, instead of a mouse. This is a ball which is half
inserted, and by changing fingers on the ball, the pointer can be moved.
Advantage
Trackball is stationary, so it does not require much space to use it.
Compact Size
Space ball
It is similar to trackball, but it can move in six directions where trackball
can move in two directions only. The movement is recorded by the strain gauge.
Strain gauge is applied with pressure. It can be pushed and pulled in various
directions. The ball has a diameter around 7.5 cm. The ball is mounted in the base
using rollers. One-third of the ball is an inside box, the rest is outside.
Page 14 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Applications
It is used for three-dimensional positioning of the object.
It is used to select various functions in the field of virtual reality.
It is applicable in CAD applications.
Animation is also done using spaceball
It is used in the area of simulation and modeling.
Joystick
Light Pen (similar to the pen) is a pointing device which is used to select a
displayed menu item or draw pictures on the monitor screen. It consists of a
photocell and an optical system placed in a small tube. When its tip is moved over
the monitor screen, and pen button is pressed, its photocell sensing element
Page 15 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
detects the screen location and sends the corresponding signals to the CPU.
Uses
1. Light Pens can be used as input coordinate posins by providing necessary arrangements.
2. If background color or intensity, a light pen can be used as a locator.
3. It is used as a standard pick device with many graphics system.
4. It can be used as stroke input devices.
It can be used as valuatorsDigitizers:
Page 16 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
When the wave signals are interrupted by some contact with the screen,
that located is recorded. Touch screens have long been used in military
applications.
Voice Systems (Voice Recognition):
Voice Recognition is one of the newest, most complex input techniques
used to interact with the computer. The user inputs data by speaking into a
microphone. The simplest form of voice recognition is a one-word
command spoken by one person. Each command is isolated with pauses
between the words.
Voice Recognition is used in some graphics workstations as input devices
to accept voice commands. The voice-system input can be used to initiate
graphics operations or to enter data. These systems operate by matching an
input against a predefined dictionary of words and phrases.
Advantage:
More efficient device.
This acceleration is generally produced by means of an accelerating
anode.
Next component is the Focusing System, which is used to force the
electron beam to converge to small spot on the screen.
If there will not be any focusing system, the electrons will be scattered
because of their own repulsions and hence we won’t get a sharp image of
the object.
This focusing can be either by means of electrostatic fields or magnetic
fields.
Easy to use
Unauthorized speakers can be identified
Disadvantages:
Very limited vocabulary
Voice of different operators can't be distinguished.
Image Scanner
It is an input device. The data or text is written on paper. The paper is
feeded to scanner. The paper written information is converted into
Page 17 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
It resembles a photocopy machine. It has a glass top on its top. Glass top
in further covered using a lid. The document to be scanned is kept on glass plate.
The light is passed underneath side of glass plate. The light is moved left
to right. The scanning is done the line by line. The process is repeated until the
complete line is scanned. Within 20-25 seconds a document of 4" * 6" can be
scanned.
2. Hand Held Scanner:
Page 18 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
It has a number of LED's (Light Emitting Diodes) the LED's are arranged
in the small case. It is called a Hand held Scanner because it can be kept in hand
which performs scanning. For scanning the scanner is moved over document from
the top towards the bottom. Its light is on, while we move it on document. It is
dragged very slowly over document. If dragging of the scanner over the document
is not proper, the conversion will not correct.
Graphics software
There are mainly two types of graphics software:
General programming package
Special−purpose application package
General programming package
A general programming package provides an extensive set of graphics
function that can be used in high level programming language such as C or
FORTRAN.
It includes basic drawing element shape like line, curves, polygon, color
of element transformation etc.
Example: − GL (Graphics Library).
Page 19 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
to graphics package.
Special−purpose package may allow use of other coordinates which suits
application.
In general several different Cartesian reference frames are used to construct
and display scene.
We can construct shape of object with separate coordinate system called
modeling coordinates or sometimes local coordinates or master
coordinates.
Once individual object shapes have been specified we can place the objects
into appropriate positions called world coordinates.
Finally the World−coordinates description of the scene is transferred to one
or more output device reference frame for display. These display
coordinates system are referred to as “Device Coordinates” or “Screen
Coordinates”.
Generally a graphic system first converts the world−coordinates position
to normalized device coordinates. In the range from 0 to 1 before final
conversion to specific device coordinates.
An initial modeling coordinates position ( Xmc,Ymc) in this illustration is
transferred to a device coordinates position (Xdc,Ydc) withthesequence
(Xmc,Ymc)→(Xwc,Ywc)→(Xnc,Ync)→(Xdc,Ydc).
Graphic Function
A general purpose graphics package provides user with Varity of function
for creating and manipulating pictures.
The basic building blocks for pictures are referred to as output primitives.
They includes character, string, and geometry entities such as point,
straight lines, curved lines, filled areas and shapes defined with arrays of
color points.
Input functions are used for control & process the various input device
such as mouse, tablet, etc.
Control operations are used to controlling and housekeeping tasks such as
Page 20 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
OUTPUT PRIMITIVES
Points and Lines
Point plotting is done by converting a single coordinate position
furnished by an application program into appropriate operations for the
output device in use.
Line drawing is done by calculating intermediate positions along the
line path between two specified end point positions.
Page 21 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 22 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Fig. Stair step effect produced when line is generated as a series of pixel
positions.
The stair step shape is noticeable in low resolution system, and we can
improve their appearance somewhat by displaying them on high resolution
system.
More effective techniques for smoothing raster lines are based on
adjusting pixel intensities along the line paths.
For raster graphics device−level algorithms discuss here, object
positions are specified directly in integer device coordinates.
Pixel position will referenced according to scan−line number and
column number which is illustrated by following figure.
6
5
4
3
2
1
0
01 2 3 4 6
Page 23 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Advantage:
1. It is a faster method than method of using direct use of line equation.
2. This method does not use multiplication theorem.
3. It allows us to detect the change in the value of x and y ,so plotting of same
point twice is not possible.
4. This method gives overflow indication when a point is repositioned.
5. It is an easy method because each step involves just two additions.
Page 24 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
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:
Step1 : Start Algorithm
Step2 : Declare x1,y1,x2,y2,dx,dy,x,y as integer variables.
Step3 : Enter value of x1,y1,x2,y2.
Step4 : Calculate dx = x2-x1
Step5 : Calculate dy = y2-y1
Step6 : If ABS (dx) > ABS (dy)
Then step = abs (dx) Else
Step7 : xinc=dx/step
yinc=dy/step assign x = x1
assign y = y1
Step8 : Set pixel (x, y)
Step9 : x = x + xinc y = y + yinc
Set pixels (Round (x), Round (y))
Step10: Repeat step 9 until x = x2
Step11: End Algorithm
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?
Page 25 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Solution
P1 (2,3) P11 (6,15)
x1=2 y1=3
x2= 6 y2=15 dx = 6 - 2 = 4
dy = 15 - 3 = 12
m =For calculating next value of x takes x = x
Page 26 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
(1)
The distance from S to the actual line in y direction s = y-yi
The distance from T to the actual line in y direction t = (yi+1)-y
Now consider the difference between these 2 distance values s - t
When (s-t) <0 ⟹ s < t The closest pixel is S When (s-t) ≥0 ⟹ s < t The closest
pixel is T This difference is
s-t = (y-yi)-[(yi+1)-y]
= 2y - 2yi
Page 27 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 28 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Example: Starting and Ending position of the line are (1, 1) and (8, 5). Find
intermediate points.
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
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.
Page 29 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
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.
DDA Algorithm can draw circle and Bresenham's Line Algorithm can
curves but are not accurate as draw circle and curves with more
Bresenham's Line Algorithm accurate than DDA Algorithm.
Page 30 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Procedure-
Given- Centre point of Circle = (X0, Y0) Radius of Circle = R
The point’s generation using Mid-Point Circle Drawing Algorithm involves the
following steps-
Step-01:
Assign the starting point coordinates (X0, Y0) as- X0 = 0
Y0 = R
Step-02:
Calculate the value of initial decision parameter P0 as- P0 = 1 – R
Step-03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point of the first octant depending on the value of decision parameter
Pk.
Follow the below two cases-
Step-04:
If the given center point (X0, Y0) is not (0, 0), then do the following and plot the
point- Xplot = Xc + X0
Yplot = Yc + Y0
Here, (Xc, Yc) denotes the current value of X and Y coordinates.
Page 31 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Step-05:
Keep repeating Step-03 and Step-04 until Xplot >= Yplot.
Step-06:
Step-05 generates all the points for one octant.
To find the points for other seven octants, follow the eight symmetry property of
circle. This is depicted by the following figure-
Problem-01:
Given the center point coordinates (0, 0) and radius as 10, generate all the
points to form a circle.
Solution-
Given-
Centre Coordinates of Circle (X0, Y0) = (0, 0) Radius of Circle = 10
Step-01:
Assign the starting point coordinates (X0, Y0) as- X0 = 0Y0 = R = 10
Step-02:
Calculate the value of initial decision parameter P0 as- P0 = 1 – RP0 = 1 – 10P0
= -9
Step-03:
As Pinitial < 0, so case-01 is satisfied. Thus,Xk+1 = Xk + 1 = 0 + 1 = 1
Page 32 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Yk+1 = Yk = 10
Pk+1 = Pk + 2 x Xk+1 + 1 = -9 + (2 x 1) + 1 = -6
Step-04:
This step is not applicable here as the given center point coordinates is (0, 0).
Step-05:
Step-03 is executed similarly until Xk+1 >= Yk+1 as follows
Algorithm Terminates
These are all points for Octant-1.
Algorithm calculates all the points of octant-1 and terminates.
Now, the points of octant-2 are obtained using the mirror effect by swapping X
and Y coordinates.
Page 33 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Now, the points for rest of the part are generated by following the signs
of other quadrants. The other points can also be generated by calculating each
octant separately.
Page 34 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Here, all the points have been generated with respect to quadrant-1-
Page 35 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 36 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
This algorithm uses the recursive method. First of all, a starting pixel called
as the seed is considered. The algorithm checks boundary pixel or adjacent pixels
are colored or not. If the adjacent pixel is already filled or colored then leave it,
otherwise fill it. The filling is done using four connected or eight connected
approaches.
Connected pixels:
After painting a pixel, the function is called for four neighboring points.
These are the pixel positions that are right, left, above and below the current pixel.
Areas filled by this method are called 4-connected. Below given is the algorithm
Algorithm for boundary fill (4-connected)
Boundary fill (x, y, fill, boundary)
Page 37 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Algorithm:
Void boundaryFill8 (int x, int y, intfill_color,intboundary_color)
{ if(getpixel(x, y) != boundary_color&& getpixel(x, y) != fill_color)
{putpixel(x, y, fill_color);
boundaryFill8(x + 1, y, fill_color, boundary_color); boundaryFill8(x, y + 1,
fill_color, boundary_color); boundaryFill8(x - 1, y, fill_color, boundary_color);
boundaryFill8(x, y - 1, fill_color, boundary_color); boundaryFill8(x - 1, y - 1,
fill_color, boundary_color); boundaryFill8(x - 1, y + 1, fill_color,
boundary_color); boundaryFill8(x + 1, y - 1, fill_color, boundary_color);
boundaryFill8(x + 1, y + 1, fill_color, boundary_color);}}
Four connected approaches is more suitable than the eight connected approaches.
Page 38 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 39 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
End.
In fill algorithm, we start from a specified interior point (x, y) and reassign
all pixel values are currently set to a given interior color with the desired color.
Using either a 4-connected or 8-connected approaches, we then step through pixel
positions until all interior points have been repainted.
Disadvantage:
Very slow algorithm
May be fail for large polygons
Initial pixel required more knowledge about surrounding pixels.
Page 40 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
UNIT - II
ATTRIBUTES OF OUTPUT PRIMITIVES
Page 41 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 42 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Round cap
Obtained by adding a filled semicircle to each butt cap. The circular
arcs are centered on the line endpoints and have a diameter equal to the line
thickness.
Projecting square cap
Extend the line and add butt caps that are positioned one- half of the
line width beyond the specified endpoints.
Page 43 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 44 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Character Attributes
The appearance of displayed character is controlled by attributes such
as font, size, color and orientation. Attributes can be set both for entire
character strings (text) and for individual characters defined as marker
symbols
Text Attributes
The choice of font or type face is set of characters with a particular
design style as courier, Helvetica, times roman, and various symbol groups.
The characters in a selected font also be displayed with styles. (solid,
dotted, double) in bold face in italics, and in outline or shadow styles. A
particular font and associated style is selected in a PHIGS program by setting
an integer code for the text font parameter tf in the function
Set Text Font (tf)
Control of text color (or intensity) is managed from an application
program with
Set Text Colour Index (tc)
Where text color parameter tc specifies an allowable color code.Text
size can be adjusted without changing the width to height ratio of characters
with
Set Character Height (SCH)
Page 45 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 46 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 47 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Basic transformation
Translation
T(tx,ty)
Translation distances Scale
S(sx,sy)
Scalefactors Rotation
- R()
Rotationangle
Translation
Translation is applied to an object by representing it along a straight
line path from one coordinate location to another adding translation distances,
tx, ty to original coordinate position (x,y) to move the point to a new position
(x’,y’) to
x’ = x + tx, y’ = y + ty
The translation distance point (tx,ty) is called translation vector or shift
vector.
Translation equation can be expressed as single matrix equation by
using column vectors to represent the coordinate position and the translation
vector as
Page 48 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 49 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Rotation Equation
Rotation Matrix R=𝑐𝑜𝑠∅ −𝑠𝑖𝑛∅
𝑠𝑖𝑛∅ 𝑐𝑜𝑠∅ P’ = R . P
Note: Positive values for the rotation angle define counterclockwise
rotations about the rotation point and negative values rotate objects in the
clockwise.
Scaling
A scaling transformation alters the size of an object. This operation can
be carried out for polygons by multiplying the coordinate values (x, y) to each
vertex by scaling factor Sx&Sy to produce the transformed coordinates (x’,
y’)
x’=x.Sx y’ =y.Sy
Scaling factor Sx scales object in x direction while Syscales in y
direction. The transformation equation
𝑥′ 𝑆𝑥 0 𝑥
in matrix form𝑦′= 0 𝑆𝑦 . 𝑦
(or)
P’ = S. P
Where S is 2 by 2 scaling matrix.
Page 50 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Turning a square (a) Into a rectangle (b) with scaling factors sx = 2 and
sy = 1
Any positive numeric values are valid for scaling factors sx and sy.
Values less than 1 reduce the size of the objects and values greater than 1
produce an enlarged object.
There are two types of Scaling. They are
Uniform scaling
Non Uniform Scaling
To get uniform scaling it is necessary to assign same value for sx
and sy. Unequal values for sx and sy result in a non-uniform scaling.
Matrix Representation and Homogeneous Coordinates
Many graphics applications involve sequences of geometric
transformations. An animation, for example, might require an object to be
translated and rotated at each increment of the motion. In order to combine
sequence of transformations we have to eliminate the matrix addition. To
achieve this we have represent matrix as 3X3 instead of 2X2 introducing an
additional dummy coordinate. Here points are specified by three numbers
instead of two. This coordinate system is called as Homogeneous coordinate
system and it allows to express transformation equation as matrix
multiplication. Cartesian coordinate position (x, y) is represented as
homogeneous coordinate triple(x, y, h)
Represent coordinates as (x, y,h)
Actual coordinates drawn will be (x/h,y/h)
For Translation
For Scaling
Page 51 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
For Rotation
Composite Transformations
A composite transformation is a sequence of transformations; one
followed by the other. We can set up a matrix for any sequence of
transformations as a composite transformation matrix by calculating the
matrix product of the individual transformations
Translation If two successive translation vectors (tx1,ty1) and (tx2,ty2) are
applied to a coordinate position P, the final transformed location P’ is calculated
as
P’ = T(tx2, ty2). {T(tx1, ty1).P}
= {T(tx2, ty2).T(tx1,ty1)}.P
Where P and P’ are represented as homogeneous-coordinate column vectors.
Which demonstrated the two successive translations are additive.
Rotations
Two successive rotations applied to point P produce the transformed position
P’ = R(θ2).{R(θ1).P} = {R(θ2).R(θ1)}.P
By multiplying the two rotation matrices, we can verify that two successive
rotation are additive
R(θ2).R(θ1) = R(θ1 + θ2)
So that the final rotated coordinates can be calculated with the composite
rotation matrix as
Page 52 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
P’ = R(θ1 + θ2).P
Scaling
Concatenating transformation matrices for two successive scaling
operations produces the following composite scaling matrix
Page 53 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Use the inverse translation of step 1 to return the object to its original
position concatenating the matrices for these three operations produces the
required scaling matix
Can also be expressed as T(xf, yf).S(sx, sy).T(-xf, -yf) = S(xf, yf, sx, sy)
Note: Transformations can be combined by matrix multiplication
Other Transformations
Reflection
Shear
Page 54 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Reflection
A reflection is a transformation that produces a mirror image of an
object. The mirror image for a two-dimensional reflection is generated
relative to an axis of reflection by We can choose an axis of reflection in the
xy plane or perpendicular to the xy plane or coordinate origin.
Reflection of an object about the x axis
Reflection the x axis is accomplished with the transformation matrix
1 0 0
0 −1 0
0 0 1
Page 55 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 56 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 57 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
X - Shear
The x shear preserves the y coordinates, but changes the x values
which cause vertical lines to tilt right or left as shown in figure
The Transformations matrix for x-shear is which transforms the coordinates
as x’ =x+ shx .y ;y’ =y
Y - Shear
The y shear preserves the x coordinates, but changes the y values which
cause horizontal lines which slope up or down The Transformations matrix
for y- shear is Which transforms the coordinates as
x’ = x
y’ = y + y shx .x
XY - Shear
The transformation matrix for xy-shear which transforms the coordinates as
x’ = x +x shx.y y’ = y +yshx
Page 58 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
x’ = x+xshx (yref y)
y’ = y
Example Shx = ½ and yref = -1
x’ = x
y’ = shy (x - xref) + y
Example
Page 59 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
UNIT - III
TWO DIMENSIONAL VIEWING
The process of selecting and viewing the picture with different views is
called windowing and a process which divides each element of the picture into
its visible and invisible portions, allowing the invisible portion to be discarded is
called clipping.
The viewing pipeline
A world coordinate area selected for display is called a window. An area
on a display device to which a window is mapped is called a view port. The
window defines what is to be viewed the view port defines where it is to be
displayed.
The mapping of a part of a world coordinate scene to device coordinate is
referred to as viewing transformation. The two dimensional viewing
transformation is referred to as window to view port transformation of windowing
transformation.
A viewing transformation using standard rectangles for the window and
viewport
Page 60 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 61 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Solving these impressions for the viewport position (xv, yv), we have
xv=xvmin+(xw-xwmin)sx
yv=yvmin+(yw-ywmin)sy .....equation 2
Where scaling factors are
Page 62 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
(Sx=Sy).
Otherwise world objects will be stretched or contracted in either the x or y
direction when displayed on output device. For normalized coordinates, object
descriptions are mapped to various display devices.
Any number of output devices can be open in particular application and
another window view port transformation can be performed for each open output
device. This mapping called the work station transformation is accomplished by
selecting a window area in normalized apace and a view port are in coordinates
of display device.
Page 63 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 64 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 65 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
All other lines cross one or more clipping boundaries. For a line segment with
end points (x1,y1) and (x2,y2) one or both end points outside clipping rectangle,
the parametric representation
x=x1+u(x2-x1),
y=y1+u( y2-y1),0<=u<=1
Could be used to determine values of u for an intersection with the clipping
boundary coordinates. If the value of u for an intersection with a rectangle
boundary edge is outside the range of 0 to 1, the line does not enter the interior of
the window at that boundary. If the value of u is within the range from 0 to 1,the
line segment does indeed cross into the clipping area. This method can be applied
to each clipping boundary edge in to determine whether any part of line segment
is to displayed.
Page 66 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 67 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
the clipping rectangle, as indicated by the 1 in the first bit position of each region
code.
A method that can be used to test lines for total clipping is to perform the
logical and operation with both region codes. If the result is not 0000,the line is
completely outside the clipping region.
Lines that cannot be identified as completely inside or completely outside
a clip window by these tests are checked for intersection with window boundaries.
Line extending from one coordinates region to another may pass through the
clip window, or they may intersect clipping boundaries without entering
window.
Cohen-Sutherland line clipping starting with bottom endpoint left, right ,
bottom and top boundaries in turn and find that this point is below the
clipping rectangle.
Starting with the bottom endpoint of the line from P1to P2, we check P1
against the left, right, and bottom boundaries in turn and find that this point
is below the clipping rectangle. We then find the intersection point P1‟
with the bottom boundary and discard the line section from P1 toP1‟.
The line now has been reduced to the section from P1‟ to P2,SinceP2, is
outside the clip window, we check this endpoint against the boundaries and
find that it is to the left of the window. Intersection point P2‟ is calculated,
but this point is above the window. So the final inter section
calculation yields P2”, and the line from P1‟ to P2” is saved. This completes
processing for this line, so we save this part and go on to the next line. Point
P3in the next line is to the left of the clipping rectangle, so we determine
the intersection P3‟, and eliminate the line section from P3to P3'.
By checking region codes for the line section from P3'to P4 we find that the
Page 68 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
remainder of the line is below the clip window and can be discarded also.
Intersection points with a clipping boundary can be calculated using the
slope- intercept form of the line equation. For a line with endpoint
coordinates (x1,y1) and (x2,y2) and the y coordinate of the intersection
point with a vertical boundary can be obtained with the calculation.
y =y1 +m (x-x1) where x value is set either to x wmin or to x wmax and slope of
line is calculated as m = (y2- y1) / (x2- x1) the intersection with a horizontal
boundary the x coordinate can be calculated as x= x1+( y- y1) / m with y set to
either to ywmin or to ywmax.
Polygon Clipping
To clip polygons, we need to modify the line-clipping procedures. A
polygon boundary processed with a line clipper may be displayed as a series of
unconnected line segments (Fig.), depending on the orientation of the polygon to
the clipping window.
Display of a polygon processed by a line clipping algorithm
Page 69 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 70 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Primed numbers are used to label the points in the output vertex list for this
window boundary.
Vertices 1 and 2 are found to be on outside of boundary. Moving along
vertex 3 which is inside, calculate the intersection and save both the intersection
point and vertex 3. Vertex 4 and 5 are determined to be inside and are saved.
Vertex 6 is outside so we find and save the intersection point. Using the five saved
points we repeat the process for next window boundary.
Output
Left Clipper Right Bottom Clipper Top Clipper
Clipper
Page 71 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
UNIT - IV
GRAPHICAL USER INTERFACES AND INTERACTIVE INPUT
METHODS
In order to be able to interact with the graphical image input methods are
required. These can be used to just change the location and orientation of the
camera, or to change specific settings of the rendering itself.
Different devices are more suitable for changing some settings then others.
In this chapter we will specify different types of these devices and discuss their
advantages.
Input methods can be classified using the following categories:
Locator
Stroke
String
Valuator
Choice
Pick
Locator
A device that allows the user to specify one co-ordinate position. Different
methods can be used, such as a mouse cursor, where a location is chosen by
clicking a button, or a cursor that is moved using different keys on the keyboard.
Touch screens can also be used as locators; the user specifies the location by
inducing force onto the desired coordinate on the screen.
Stroke
A device that allows the user to specify a set of coordinate positions. The
positions can be specified, for example, by dragging the mouse across the screen
while a mouse button is kept pressed. On release, a second coordinate can be
used to define a rectangular area using the first coordinate in addition.
Page 72 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
String
A device that allows the user to specify text input. A text input widget in
combination with the keyboard is used to input the text. Also, virtual keyboards
displayed on the screen where the characters can be picked using the mouse can
be used if keyboards are not available to the application.
Valuator
A device that allows the user to specify a scalar value. Similar to string
inputs, numeric values can be specified using the keyboard. Often, up-down-
arrows are added to increase or decrease the current value. Rotary devices, such
as wheels can also be used for specifying numerical values. Often times, it is
useful to limit the range of the numerical value depending on the value.
Choice
A device that allows the user to specify a menu option. Typical choice
devices are menus or radio buttons which provide various options the user can
choose from. For radio buttons, often only one option can be chosen at a time.
Once another option is picked, the previous one gets cleared.
Pick
A device that allows the user to specify a component of a picture. Similar
to locator devices, a coordinates specified using the mouse or other cursor input
devices and then back- projected into the scene to determine the selected 3-D
object. It is often useful to allow a certain “error tolerance” so that an object is
picked even though the user did not exactly onto the object but close enough next
to it. Also, highlighting objects within the scene can be used to traverse through a
list of objects that fulfill the proximity criterion.
INPUT FUNCTIONS
Input Modes
Specify how the program and input device should interact including
request mode, sample mode and event mode
Page 73 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Request Mode
The application program initiate data entry
Sample Mode
The application program and input devices operate independently
Event Mode
The input device initiate data input to the application program Other functions are
used to specify physical devices for the logical data classes
THREE DIMENSIONAL DISPLAY METHODS
To obtain display of a three-dimensional scene that has been modeled in
world coordinates. We must first set up a coordinate reference for the "camera".
This coordinate reference defines the position and orientation for the plane of the
camera film which is the plane we want to us to display a view of the objects in
the scene. Object descriptions are then transferred to the camera reference
coordinates and projected onto the selected display plane. We can then display
the objects in wireframe (outline) form, or we can apply lighting surface
rendering techniques to shade the visible surfaces.
Parallel Projection
In a parallel projection, parallel lines in the world-coordinate scene
projected into parallel lines on the two-dimensional display plane.
Perspective Projection
Another method for generating a view of a three-dimensional scene is to
project points to the display plane along converging paths. This causes objects
farther from the viewing position to be displayed smaller than objects of the same
size that are nearer to the viewing position. In a perspective projection, parallel
lines in a scene that are not parallel to the display plane are projected into
converging lines
Depth Cueing
A simple method for indicating depth with wireframe displays is to vary
the intensity of objects according to their distance from the viewing position. The
viewing position are displayed with the highest intensities, and lines farther away
are displayed with decreasing intensities.
Page 74 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 75 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Translation
In a three dimensional homogeneous coordinate representation, a point or
an object is translated from position P = (x,y,z) to position P’ = (x’,y’,z’) with the
matrix operation.
Page 76 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Rotation
To generate a rotation transformation for an object an axis of rotation must
be designed to rotate the object and the amount of angular rotation is also be
specified.
Positive rotation angles produce counter clockwise rotations about a
coordinate axis.
Co-ordinate Axes Rotations
The 2D z axis rotation equations are easily extended to3D.
x‟ = x cosθ– y sinθ
y‟=xsinθ+ycosθ
z‟=z (2)
Page 77 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
rotation
y‟ = ycosθ - zsinθ
z‟ = ysinθ + zcosθ ---------------(6)
= x
x‟
1 0 0 0 x
x‟
y‟ = 0 cosθ -sinθ 0 y
z‟ 0 sinθ cosθ 0 Z ------------------- (7)
1 0 0 0 1 1
P’ = Rx (θ). P-----------(8)
(or)
Rotation of an object around the x-axis is demonstrated in below.Cyclically
permuting coordinates in equation (6) give the transformation equation for a y
axis rotation.
Page 78 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 79 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 80 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Scaling
The matrix expression for the scaling transformation of a position P = (x,y,z)
relative to the coordinate origin can be written as
x‟ sx 0 0 0 x
y‟ = 0 sy 0 0 y
z‟ 0 0 sz 0 Z -------------------- (11)
1 0 0 0 1 1
(or) P’ = S.P ---------(12)
Where scaling parameters sx,sy, and sz are assigned any position values.
Explicit expressions for the coordinate transformations for scaling relative to the
originare x‟ =x.sx
Scaling an object changes the size of the object and repositions the object
relatives to the coordinate origin.
If the transformation parameters are not equal, relative dimensions in the
object are changed.
The original shape of the object is preserved with a uniform scaling (sx=
sy= sz).
Scaling with respect to a selected fixed position (x f, yf, zf) can be
represented with the following transformation sequence:
1. Translate the fixed point to the origin.
2. Scale the object relative to the coordinate origin usingEq.11.
3. Translate the fixed point back to its original position. This sequence of
transformation is shown in the below figure.
Page 81 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
The matrix representation for an arbitrary fixed point scaling can be expressed as
the concatenation of the Translate scale translate transformation are T (xf, yf,zf)
. S(sx, sy, sz ). T(-xf,- yf, -zf ) =
sx 0 0 (1-sx)xf
0 sy 0 (1-sy)yf -------------(14)
0 0 sz (1-sz)zf
0 0 0 1
Page 82 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 83 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
UNIT - V
THREE – DIMENSIONAL VIEWING
Three Dimensional Viewing
In three dimensional graphics applications,
We can view an object from any spatial position, from the front, from
above or from the back.
We could generate a view of what we could see if we were standing in the
middle of a group of objects or inside object, such as abuilding.
Viewing Pipeline:
In the view of a three dimensional scene, to take a snapshot we need to do the
following steps.
Positioning the camera at a particular point in space.
Deciding the camera orientation (i.e.,) pointing the camera and rotating it
around the line of right to set up the direction for the picture.
When snap the shutter, the scene is cropped to the size of the „window‟ of
the camera and light from the visible surfaces is projected into the camera
film.
In such a way the below figure shows the three dimensional transformation
pipeline, from modeling coordinates to final device coordinate.
Page 84 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Processing Steps
Once the scene has been modeled, world coordinates position is converted
to viewing coordinates.
The viewing coordinates system is used in graphics packages as a reference
for specifying the observer viewing position and the position of the
projection plane.
Projection operations are performed to convert the viewing coordinate
description of the scene to coordinate positions on the projection plane,
which will then be mapped to the output device.
Objects outside the viewing limits are clipped from further consideration,
and the remaining objects are processed through visible surface
identification and surface rendering procedures to produce the display
within the device view port.
Viewing Coordinates specifying the viewplane
Page 85 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 86 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
2. Perspective Projection:
Here, object positions are transformed to the view plane along lines that converge
to a point called the projection reference point.
Page 87 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
The orthographic projection that displays more than one face of an object is called
axonometric orthographic projections.
ISOMETRIC PROJECTION
The most commonly used axonometric projection is the is ometric
projection.
It can be generated by aligning the projection plane so that it intersects
each coordinate axis in which the object is defined as the same distance
from the origin.
Page 88 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
1 0 L1cosφ 0
Page 89 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Mparall = 0 1 L1sinφ 0
el
0 0 1 0
0 0 0 1
An orthographic projection is obtained when L1 = 0 (which occurs at a
projection angle α of900)
Oblique projections are generated with non zero values forL1.
Perspective Projections
To obtain perspective projection of a 3D object, we transform points along
projection lines that meet at the projection reference point.
If the projection reference point is set at position zprp along the zv axis and
the view plane is placed at zvp as in fig , we can write equations describing
coordinate positions along this perspective projection line in parametric
formas
x‟ = x - xu y‟= y - yu
z‟=z–(z–zprp)u
Page 90 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
yp= y((zprp - zvp) / (zprp – z)) = y(dp/ (zprp– z)) ------------------------- (2)
where dp = zprp – zvp is the distance of the view plane from the projection
reference point.
Using a 3D homogeneous coordinate representation we can write the
perspective projection transformation (2) in matrix formats
xh 1 0 0 0 x
yh = 0 1 0 0 y
zh 0 0 -(zvp/dp) zvp(zprp/d z -------------- (3)
p)
H 0 0 -1/dp zprp/dp 1
In this representation, the homogeneous factoris
h=(zprp-z)/dp (4)
and the projection coordinates on the view plane are calculated from eq (2)the
homogeneous coordinates as
xp = xh / h
yp= yh/h (5)
where the original z coordinate value retains in projection coordinates for depth
processing.
VISIBLE SURFACEDETECTION
A major consideration in the generation of realistic graphics displays
is identifying those parts of a scene that are visible from a chosen viewing
position.
Classification of Visible Surface Detection Algorithms
These are classified into two types based on whether they deal with object
definitions directly or with their projected images
1. Object space methods: compares objects and parts of objects to each other
within the scene definition to determine which surfaces as a whole we should
label as visible.
2. Image space methods: visibility is decided point by point at each pixel
position on the projection plane. Most Visible Surface Detection Algorithms
use image space methods.
Page 91 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Thus, in general, we can label any polygon as a back face if its normal vector has
a z component value
C<= 0
By examining parameter C for the different planes defining an object, we can
immediately identify all the blackfaces.
Page 92 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Therefore, for each pixel position (x, y) on the view plane, object depths
can be compared by comparing z values. The figure showsthree surfaces at
varying distances along the orthographic projection line from position (x,y ) in a
view plane taken as the (xv,yv) plane. Surface S1, is closest at this position, so
its surface intensity value at (x,y) is saved.
We can implement the depth-buffer algorithm in normalized coordinates, so
that z values range from 0 at the back clipping plane to Zmaxat the front clipping
plane.
Two buffer areas are required. A depth buffer is used to store depth values
for each (x, y) position as surfaces are processed, and the refresh buffer stores
the intensity values for each position.
Initially, all positions in the depth buffer are set to 0 (minimum depth), and the
refresh buffer is initialized to the background intensity.
Page 93 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
z =-Ax –By-D
C (1)
For any scan line adjacent horizontal positions across the linediffer by1,
and a vertical y value on an adjacent scan line differs by 1. If the depth of
position(x, y) has been determined to be z, then the depth z' of the next position
(x +1, y) along the scan line is obtained from Eq. (1)as
z'=-A(x+1)-By- -----------------------(2)
DC
Aor
z' =z- -----------------------(3)
Page 94 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
On each scan line, we start by calculating the depth on a left edge of the
polygon that intersects that scan line in the below fig. Depth values at each
successive position across the scan line are then calculated by Eq. (3).
Scan lines intersecting a polygon surface
We first determine the y-coordinate extents of each polygon, and process
the surface from the topmost scan line to the bottom scan line. Starting at a top
vertex, we can recursively calculate x positions down a left edge of the polygon
as x' = x - l/m, where m is the slope of theedge.
Depth values down the edge are then obtained recursively as
A/m+B
z'=z+ C---------------------(4)
If we are processing down a vertical edge, the slope is infinite and the
recursive calculations reduce to
z' =z +B/C -(5)
An alternate approach is to use a midpoint method or Bresenham-type
algorithm for determining x values on left edges for each scan line. Also the
method can be applied to curved surfaces by determining depth and intensity
values at each surface projection point.
For polygon surfaces, the depth-buffer method is very easy to implement,
and it requires no sorting of the surfaces in a scene. But it does require the
availability of a second buffer in addition to the refresh buffer.
Page 95 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
A- BUFFERMETHOD
An extension of the ideas in the depth-buffer method is the A-buffer
method. The A buffer method represents an antialiased, area-averaged,
accumulation-buffer method developed by Lucas film for implementation in
the surface-rendering system called REYES (an acronym for "Renders
Everything You Ever Saw").
A drawback of the depth-buffer method is that it can only find one visible
surface at each pixel position. The A-buffer method expands the depth buffer so
that each position in the buffer can reference a linked list of surfaces.
Thus, more than one surface intensity can be taken into consideration at
each pixel position, and object edges can be antialiased.
Each position in the A-buffer has two fields:
1) Depth field - stores a positive or negative real number
2) Intensity field - stores surface-intensity information or a pointer value.
If the depth field is positive, the number stored at that position is the depth
of a single surface overlapping the corresponding pixel area. The intensity field
then stores the RCB components of the surface color at that point and the percent
of pixel coverage, as illustrated in Fig.A
If the depth field is negative, this indicates multiple-surface contributions
to the pixel intensity. The intensity field then stores a pointer to a linked Iist of
surface data, as in Fig. B.
Page 96 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
Page 97 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
whether a position along a scan line is inside or outside of the surface. Scan lines
are processed from left to right. At the leftmost boundary of a surface, the surface
flag is turned on; and at the rightmost boundary, it is turned off.
Scan lines crossing the projection of two surfaces S1 and S2 in the view plane.
Dashed lines indicate the boundaries of hidden surfaces. The figure illustrates
the scan-line method for locating visible portions of surfaces for pixel positions
along the line.
The active list for scan line 1 contains information from the edge table for
edges AB, BC, EH, and FG.For positions along this scan line between edgesAB
and BC, only the flag for surface S1 is on.
Therefore no depth calculations are necessary, and intensity information
for surface S1, is entered from the polygon table into the refresh buffer.
Similarly, between edges EH and FG, only the flag for surface S2 is on. No
other positions along scan line 1 intersect surfaces, so the intensity values in the
other areas are set to the background intensity.
For scan lines 2 and 3 , the active edge list contains edges AD,EH, BC, and
FG. Along scan line 2 from edge AD to edge EH, only the flag for surface S1, is
on. But between edges EH and BC, the flags for both surfaces are on.
In this interval, depth calculations must be made using the plane
coefficients for the two surfaces. For this example, the depth of surface S1is
assumed to be less than that of S2, so intensities for surface S1, are loaded into
the refresh buffer until boundary BC is encountered. Then the flag for surface S1
Page 98 of 99
STUDY MATERIAL FOR B.Sc. COMPUTER SCIENCE
COMPUTER GRAPHICS & VISUALIZATION
VI - SEMESTER, ACADEMIC YEAR 2022-2023
goes off, and intensities for surface S2 are stored until edge FG is passed.
Any number of overlapping polygon surfaces can be processed with this
scan-line method. Flags for the surfaces are set to indicate whether a position is
inside or outside, and depth calculations are performed when surfaces overlap.
Page 99 of 99