Overview of Computer Graphics Concepts
Overview of Computer Graphics Concepts
Introduction
Definition:
The term of Graphics comes from Greek “graphikos” which means 'something written' e.g. autograph.
So, graphics are visual images or designs on some surface, such as a wall, canvas, screen, paper, or
stone to inform, illustrate, or entertain.
Computer Graphics is a field that is concerned with all aspects of producing pictures or images using
a computer with the help of data structure, graphics algorithm and programming. i.e.
Computer graphics = Data Structure + Graphics Algorithm + Language
Computer Graphics includes the creation; storage and manipulation of images of objects those come
from diverse fields such as physical, mathematical engineering, architectural abstract structures and
natural phenomenon.
We use different input and display devices to generate & perform the modification on the digital
images. Some such devices are keyboard, mouse, or touch sensitive panel, monitors etc.
Some considerable terminologies on the computer graphics are:
✗ Modeling: creating and representing the geometry of objects in the 3D world
✗ Rendering: generating 2D images of the 3D objects
✗ Animation: describing how objects change in time
History of Computer Graphics
The history of the computer graphics illustrates a acute development of hardware and software. The
past principals and techniques are still applicable in present and future computer graphics
technology. The evolutions of graphics can be explained under following points.
Year Major Achievements
1950 First Graphics Images were created
1951 CRT monitors on Main Frame computer were instroduced
1959 CAD was used to design cars
1961 First video game named “Space War”developed
1963 First Hidden Line and Hidden surface removal algorithms developed.
1
Compiled By: Mohan Bhandari
Differentiate between Computer Graphics and Image Processing
2
Compiled By: Mohan Bhandari
1. Computational Biology: Computational biology is a field that applies the techniques of computer
science, applied mathematics and statistics to address biological problems. The main focus lies on
developing mathematical modeling and computational simulation techniques.
2. Computational Physics: Computational physics is the study and implementation of numerical
algorithm to solve problems in physics for which a quantitative theory already exists.
3. Information of Graphics: Information graphics are visual representations of information, data or
knowledge. These graphics are used where complex information needs to be explained quickly and
clearly, such as in signs, maps, journalism, technical writing, and education.
4. Scientific Visualization: Scientific visualization focuses on the use of computer graphics to create
visual images which aid in understanding of complex, often massive numerical representation of
scientific concepts or results.
5. Graphic Design: Graphic design can refer to a number of artistic and professional disciplines
which focus on visual communication and presentation. Various tools like Coral Draw, In Design,
photo shop are used.
6. Computer-aided Design: Computer-aided design (CAD) is the use of computer technology for
the design of objects, real or virtual. CAD is also widely used to produce computer animation for
special effects in movies, advertising, technical manuals.
7. Web Design: The process of designing Web pages, Web sites, Web applications or multimedia for
the Web may utilize multiple disciplines, such as animation, communication design, corporate
identity, graphic design, interaction design, marketing, photography, search engine optimization
etc.
8. Digital Art: The impact of digital technology has transformed traditional activities such as painting
and drawing.
9. Video Games: A video game is an electronic game that involves interaction with a user interface
to generate visual feedback on a raster display device. The electronic systems used to play video
games are known as platforms. This platform creates through graphics.
10. Virtual Reality: Virtual reality (VR) is a technology which allows a user to interact with a
3
Compiled By: Mohan Bhandari
computer-simulated environment. The simulated environment can be similar to the real world, for
example, simulations for pilot or combat training, or it can differ significantly from reality, as in
VR games.
11. Computer Simulation: A computer simulation, a computer model or a computational model is a
computer program, or network of computers, that attempts to simulate an abstract model of a
particular system.
12. Education: Different computer graphics and images are used in schools and many training centers
for the better understanding the subject of interest.
13. Information Visualization: Information visualization is the study of the visual representation and
the use of graphical techniques to help people understand and analyze data
4
Compiled By: Mohan Bhandari
Chapter 2
Graphics Hardware
Input and Input Devices
• Keyboard
• Mouse
• Light Pen
• Touch panel
• Barcode Readers
• Data Gloves
Output and Output Devices
1. Hard Copy Devices
2. Display Devices
Basic Terms:
➢ Image
An image is a visual representation of something. It is a 2 dimensional light intensity function f(x,y)
where (x,y) are the spatial co-ordinate and f(x, y) is proportional to brightness or intensity or gray value
of the image at that point.
Types of Images:
- Raster Image
- Vector Image
➢ Pixel (or Pel)
Computer graphics consists pictures or images which are collection of discrete picture elements called
pixels.
➢ Frame (or Refresh) Buffer
➢ It is a large piece of memory into which the intensity values for all pixels are placed.
➢ At a minimum there is
one memory bit for each
pixel called a bit plane
which stores the internal
representation of image
called frame buffer.
Figure given above
illustrates a system with
N=3 bit planes for a total
of 8 (23) intensity levels.
The frame buffer is a
digital device and the
CRT is an analog device.
Therefore, a conversion
from a digital
representation to an analog signal must take place when information is read from the frame
Compiled By: Mohan Bhandari 1
buffer and displayed on the raster CRT
graphics device. For this we can use a
digital to analog converter (DAC). This
is converted into an analog voltage
between 0 and the maximum voltage of
the electron gun by the DAC. Each pixel
in the frame buffer must be accessed and
converted before it is visible on the
raster CRT.
Because there are three primary colors,
a simple color frame buffer is
implemented with three bit planes, one
for each primary color. Each bit plane
drives an individual color gun for each of the three primary colors used in color video. These
three primaries (red, green, and blue) are combined at the CRT to yield eight colors.
➢ Aliasing
➢ Aliasing is distortion that appear in any display system when the sampling the continuous object
to discrete integer pixel position.
➢ This is because, lines, polygon, circle etc. are continuous but a raster device is discrete.
➢ Bit Map and Pixel Map
➢ If a pixel has only two-color values (i.e. black and white), it can be encoded by a 1 bit of
information. On a black and white system with one bit per pixel, the frame buffer is called
bitmap.
➢ An image of more than two colors is called pix map.
➢ Bit Depth (Or Color Depth)
It is defined as number of bits assigned to each pixel in the image.
➢ Resolution
➢ It is defined as the ratio of width and height of output of the display device. So the number of
pixels in horizontal direction and vertical direction on the screen is called resolution.
➢ Example: For a resolution of 1024 * 768, 1024 pixels are going horizontally and 768 pixels are
going vertically.
➢ Aspect Ratio
➢ It is defined as the ratio of horizontal points to the vertical points required to produce equal
length lines in both the direction of the screen.
➢ It is given by the following formula.
𝑁𝑜 𝑜𝑓 ℎ𝑜𝑟𝑖𝑧𝑜𝑛𝑡𝑎𝑙𝑝𝑜𝑖𝑛𝑡𝑠
Aspect Ratio =
𝑁𝑜 𝑜𝑓 𝑣𝑒𝑟𝑡𝑖𝑐𝑎𝑙𝑃𝑜𝑖𝑛𝑡𝑠
➢ For example: (800 * 600) pixels in the display has the aspect ratio 800/600 = 4/3 i.e. 4:3
➢ The main difference between resolution and aspect ratio is that aspect ratio is the shape that the
picture takes while the resolution is the number of pixels in that shape.
➢ Phosphorescence
It is a process in which energy absorbed by a substance is released relatively slowly in the form of light.
➢ Persistence
- When a particular command is called by the application program, the graphics subroutine package sets
the appropriate pixels in the frame buffer. The video controller then cycles through the frame buffer,
one scan line at a time, typically 50 times per second. It will bring a value of each pixel contained in
the frame buffer and uses it to control the intensity of the CRT electron beam. So there exists a one to
one relationship between the pixel in frame buffer and that on the CRT screen.
- Frame buffer locations, and the corresponding screen position are referenced in Cartesian co-
ordinates. For most of the system, the coordinate origin is referenced at the lower left corner of the
screen, with positive X value increasing to the right and positive y value increasing from bottom to top.
However, in some PC, the coordinate origin is referenced at the upper left corner of the screen.
Two registers are used to store the coordinates of the screen pixels; x register is used to store x coordinate and
y register is used to store y-coordinate.
The raster scan generator produces the deflection signals that generates the raster scan and also controls x and
y registers. Initially, the x-axis is incremented by 1 up to xmax. Each pixel value is fetched and used to control
the intensity. After the first scan line, the x-address is set to 0 and y address is incremented by 1 and the process
continues till ymax.
Vector Display System or Random Scan
➢ In this technique, the electron beam is directed only to the part of the screen where the picture is to
be drawn rather than scanning from left to right and top to bottom as in raster scan. It is also called
vector display, stroke-writing display, or calligraphic display.
➢ Random-scan displays are designed to draw all the component lines of a picture 30 to 60 times each
second.
➢ Architecture for Random Scan System
Emissive Display
Emissive display or emitter change electrical energy into light energy. Plasma boards and light
discharging diode are cases of emissive display.
➢ Plasma Display:
Plasma Display is a emissive display common to large
TV displays beyond 30 inches or larger. They are called
plasma displays because they use small cell containing
electrically charged ionized gas.
Plasma Panel are developed by filling area between two
glass plates with a blend of gas.
Advantages:
- Wider viewing angles than of LED.
Solved Problems
1. There is a system with 24 bits per pixel and resolution of 1024 by 1024. Calculate the size of frame
buffer (in Megabytes)
8bit= 1 byte
Solution: 1024byte = 1 kilobyte
Resolution = 1024 * 1024 1024kilobyte= 1Megabyte
Total number of pixel = 1024 * 1024 = 1048576 pixels 1024Megabyte= 1 Gigabyte
Bits per pixels storage = 24 bits
Therefore, total storage required in frame buffer = 1048576 * 24
= 25165824bits
=25165824 / 8 Byte
= 25165824 / (8 * 1024) Kb
= 25165824 / (8 * 1024 * 1024) Mb
= 3 Mb
2. How Many k bytes does a frame buffer needs in a 600 x 400 pixel?
Suppose, n bits are required to store 1 pixel. Then,
the size of frame buffer = Resolution * bits per pixel
= (600 * 400) * n bits
= 240000 n bits
= 240000 n kb / (8 * 1024)
= 29.30 n k bytes.
5. What is the time required to display a pixel on the monitor of size 1024 * 768 with refresh rate of
60 Hz?
Solution:
Refresh Rate = 60Hz → 60 frames per second
Total number of pixel in one frame = 1024 * 768 = 786432 pixels.
60 frames need 1 second
1 frame need 1 / 60 second → 786432 pixels need 1/ 60 second
→ 1 pixels need 1 / (60 * 786432 ) second
→ 109 / (60 * 786432) ns
→ 21.19 ns
6. If the total intensity achievable for a pixel is 256 and the screen resolution is 640 * 480. What will
be the size of frame buffer?
Solution:
1 pixel = 256 different intensity level
Let; x be the number of bits required to represent 256 different intensity level
Then, 2X = 256
Therefore, x= 8 bits
Resolution = 640 * 480
Hence, number of bits required for the screen = 640 * 480 * 8 = 2457600 bits.
7. If a pixel is accessed from the frame buffer with an average access time of 300ns then will this
rate produce an un-flickering effect for the screen size of 640 * 480.
Solution:
Size of screen = 640 * 480
Total Number of pixels = 640 * 480 = 307200
The above equations are under the assumption that lines are to be processed from left endpoints
(xk, yk) to right endpoints (xk+1, yk+1).
➢ Advantage of DDA
a. It is simple to understand.
b. It is faster method than direct use of line equation y=mx+c.
(Removes multiplication operation and only involve increments operation of x or y
direction)
c. It requires no special skills for implementation
➢ Disadvantages of DDA
a. A floating point addition is still needed in determining each successive point which is time
consuming.
b. The accumulation of round off error in successive addition of the floating-point
increments may cause the calculated pixel position to drift away from the true line path
for long line segment.
➢ The other possible combinations can be as:
Q. Digitized the line with end points (3,7) and (8,3) using DDA.
Given Starting Point :(x1, y1)= (3,7) and Ending Point: (x2,y2) = (8,3)
Now Slope m=(y2-y1)/(x2-x1)= (3-7)/(8-3) =(-4/5) = -0.8
Since |m|<1, From DDA algorithm we have
Xk+1 = Xk + 1
Yk+1 = Yk + m
Q. Consider a line from (0,0) to (5,5). Using simple DDA algorithm, rasterize this line.
Solution:
Given Starting Point :(x1, y1)= (0,0) and Ending Point: (x2,y2) = (5,5)
Compiled by: Mohan Bhandari 4
Now Slope m=(y2-y1)/(x2-x1)= (5-0)/(5-0) =(/55) = 1
Since |m|<=1, From DDA algorithm we have
Xk+1 = Xk + 1
Yk+1 = Yk + m
X Y X-Plot Y-Plot (X,Y)
0 0 0 0 (0,0)
1 1 1 1 (1,2)
2 2 2 2 (2,2)
3 3 3 3 (3,3)
4 4 4 4 (4,4)
5 5 5 5 (5,5)
Pixel position along the line path are determined by sampling at unit x intervals. Starting from left
end point, we step to each successive column and plot the pixel
closest to line path.
Assume that (xk,yk) is pixel at kth step then next point to plot may
be either (𝑥𝑘 + 1, 𝑦𝑘 ) or (𝑥𝑘 + 1, 𝑦𝑘 + 1)
A decision parameter pk for the kth step in the line algorithm can be obtained by substituting 𝑚 =
𝛥𝑦
𝛥𝑥
in above eqn and defining
𝑝𝑘 = 𝛥𝑥(𝑑1 − 𝑑2 )
𝛥𝑦
= 𝛥𝑥[2 𝛥𝑥 (𝑥𝑘 + 1) − 2𝑦𝑘 + 2𝑏 − 1]
= 2𝛥𝑦.𝑥𝑘 − 2𝛥𝑥.𝑦𝑘 + 2𝛥𝑦 + 𝛥𝑥(2𝑏 − 1)
= 2𝛥𝑦.𝑥𝑘 − 2𝛥𝑥.𝑦𝑘 + 𝑐
Where the constant 𝑐 = 2𝛥𝑦 + 𝛥𝑥(2𝑏 − 1) which is independent.
If decision parameter pk is negative i.e. d1 < d2, pixel at yk is closer to the line path than pixel at
yk+1 . In this case we plot lower pixel ( xk + 1 , yk) other wise plot upper pixel (xk+1,yk+1).
Q. If the starting point is (x0 , y0 ), then what will be the value of initial decision parameter
(P0) when |m| ≤ 1?
We have Pk = ∆x(d1 - d2)
Pk = ∆x (2m(xk +1) - 2yk + 2b -1)
Pk = ∆x (2mxk +2m + 2b - 2yk -1)
Pk = ∆x {2(mxk + b - yk )+2m -1)
The line y = mx + b must passes through the initial point (x0, y0) , (mxk+b - yk) = 0,
we have
P0 = ∆x (2m -1)
P0 = ∆x (2 ∆y/∆x - 1)
P0 = 2∆y - ∆x, which is the initial decision parameter.
Q. Digitize the line with end points (20, 10) and (30, 18) using BLA.
Solution
Here, Starting point of line = (x1, y1) = (20, 10)
Ending point of line = (x2, y2) = (30, 18)
Thus, slope of line,
m = ∆y / ∆x = y2-y1 / x2-x1 = (18-10) / (30-20) = 8/10
As the given points, it is clear that the line is moving left to right,
|m| = 0.8 ≤ 1
Thus,
The initial decision parameter (P0) = 2∆y - ∆x = 2*8 – 10 = 6
Since, for the Bresenham’s Line drawing Algorithm of slope, |m| ≤ 1, we have
If Pk >0,
P k+1 = P k + 2∆y - 2∆x, and y k+1 = y k + 1 & x k+1 = x k +1
Else If Pk<0,
P k+1 = P k + 2∆y , and y k+1 = yk & x k+1 = xk +1
Q. Apply Bresenham’s algorithm to draw a line from (-3,0) and end point is (4,4)
Solution
Starting Point (x0,y0) = (-3, 0)
Ending Point (xn, yn) = (4,4) such that scanning takes place from left to right
Slope m = (4-0)/ ( 4+3) = 4/ 5 = 0.57 i.e. |M|<1
Here:
Δx= 4 + 3 = 7
Δy= 4 - 0 = 4
2Δx = 2 * 7 = 14
2Δy = 2 * 4 = 8
Now from Bresenhams Algorithm for |M|<1, and scanning from left to right
Initial Decision Parameter: P0 = 2Δy – Δx
if(pk<0) then
Xk+1 = Xk + 1
Yk+1 = Yk
Pk+1 = Pk + 2Δy
otherwise
Xk+1 = Xk+1 and
Yk+1 = Yk+1 and
Pk+1 = Pk + 2Δy - 2Δx
K Pk (Xk+1, Yk+1)
0 1 (-2,1)
1 -5 (-1,1)
2 3 (0,2)
3 -3 (1,2)
4 5 (2,3)
5 -1 (3,3)
6 7 (4,4)
(0,0)
If P2k<0, the midpoint is inside the ellipse and the pixel on the scan line xk is closer to the ellipse boundary.
Otherwise, the midpoint is outside or on the ellipse boundary, and we select the pixel on scan line x k +1.
Case : P2 k ≤ 0
x k+1 = x k +1
Boundary-fill Algorithm:
In Boundary filling algorithm starts at a point called seed pixel inside a region and paint the interior outward
the boundary. If the boundary is specified in a single color, the fill algorithm proceeds outward pixel by
until the boundary color is reached.
Starting from (x,y), the procedure tests neighboring positions to determine whether they are of boundary
color. If not, they are painted with the fill color, and their neighbors are tested. This process continues until
all pixel up to the boundary color area have tested.
The neighboring pixels from current pixel are proceeded by two
method:
✗ 4-connected if they are adjacent horizontally and
vertically.
✗ 8- connected if they adjacent horizontally, vertically and
diagonally.
Flood-fill Algorithm:
Flood_fill Algorithm is applicable when we want to fill an area that is not defined within a single-color
boundary. If fill area is bounded with different color, we can paint that area by replacing a specified
interior color instead of searching of boundary color value. This approach is called flood fill algorithm.
We start from a specified interior pixel (x,y) and reassign all pixel values that are currently set to a given
interior color with desired fill_color.
Using either 4-connected or 8-connected region recursively starting from input position, the algorithm
fills the area by desired color.
Algorithm:
void flood_fill4(int x,int y,int fill_color,int old_color)
{
int current;
current = getpixel (x,y);
if (current == old_color)
{
putpixel (x,y,fill_color);
flood_fill4(x-1,y, fill_color, old_color);
flood_fill4(x,y-1, fill_color, old_color);
flood_fill4(x,y+1, fill_color, old_color);
flood_fill4(x+1,y, fill_color, old_color);
}
}
Transformations play an important role in computer graphics to reposition the graphics on the screen and
change their size or orientation.
a) Translation
b) Rotation
c) Scaling.
x'=x+t𝑥
y'=x+t𝑦
For Example:
Given a point P with original position (2,2). Then after performing translation operation with tx = 6 and ty
= 4, we get new transformed coordinate P’ with coordinate (8,6).
b) Rotation
A two-dimensional rotation is applied to an object by repositioning it along a circular path in the xy plane.
To generate a rotation, we specify a rotation angle ‘θ’ and the position (x r , y r ,) of the rotation point (or
pivot point) about which the object is to be rotated.
➢ + Value for ‘θ’ define counter-clockwise rotation
about a point
➢ - Value for ‘θ’ defines clockwise rotation about a point
Let (x, y) is the original point, ‘r’ the constant distance from
origin, & ‘Φ’ the original angular displacement from x-axis.
Now the point (x, y) is rotated through angle ‘θ’ in a counter
clock wise direction
we can express the transformed coordinates in terms of ‘Φ’
and ‘θ’ as
x’ = r cos( Φ + θ) = r cosΦ . cosθ - r sin Φ. sinθ ....(i)
y’ = r sin( Φ + θ) = r cosΦ . sinθ + r sinΦ . cosθ ....(ii)
We know that original coordinates of point in polar
coordinates are
x = r cos Φ
y = r sin Φ
Substituting these values in (i) and (ii), we get,
x’ = x cosθ - y sinθ
y’ = x sinθ + y cosθ
So using column vector representation for coordinate points the matrix form would be P’ = R . P
− Translate the point (xr,yr) and P(x,y) by translation vector (-xr , -yr) which translates the pivot to origin
and P(x,y) to (x-xr , y-yr).
− Now apply the rotation equations when pivot is at origin to
rotate the translated point (x-xr , y-yr) as:
𝑥1 = (𝑥 − 𝑥𝑟 )cos𝜃 − (𝑦 − 𝑦𝑟 )sin𝜃
𝑦1 = (𝑥 − 𝑥𝑟 )sinθ+(𝑦 − 𝑦𝑟 )cos𝜃
− Re- translate the rotated point (𝑥1 ,y1 ) with translation vector
(xr,yr) which is reverse translation to original translation.
Finally we get the equation after successive transformation
as
x'=x𝑟 + (𝑥 − 𝑥𝑟 )cos𝜃 − (𝑦 − 𝑦𝑟 )sin𝜃…………1
y'=y𝑟 + (𝑥 − 𝑥𝑟 )sinθ+(𝑦 − 𝑦𝑟 )cos𝜃…………2
Which are actually the equations for rotation of (x,y) from the pivot point (xr,yr)
c) 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) of each vertex by scaling factors sx and sy to produce the
transformed coordinates (x', y').
x' = x. sx and y’ = y. sy
X-direction Shear:
An X-direction shear relative to x-axis is produced with transformation matrix
equation.
Y-direction Shear:
An y-direction shear relative to y-axis is produced by following transformation
equations.
x’ = x
y’= - y
x’ = - x
y’= y
x’ = - x
y’ = -y
Example:
Here, we have multiple transformation at once, So when more than one transformations are
applied for performing a task then such transformation is called composite transformation.
So the composite transformation required for reflecting the given object about y=x axis is
Solution:
Given Point P (2, 5) and translation distance Tx= 3, and Ty= 3
We have From Translation Matrix
i.e.
Solution:
Given points A (0,0), B (3,0), and C (3,3) and D ( 0, 3) and translating value 2 (t x=ty=2)
We have From Translation Matrix
i.e.
0 2 2
A’= [ ]+ [ ]= [ ]
0 2 2
3 2 5
B’= [ ]+ [ ]= [ ]
0 2 2
3 2 5
C’= [ ]+ [ ]= [ ]
3 2 5
0 2 2
D’= [ ]+ [ ]= [ ]
3 2 5
Hence the final co-ordinate are A’ (2,2), B’(5,2), C’(5,5) and D’(2,5)
Homogeneous Co-ordinates
To perform a sequence of transformation such as translation followed by rotation and scaling, we need
to follow a sequential process −
To shorten this process, we have to use 3×3 transformation matrix instead of 2×2 transformation matrix.
To convert a 2×2 matrix to 3×3 matrix, we have to add an extra dummy coordinate. So, we can represent
the point by 3 numbers instead of 2 numbers, which is called Homogenous Coordinate system.
In this system, we can represent all the transformation equations in matrix multiplication.
Coordinates of a point are represented as three element column vectors; transformation operations are
written as 3 x 3 matrices.
For translation
With T (tx, ty) as translation matrix, inverse of this translation matrix is obtained by
representing t x, t y with -t x, -t y.
For rotation
For Shearing
Q. Derive the composite matrix for reflecting an object about any arbitrary line
y=mx+c.
Also we have,
sin2Θ + cos2Θ =1
sin2Θ = 1- cos2Θ
2
sin2Θ = 1 - 𝑚21+1= 𝑚𝑚+1−1
2 +1
1−𝑚2 2𝑚 −2𝑐𝑚
1 0 0 𝑚2 +1 𝑚2 +1 𝑚2 +1
= [0 1 𝑐] 2𝑚 𝑚2 −1 𝑐−𝑐𝑚2
0 0 1 𝑚2 +1 𝑚2 +1 𝑚2 +1
[ 0 0 1 ]
1−𝑚2 2𝑚 −2𝑚𝑐
𝑚2 +1 𝑚2 +1 𝑚2 +1
= 2𝑚 𝑚2 −1 2𝑐
𝑚2 +1 𝑚2 +1 𝑚2 +1
[ 0 0 1 ]
Q. Rotate a triangle A(0,0) , B(2,2) , C(4,2) about the origin by the angle of 45 degree.
Solution:
The given triangle ABC can be represented by a matrix, formed from the homogeneous coordinates
of the vertices.
Also, we have
Q. Rotate the triangle (5, 5), (7, 3), (3, 3) about fixed point (5, 4) in counter clockwise
(CCW) by 90 degree.
Solution
The required steps are:
1. Translate the fixed point to origin.
P’ = Com * P
Hence, the new required coordinate points are (4, 4), (6, 6) & (6, 2).
5. Reverse translate the line to original position by adding the y-intercept with one
Com = T’ Rθ’RxRθT
P’ = Com * P
Hence, the final coordinates are (2, 3), (2, 5) & (4, 5)
where m= 1, c=1.
Q. Rotate triangle ABC by 450 clockwise about origin and scale it by (2,3) about
origin.
Here,
1. Rotate by 45 clockwise
com = S(2,3).R-45
A’ = com * A
B’ = com * B
C’ = com * C
Q. Rotate the △ABC by 90° anti clockwise about ( 5,8) and scale it by (2,2) about
(10,10)
Q. A mirror is placed such that it passes through (0,10) (10,0). Find the mirror image
of an object (6,7), (7,6), (6,9).
Q. Show that Successive translations are additive
If two successive translations are applied then they are additive.
Proof:
If two successive translation vectors (tx1, ty1) and (tx2, ty2) are applied to a coordinate
position P, the final transformed location P‘ is calculated with the following composite
transformation as:
T’ = T(x2,y2) . T(x1,y1)
1 0 𝑇𝑥2 1 0 𝑇𝑥1
= [0 1 .
𝑇𝑦2] [0 1 𝑇𝑦1]
0 0 1 0 0 1
1 0 𝑇𝑥1 + 𝑇𝑥2
= [0 1 𝑇𝑦1 + 𝑇𝑦2]
0 0 1
Hence, T(tx2, tx2).T(tx1,ty1)= T(tx1+ty1, tx2+ty2) which demonstrates that two successive
translation are additive
Q. Show that Successive rotation are additive
If two successive rotations are applied, then they are additive.
Proof:
Let P be point anticlockwise rotated by angle θ1 to point P’ and again let P’ be rotated by
angle θ2 to point P’’, then the combined transformation can be calculated with the following
composite matrix as:
Compiled By: Mohan Bhandari
T = R(θ2) R(θ1)
i.e. Rθ2. R θ1 = R (θ1 + θ2), which demonstrates that two successive rotations are additive.
i.e. S (sx2,sy2) S(sx2,sy2) = S(sx1.sx2, sy1.sy2), which demonstrates that two successive
scaling are multiplicative.
Multiple Coordinate Systems in a Graphics Program
A coordinate system is a reference system used to represent the object along with its features within a
common co-ordinate framework.
In a typical graphics program, we may need to deal with a number of different coordinate systems, and a
good part of the work is the conversion of coordinates from one system to another. The list of some of the
coordinate systems are:
a) Modeling co-ordinate system
The Model Coordinate System is simply the coordinate system where the model was created. It is used
to define coordinates that are used to construct the shape of individual parts (objects) of a 2D scene
b) World co-ordinate system
A Model Coordinate System is the unique coordinate space of the model. Two distinct models, each with
their own coordinate systems can’t interact with each other. There needs to be a universal coordinate
system that allows each model to interact with each other. This universal system is called World
Coordinate System. For interaction to occur, the coordinate system of each model is transformed into the
World Coordinate System
Fig: Mapping of picture section falling under rectangular Window onto a designated rectangular view port
Procedure for to transform a window to the view port we have to perform the following steps:
Step1: The object together with its window is translated until the lower left corner of the window
is at the origin
Step2: The object and window are scaled until the window has the dimensions of the view port
Step3: Again translate to move the view port to its correct position on the screen
(Setup Window,Translate window, Scale to normalize, Scale to view port, Translate to View port)
Application
i. By changing the position of the view port, we can view objects at different positions on the
display area of an output device.
ii. By varying the size of view ports, we can change size of displayed objects.
iii. Zooming effects can be obtained by successively mapping different-sized windows on a
fixed-sized view port
iv. Panning effects (Horizontal Scrolling) are produced by moving a fixed-size window across
the various objects in a scene.
Window to View port Coordinate Transformation
A window can be specified by four world coordinates: xwmin, xwmax, ywmin and ywmax. Similarly, a view
port can be described by four device coordinates: xvmin, xvmax, yvmin and yvmax
The equations for mapping window co-ordinate to view port coordinate is given by
xv= xvmin + (xw - xwmin)Sx
yv= yvmin + (yw- ywmin)Sy
Hence,
xv= 50 + (200 -100)* 0.5 = 100
yv= 50 + (200 -100)* 0.5 = 100
Compiled By: Mohan Bhandari
The transformed view port coordinate is (100,100).
Q. Find the normalization transformation matrix for window to view port which uses the rectangle
whose lower left corner is at (2,2) and upper right corner is at (6,10) as a window and the view port
that has lower left corner at (0,0) and upper right corner at (1,1)
The composite transformation matrix for transforming the window co-ordinate to viewport coordinate is
given as
T = S(sx, Sy)T(-2, -2)
Now we know,
Sx = (1-0 )/ (6 – 2) = 0.25
Sy = (1-0 )/ (10 – 2) = 0.125
𝑆𝑥 0 0 1 0 𝑡𝑥
T=[ 0 𝑆𝑦 0] [ 0 1 𝑡𝑦]
0 0 1 0 0 1
0.25 0 0 1 0 −2
=[ 0 0.125 0] [0 1 −2]
0 0 1 0 0 1
0.25 0 −0.5
=[ 0 0.125 −0.25]
0 0 1
Clipping
The process of discarding those parts of a picture which are outside of a specified region or window is
called clipping. The procedure using which we can identify whether the portions of the graphics object is
within or outside a specified region or space is called clipping algorithm.
The region or space which is used to see the object is called window and the region on which the object
is shown is called view port.
Clipping is necessary to remove those portions
of the objects which are not necessary for
further operation’s. excludes unwanted
graphics from the screen. So there are three
cases
i. The object may be
completely outside the
viewing area defined by the window port.
ii. The object may be seen partially in the window port.
iii. The object may be seen completely in the window port
For case i and ii, clipping operation is necessary but not for case iii.
Applications of Clipping
Compiled By: Mohan Bhandari
i. Extracting part of a defined scene for viewing.
ii.Identifying visible surfaces in three-dimensional views.
Anti aliasing line segments or object boundaries.
iii.
iv.Drawing and painting operations that allow parts of a picture to be selected for copying,
moving erasing, or duplicating.
Types of Clipping
i. Point Clipping
ii. Line Clipping (straight-line segments)
iii. Area Clipping (polygons)
iv. Curve Clipping
v. Text Clipping
Point Clipping
Point clipping is the process of removing all those points that lies
outside a given region or window. Let xwmin and xwmax be the edge
of the boundaries of the clipping window parallel to Y axis and ywmin
and ywmax be the edge of the boundaries of the clipping window parallel to X axis as shown in figure below.
So any point P(x,y) of world coordinate can be saved for display if the following conditions are satisfied
Line Clipping
In line clipping, a line or part of line is clipped if it is outside the window port. All the line segment falls into
one of the following clipping cases.
a. The line is totally outside the window port so is directly clipped.
b. The line is partially clipped if a part of the line lies outside the window port.
c. The line is not clipped if all whole line lied within the window port.
So in the above figure, line FE require total clipping, CD, GH, IJ require partial clipping and
AB requires no clipping.
➢ Any point inside the clipping window has a region code 0000.
➢ Any endpoint (x, y) of a line segment, the code can be determined as follows:
- If x < xw min, first bit is 1, (Point lies to left of window(Left)) (0th bit) Otherwise 0.
- If x > xw max, second bit is 1, (Point lies to right of window(Right)) (1st bit), otherwise 0.
- If y < yw min, third bit is 1, (Point lies to below window(Bottom)) (2nd bit), otherwise 0.
- If y > yw max, fourth bit is 1, (Point lies to above window(Top)) (3rd bit), otherwise 0.
Example:
Algorithm:
a) Given a line segment with end points P1=(x1,y1) and P2(x2,y2), compute 4 bit region code
for each end point.
b) To clip a line, first we have to find out which regions its two endpoints lie in.
Case II:
Case III:
If lines cannot be identified as completely inside or outside we have to do some more
calculations.
Here we find the intersection points with a clipping boundary using the slope intercept form
of the line equation
Here, to find the visible surface, the intersection points on the boundary of window can be
determined as:
y-y1= m (x-x1)
where m = (y 2 -y 1 )/ (x 2 -x 1 )
Q. Use the Cohen –Sutherland algorithm to clip the line P1(70,20) and P2(100,10) against
a window lower left hand corner (50,10) and upper right hand corner (80,40)
Solution:
Now, For finding the intersection of P1 and P2 with the boundary of Window,
We have,
P1(x1,y1) = (70,20)
P2(x2,y2) = (100,10)
Slope m = (10-20)/(100-70) = -1/3
We have to find the intersection with right edge of window, here x=80, y=?
We have
y = y2 + m(x-x2)
= 10 +(-1/3)(80-100)
= 10 + 6.67
= 16.67
Thus the intersection point P3 = (80,16.66), So discarding the line segment that lie outside the
boundary i.e P3P2, we get new line P1P3 with co-ordinate P1(70, 20) and P3(80,16.67)
The Sutherland–Hodgeman algorithm is used for clipping polygons. A single polygon can actually be split
into multiple polygons. The algorithm clips a polygon against all edges of the clipping region in turn.
Compiled By: Mohan Bhandari
This algorithm is actually quite general — the clip region can be any convex polygon in 2D, or any convex
polyhedron in 3D.
There are four possible cases for any given edge of given polygon against clipping edge.
1. Both vertices are inside :
Only the second vertex is added to the output list
2. First vertex is outside while second one is inside :
Both the point of intersection of the edge with the clip boundary and the second vertex are added to the
output list
3. First vertex is inside while second one is outside :
Only the point of intersection of the edge with the clip boundary is added to the output list
4. Both vertices are outside :
No vertices are added to the output list
Example:
3D Graphics
3D computer graphics or three-dimensional computer graphics are
graphics that use a three-dimensional representation of geometric
data that is stored in the computer for the purposes of performing
calculations and rendering 2D images.
2D is "flat", using the horizontal and vertical (X and Y) dimensions, the image has only two dimensions. 3D adds
the depth (Z) dimension. This third dimension allows for rotation and visualization from multiple perspectives. It is
essentially the difference between a photo and a sculpture.
We can perform different transformation by specifying the three-dimensional transformation vector, however the 3d
Transformation is more complex than 2D transformation.
Q. What are the issue in 3D that makes it more complex than 2D?
When we model and display a three-dimensional scene, there are many more considerations we must
take into account besides just including coordinate values as 2D, some of them are:
➢ Relatively more co-ordinate points are necessary.
➢ Object boundaries can be constructed with various combinations of plane and curved surfaces.
➢ Consideration of projection (dimension change with distance) and transparency.
➢ Many considerations on visible surface detection and remove the hidden surfaces.
Pseudo-3D and true 3D
Pseudo-3D is a term used to describe either 2D graphical projections and similar techniques used to cause images or
scenes to simulate the appearance of being three-dimensional (3D) when in fact they are not.
By contrast, games using 3D computer graphics without such restrictions are said to use true 3D.
3D display method
Three-dimensional viewing coordinates must
be transformed onto two-dimensional device
coordinates to view the scene.
To obtain a 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 use to display a view of the
objects in the scene. Object descriptions are then transferred to the camera reference coordinates and projected onto
Compiled By: Mohan Bhandari
the selected display plane.
We can then apply lighting and surface-rendering techniques to shade the visible surfaces.
3D Geometric Transformation
Methods for geometric transformations and object modeling in three dimensions are extended from two-dimensional
methods by including considerations for the z coordinate. We now translate an object by specifying a three-
dimensional translation vector, which determines how much the object is to be moved in each of the three coordinate
directions.
2D transformations can be represented by 3 x 3 matrices using homogeneous coordinates, so 3D transformations can
be represented by 4 x 4 matrices, providing we use homogeneous coordinate representations of points in 2 spaces as
well. Thus instead of representing a point as (x, y, z), we represent it as (x, y, z, H), where two these quadruples
represent the same point it one is a non-zero multiple of the other the quadruple (0, 0, 0, 0) is not allowed. A standard
representation of a point (x,y, z, H) with H not zero is given by (x/H, y/H, z/H, 1). Transforming the point to this
form is called homogenizing.
1. Translation
A point is translated from position P=(x, y, z) to position P’= (x’, y’, z’) with the matrix operation as:
𝑠𝑥 0 0 (1 − 𝑠𝑥 )𝑥𝑓
0 𝑠𝑦 0 (1 − 𝑠𝑦 )𝑦𝑓
=
0 0 𝑠𝑧 (1 − 𝑠𝑧 )𝑧𝑓
[0 0 0 1 ]
3. Shearing
Shearing transformations are used to modify object shapes.
a) Z axis Shearing
This transformation alters x and y co-
ordinate values by amount that is
proportional to the z value while leaving z
co-ordinate unchanged.
x’ = x + Shx.Z
z’ = y + Shy.Z
z’ = z
b) Y-Z plane
This transformation changes the sign of the x
coordinates, leaving the y and z coordinate values
unchanged.
c) Z-X plane
This transformation changes the sign of the y
coordinates, leaving the x and z coordinate values
unchanged.
Step-2: Rotate the object so that the arbitrary axis coincides with one of the coordinate axes.
Usually the z axis is preferred
To coincide the axis of rotation to z axis we have to first perform rotation about x axis to
bring it into X-Z plane and then perform rotation about y axis to coincide it with z axis.
a) Rotation about x-axis by angle ‘k’ in clockwise direction so that the arbitrary axis
lies on X-Z-plane
Here,
Cos k = C / V
Here,
Sin α= A / W &
Cos α= C / W
RFZ =
Step 1: Translate the reflection plane to the origin of the coordinate system
Step 2: Perform appropriate rotations to make the normal vector of the reflection plane at the origin
until it coincides with the z-axis.
Step 3: After that reflect the object through the z= 0 coordinate plane.
5. Rotation
To generate a rotation transformation for
an object in 3D space, we require the
following:
➢ Angle of rotation.
➢ Pivot point
➢ Direction of rotation
➢ Axis of rotation
Cyclic permutation of the coordinate parameters x, y and z are used to get transformation equations for
rotations about the coordinates:
Taking origin as the center of rotation, when a point P(x, y, z) is rotated through an angle about any one of
the axes to get the transformed point P’(x’, y’, z’), we have the following equation for each.
a) 3D x-axis rotation (P’ = Rx(θ) . P)
x’ = x
y’ = y cosθ – z sinθ
z’ = y sinθ + z cosθ
Step-2: Align the arbitrary axis on any major co-ordinate axis (z-axis)
Hence,
Composite matrix = T’ R x ’R y ’ R Z R y R x T
Step 1: Translate the rotation plane to the origin of the coordinate system
Step 2: Perform appropriate rotations to make the normal vector of the rotation plane at the origin
Compiled By: Mohan Bhandari
until it coincides with the z-axis.
Step 3: After that rotate the object through the z= 0 coordinate plane.
3D Representation
Graphics scenes can contain many different kinds of objects like trees, flowers, clouds, rocks, water etc. These cannot
be describe with only one methods but obviously require large precisions such as polygon & quadratic surfaces,
spline surfaces, procedural methods, volume rendering, visualization techniques etc.
Representation schemes for solid objects are often divided into two broad categories:
➢ Boundary representations (B-reps): Often abbreviated as B-rep or BREP, boundary representation is
a method for representing shapes (a set of surfaces that separate the object interior from the environment)
using the limits.
A solid is represented as a collection of connected
surface elements, the boundary between solid
and non-solid.
For examples: polygon surfaces and spline
patches.
Boundary representation of models are
composed of two parts: topology and geometry
(surfaces, curves and points). The main
topological items are: faces, edges and
vertices. A face is a bounded portion of a
surface; an edge is a bounded piece of a curve
and a vertex lies at a point.
Other elements are the shell (a set of connected faces), the loop (a circuit of edges bounding a face) and
loop-edge links (also known as winged edge links or half-edges) which are used to create the edge
circuits. The edges are like the edges of a table, bounding a surface portion.
➢ Space-partitioning representations: are used to describe interior properties, by partitioning the spatial
region containing an object into a set of small, non-overlapping, contiguous solids (usually cubes).
Space-partitioning systems are often
hierarchical, meaning that a space (or a
region of space) is divided into several
regions, and then the same space-
partitioning system is recursively
applied to each of the regions thus
created. The regions can be organized
into a tree, called a space-partitioning
tree.
For example: Octree representation.
The visual realism in 3D object can be maintained by maintaining the transparency, projection, lighting & shading
effect on each portion. The representation of 3D object include following three stages:
1. Represent the objects with multiple polygons i.e. wired-frame representation.
2. Fill all the polygons either with flat filling or smooth filling.
3. Give the lightning or shading effect and the coloring effect.
Polygon Surfaces
Compiled By: Mohan Bhandari
A set of polygon surfaces are used to represent object boundary that enclose the object interior in 3D graphics. This
simplifies and speeds up the surface rendering and display of objects, since all surfaces are described with linear
equations of plane: Ax + By + Cz + D = 0. For this reason, polygon descriptions are often referred to as "standard
graphics objects."
The wire frame representations are common in design & solid modeling application because they can be displayed
quickly to of a give a general indication of the surface structure.
A. Polygon Tables
To specify a polygon surface, a set of vertex coordinates and associated attribute parameters are placed into tables
& that are used in the subsequent processing, display, error checking and manipulation of the objects in a scene.
Polygon data tables can be organized into two groups:
a) Geometric tables
Geometric data tables contain vertex coordinates and
parameters to identify the spatial orientation of the
polygon surfaces. A convenient organization for
storing geometric data is to create three lists: a vertex
table, an edge table, and a polygon table.
➢ Coordinate values for each vertex in the
object are stored in the vertex table.
➢ The edge table contains pointers back into
the vertex table to identify the vertices for
each polygon edge.
➢ The polygon table contains pointers back
into the edge table to identify the edges for
each polygon.
b) Attribute tables
Attribute information for an object includes parameters specifying the degree of transparency of
the object and its surface reflectivity and texture characteristics. The above three table also include the
polygon attribute according to their pointer information.
B. Plane Equations
Plane equation method is the method for representing polygon surface for 3D object. The information about spatial
orientation of object is described by its individual surface which is obtained by vertex coordinate values & equation
of each plane gives a description of each surface. The equation for plane surface can be expressed in the form of:
Ax + By + Cz + D = 0
Where (x,y,z) is any point on plane, & A, B, C, D are constants describing spatial properties of the plane. The
values of A, B, C, D can be obtained by solving set of 3 plane equations using coordinate values of three non-
collinear points on plane.
Let (x1,y1,z1), (x2,y2,z2) , (x3,y3,z3) are three such points on points on the plane. Then
The solution of these equations can be obtained in the determinant form using Cramer's rule as:
A cubic spline is a spline constructed of piecewise third-order polynomials which pass through a set m of control
points.
Splines are used:
➢ To design curve and surface shapes in graphics applications,
➢ To digitize drawings for computer storage
➢ To specify animation paths for the objects or image.
➢ Typical CAD applications for splines include the design of automobile bodies, aircraft and spacecraft
surfaces, and ship hulls.
Compiled By: Mohan Bhandari
A. Control points
We specify a spline curve by giving a set of coordinate positions, called control points, which indicates the general
shape of the curve These, control points are then fitted with piecewise continuous parametric polynomial functions
in one of two ways.
➢ Interpolation curve: The polynomial sections are fitted by passing the curve through each control
points. Interpolation curves are commonly used to digitize drawings or to specify animation paths.
➢ Approximation curve: The
polynomials are fitted to the
general control-point path without
necessarily passing through any
control point. Approximation
curves are primarily used as design
tools to structure object surfaces.
B. Convex hulls
The convex polygon boundary that encloses the set of control
points is called convex hull. Convex hulls provide the measure
for deviation of a curve or surface from a region bounding the
control points.
Some splines are bounded by convex hull, thus ensuring that
polynomials smoothly follow control points
C. Natural Cubic Splines
One of first spline curves to be developed for graphics
applications is a natural cubic spline. This interpolation
curve is the mathematical representation of a original
drafting spline. We formulate natural cubic spline by
requiring that 2 adjacent curve sections have same first
& 2nd parametric derivatives at their common boundary.
Thus, natural cubic splines have C-2 continuity.
Although natural cubic splines are the mathematical
model for drafting spline, they have major disadvantage.
If a position of any one control point is altered, then the
entire curve is affected. Thus, natural cubic splines allow
for no "local control", so that we cannot restructure part
of curve without specifying an entirely new set of control
points.
D. Hermite Curves
Hermite form is defined by 2 endpoints & 2 tangent vectors at
these endpoints. Hermite spline is an interpolating piece-wise
cubic polynomial with specified tangent at each control point.
Unlike natural cubic splines, Hermite splines can be adjusted
locally because each curve section is only dependent on endpoint
constraints.
F. Bezier Curve
A Bezier curve is a mathematically defined curve used in two-
dimensional graphic applications. The curve is defined by four points:
the initial position and the terminating position (which are called
"anchors") and two separate middle points (which are called "handles").
The shape of a Bezier curve can be altered by moving the handles. The
mathematical method for drawing curves was created by Pierre Bézier
in the late 1960's for the manufacturing of automobiles.
Let, P be the control points and Nseg is number of segments in a curve segment.
𝑖
i.e u = 𝑁 ; where i = 0 to Nseg i.e 0 ≤ u ≤ 1
𝑠𝑒𝑔
we have,
x(u) = ∑𝑛𝑗=0 𝑥𝑗 𝐵𝑒𝑍(𝑗,𝑛) (𝑢) where n= no. of control points.
= x0BeZ0,3(u) + x1BeZ1,3(u)+ x2BeZ2,3(u)+ x3BeZ3,3(u)
Also we have
Q(u) = P0 BeZ0,3(u) +P1 BeZ1,3(u) +P2BeZ2,3(u) +P3 BeZ3,3(u)
Calculating
3!
BeZ0,3(u) =
0!(3−0)!
u0 (1-u)3-0 = (1-u)3
3!
BeZ1,3(u) = u1 (1-u)3-1 = 3u(1-u)2
1!(3−1)!
3!
BeZ2,3(u) = 2!(3−2)!u 2 (1-u)3-2 = 3u2(1-u)
3!
BeZ3,3(u) = 3!(3−3)!u 3 (1-u)3-3 = u3
G. B-Spline
While drawing the bezier curve, each section of the curve is connected to the next section at a sample point but the
slopes of these two sections need not match at this point. This means that there can be corners at the sample points
and that we may not have a complete smooth curve. To solve this problems, we force the curve to pass through the
sample point but rather pull it to the neighborhood of the sample point. A set of blending functions which take this
approach are called B-Splines
H. Bezier Non-planar Surfaces
Like Bezier curve, Bézier surface is defined by a set of control points.
Similar to interpolation in many respects, a key difference is that the surface
does not pass through the central control points; rather, it is "stretched"
toward them as though each were an attractive force.
A two-dimensional Bézier surface can be defined as a parametric surface
where the position of a point p as a function of the parametric coordinates u,
v is given by:
3D Viewing Transformation
The basic idea of the 3D viewing transformation is similar to the 2D viewing transformation. That is, a viewing
window is defined in world space that specifies how the viewer is viewing the scene. A corresponding view port is
defined in screen space, and a mapping is defined to transform points from world space to screen space based on
these specifications. The view port portion of the transformation is the same as the 2D case.
Specification of the window, however, requires additional information and results in a more complex mapping to be
defined. Defining a viewing window in world space coordinates is exactly like it sounds; sufficient information needs
to be provided to define a rectangular window at some location and orientation. The usual viewing parameters that
are specified are:
Eye Point The position of the viewer in world space
Look Point The point that the eye is looking at
View Distance The distance that the window is from the eye
Window Size The height and width of the window in world space coordinates Up
Vector which direction represents “up” to the viewer, this parameter is
sometimes specified as an angle of rotation about the viewing axis
Projection
3D projection is any method of mapping three-dimensional points to a two-dimensional plane. In general, a
projection transforms a N-dimension points to N-1 dimensions. Ideally, an an object is projected by projecting each
of its endpoints. But an object has infinite number of points. So we cannot project all those points. What we do is
that we project only the corner points of an object on a 2D plane and we will join these projected points by a straight
line in a 2D plane.
➢ Similarly,
𝑧
prp −𝑧vp dp
𝑦𝑝 =y( 𝑧−𝑧 )=y(𝑧 )
prp prp −𝑧
Where dp=zprp − 𝑧vp is the distance of the view plane from projection reference point.
Clipping in 3D
Clipping in three dimensions can be accomplished using extensions of two-dimensional clipping methods. Instead
of clipping against straight-line window boundaries, we now clip objects against the boundary planes of the view
volume. (The view volume defines the three-dimensional volume in space that, once projected, is to fit within the
view port. There are two parts to the view volume: the view plane
rectangle and the near and far clipping planes)
An algorithm for three-dimensional clipping identifies and saves
all surface segments within the view volume for display on the
output device. All parts of objects that are outside the view volume
are discarded. View-volume clipping boundaries are planes whose
orientations depend on the type of projection, the projection
window, and the position of the projection reference point.
To clip a polygon surface, we can clip the individual polygon
edges. To clip a line segment against the view volume, we would
need to test the relative position of the line using the view volume's
boundary plane equations. An endpoint (x, y, z) of a line segment
is
Compiled By: Mohan Bhandari
➢ Outside a boundary plane: Ax + By + Cz + D > 0,
where A, B, C, and D are the plane parameters for that boundary.
➢ Inside the boundary if Ax + By + Cz + D < 0
Lines with both endpoints outside a boundary plane are discarded, and those with both endpoints inside all boundary
planes are saved.
The intersection of a line with a boundary is found using the line equations along with the plane equation. Intersection
coordinates (x 1 , y 1 , z 1 ) are values that are on the line and that satisfy the plane equation Ax1 + By1 + Cz1 + D =
0.
To clip a polygon surface, we can clip the individual polygon edges.
As in two-dimensional viewing, the projection operations can take place before the view-volume clipping or after
clipping. All objects within the view volume map to the interior of the specified projection window. The last step is
to transform the window contents to a two-dimensional view port, which specifies the location of the display on the
output device.
Z-clipping
Z-clipping, or depth clipping, refers to techniques that selectively render certain scene objects based on their depth
relative to the screen. Most graphics toolkits allow the programmer to specify a "near" and "far" clip depth, and only
portions of objects between those two planes are displayed.
Importance of clipping in video games
➢ Maximize the game's frame rate and visual quality
➢ Speed up the rendering of the current scene
➢ Economizing the use of renderer time and memory within the hardware's capability
Thus, N = AE x AD =
Step-2: If observer at P(5, 5, 5) so we can construct the view vector V from view point A(1,0, 0) as:
V = PA = (1-5) i + (0-5) j + (0-5) k = -4i - 5j - 5k
Step-3: To find the visibility of the object, we use dot product of view vector V and normal vector N as:
V • N = (-4i - 5j – 5k) • (i + j + k) = -4-5-5 = -14< 0
This shows that the surface is visible for the observer.
Q. Find the visibility of n1 and n2 from V.
C. Scan-Line Method
This image-space method for removing hidden surfaces is an extension of the scan-line algorithm for filling
polygon interiors where, we deal with multiple surfaces rather than one. Each scan line is processed with
calculating the depth for nearest view for determining the visible surface of intersecting polygon. When
the visible surface has been determined, the intensity value for that position is entered into the refresh
buffer.
To facilitate the search for surfaces
crossing a given scan line, we can set up
an active list of edges from information in
the edge table that contain only edges
that cross the current scan line, sorted in
order of increasing x. In addition, we
define a flag for each surface that is set
on or off to indicate 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.
D. Area-Subdivision Method
The area-subdivision method takes advantage by locating those view areas that
represent part of a single surface.
Divide the total viewing area into smaller and smaller rectangles until each small
area is the projection of part of a single visible surface or no surface at all.
Continue this process until the subdivisions are easily analyzed as belonging to
a single surface or until they are reduced to the size of a single pixel. An easy
way to do this is to successively divide the area into four equal parts at each
step. There are four possible relationships that a surface can have with a
specified area boundary.
• Surrounding surface − One
that completely encloses
the area.
• Overlapping surface − One
that is partly inside and
partly outside the area.
• Inside surface − One that is
completely inside the area.
• Outside surface − One that
is completely outside the area.
The tests for determining surface visibility within an area can be stated in terms of these four
classifications. No further subdivisions of a specified area are needed if one of the following conditions is
true −
• All surfaces are outside surfaces with respect to the area.
• Only one inside, overlapping or surrounding surface is in the area.
• A surrounding surface obscures all other surfaces within the area boundaries.
E. A-Buffer Method
The A-buffer method is an extension of the depth-buffer method. The A-buffer method is a visibility
detection method developed at Lucas film Studios for the rendering system Renders Everything You Ever
Saw (REYES).
The A-buffer expands on the depth buffer method to allow transparencies. The key data structure in the
A-buffer is the accumulation
buffer.
➢ If depth >= 0, the number stored at that position is the depth of a single surface overlapping the
corresponding pixel area.
➢ If depth < 0, it indicates multiple-surface contributions to the pixel intensity. The intensity field then
stores a pointer to a linked list of surface data.
Here plane P1 partitions the space into two sets of objects, one set of objects is back and one set is in
front of partitioning plane relative to viewing direction. Since one object is intersected by plane P 1, we
divide that object into two separate objects labeled A and B. Now object A&C are in front of P1, B and D
are 4 back of P1.
We next partition the space with plane P2 and construct the binary free as fig (a). In this tree, the objects
are represented as terminal nodes, with front object as left branches and behind object as right branches.
When BSP tree is complete, we process the tree by selecting surface for displaying in order back to front.
So fore ground object is painted over back ground objects.
Illumination models:
Illumination models are used to calculate light intensities that we should see at a given point on the surface
of an object. Lighting calculations are based on the optical properties of surfaces, the background lighting
conditions and the light source specifications. All light sources are considered to be point sources, specified
Compiled By: Mohan Bhandari
with a co-ordinate position and an intensity value (color).
Some illumination models are:
1. Ambient Light
Ambient light means the light that is already present in a scene, before any additional lighting is added. It
usually refers to natural light, either outdoors or coming
through windows etc. It can also mean artificial lights such as
normal room lights.
In addition, many graphics packages introduce an ambient reflection coefficient 𝐾𝑎 to modify the ambient-
light intensity 𝐼𝑎
Idiff = 𝐾𝑎 𝐼𝑎 + 𝐾𝑑 𝐼𝑙 (𝑁.𝐿)
In computer graphics, shading refers to the process of altering the color of an object/surface/polygon in the
3D scene, based on things like (but not limited to) the surface's angle to lights, its distance from lights, its
angle to the camera and material properties (e.g. bidirectional reflectance distribution function) to create a
photo realistic effect. Shading is performed during the rendering process by a program called a shader.
Rendered image of a box. This is the same image with the This is the same image
This image has no shading on edge lines removed. rendered with shading of the
its faces, but uses edge lines faces to alter the colors of the
to separate the faces. 3 faces based on their angle
to the light sources.
A shading model is used in computer graphics to simulate the effects of light shining on a surface. The
intensity that we see on a surface is dependent upon
- The surface characteristics (eg. Shining, matte, dull, and opaque or transparent).
2. Gouraud Shading
The intensity of a point P in the polygon surface along scan-line is obtained by linearly interpolating
intensities at Ia and Ib as,
𝑥 −𝑥 𝑥 −𝑥
𝐼𝑝 = 𝑥𝑝−𝑥𝑎 𝐼 𝑏 + 𝑥𝑏 −𝑥𝑝 𝐼𝑎
𝑏 𝑎 𝑏 𝑎
Disadvantages: Highlights on the surface are sometimes displayed with anomalous shape and linear
intensity interpolation can cause bright or dark intensity streak called mach-bands.
3. Phong Shading
➢ Each rendered polygon has one normal vector per vertex; shading is performed by interpolating the
vectors across the surface and computing the color for each point of interest.
➢ Interpolating the normal vectors gives a reasonable approximation to a smoothly-curved surface
while using a limited number of polygons
➢ This method greatly reduces the Mach-band problem but it requires more computational time
➢ A polygon surface is rendered with Phong shading by carrying out following calculations.
- Determine the average normal unit vectors at each polygon vertex.
- Linearly interpolate vertex normals over the
surface of polygon.
-Apply illumination model along each scan line to
calculate the pixel intensities for the surface point.
Mach bands
Mach bands are an optical illusion where a band of gradients will appear in places to be lighter or darker
than they actually are.
When looking at Mach bands, one sees a central band of a light to dark gradient surrounded on one side by
the lightest color and on the opposite side by the darkest color.
Mach bands, as well as numerous other visual and perceptual illusions, help scientists study the way the eye
and brain process visual information.
Depth Cueing
It is the process of rendering distant objects at a lower intensity than near ones, hence giving them the
appearance of depth.
Depth cuing indicates
the process in which
the lines closest to the
viewing position are
displayed with the
highest intensities,
and lines farther away
are displayed with
decreasing intensities.
Depth cueing is
applied by choosing
maximum and minimum intensity (or color) values and a range of distances over which the intensities are
to vary.
Computer Color Models
A machine language is a machine-dependent, low-level language that uses binary code to interact with a
specific computer system. A machine-dependent language works only on a specific computer system and
its components.
A Machine Independent language is one that can run on any machine. An example of this would be Java.
Machine Independent language can take the compiled code for any given machine and run it on the
machine we are attempting to run it on. A TRULY machine-independent language would produce exactly
the same output no matter which computer it was run on.
Graphics Software
Graphics software refers to a program or collection of programs that enable a person to manipulate images
or models visually on a computer.
General programming packages provides an extensive set of graphics functions that can be used
in a high-level programming language, such as C or FORTRAN. E.g. GL (Graphics Library) system
on Silicon Graphics equipment, which includes basic functions for generating picture components
(straight lines, polygons, circles, and other figures), setting colors and intensity values, selecting
views, and applying transformations
Special purpose applications packages are, in contrast designed for non programmers, so that
users can generate displays without worrying about how graphics operations work.
The interface to the graphics routines in such packages allows users to communicate with the
programs in their own terms. For example: the artist’s painting programs and various business,
medical, and Computer-Aided Design (CAD) systems.
There are many graphics software available in market; they can be categories as:
2) Photo manipulation program: It works with bit map images and is widely used to edit
digitized photographs.
3) Computer Aided Design program: CAD software is used in technical design fields to
create models of objects that will be built or manufactured. CAD software allows user to
design objects in 3 dimensions and can produce 3-D frames and solid models.
4) 3-D Modelling Programs: It is used to create visual effects. 3-D modeling program works
by creating objects like surface, solid, polygon etc.
5) Animation: Computer are used to create animation for use in various fields, including
games, and movies composing to allow game makers and film makers to add characters
and objects to scenes that did not originally contain them.
The Graphical Kernel System (GKS) was the first ISO standard for low-level computer graphics,
introduced in 1977. The main purpose of GKS is the production and manipulation of 2D pictures in a way
that does not depend on the system of graphical device used.
In GKS, pictures are constructed from a number of basic building blocks. These basic building blocks are
called as primitives. There are five types of primitives in GKS.
C) Polygon Mesh: A polygon mesh is a collection of vertices, edges and faces that defines the
shape of a polyhedral object in 3D computer graphics and solid modeling. The faces usually
consist of triangles (triangle mesh), quadrilaterals, or other simple convex polygons, since this
simplifies rendering, but may also be composed of more general concave polygons, or
polygons with holes.
D) Octree: An octree is a tree data structure in which each internal node has exactly
eight children. Octrees are most often used to partition a three-dimensional space by
recursively subdividing it
Open GL
OpenGL is a low-level graphics library specification. It makes available to the programmer a small set of
geometric primitives - points, lines, polygons, images, and bitmaps. OpenGL provides a set of commands
that allow the specification of geometric objects in two or three dimensions, using the provided primitives,
Since OpenGL drawing commands are limited to those that generate simple geometric primitives (points,
lines, and polygons), the OpenGL Utility Toolkit (GLUT) has been created to aid in the development of
more complicated three-dimensional objects such as a sphere, a torus, and even a teapot. GLUT may not
be satisfactory for full-featured OpenGL applications, but it is a useful starting point for learning OpenGL.
Rendering Pipeline
Libraries