Introduction To Computer Graphics: Unit - I

Download as pdf or txt
Download as pdf or txt
You are on page 1of 379

UNIT -I

Introduction to Computer
Graphics
Computer Graphics: Definition
• Computer Graphics is an art of drawing pictures, lines, charts etc.
on computer screen by using a programming language.
• Objects are presented as collections of discrete picture element
called PIXEL. Pixel is smallest unit of screen element in a
computer screen.
• The user can edit graphic object (pixel) with the help of keyboard,
mouse and touch sensitive panel, on the screen.
Graphic Devices= I/P Devices+ Display (O/P) Devices.
Definition Contd.....
• It involves computation, creation & manipulation of graphical
data.
• Computer Graphics acts as rendering tool for generation &
manipulation of images.
• It involves display, manipulation and storage of picture & data
related to visualization using computer.
• Uses computer to define, store, interrogate and present pictorial
output.
Representation of an Image
• In computer graphics, a graphic object is represented as a
collection of discrete picture elements, called pixels.
• Hence, a pixel is smallest addressable screen element. It is the
smallest piece of display screen which can be controlled.
• This control is achieved by setting the intensity and color of pixel,
which compose the screen.
Representation of an Image Contd..
• Each pixel represent a region, which theoretically can
contain infinite no of points.
• But in general a point is represented by the integer part
of x coordinates, and y coordinates.
• For example, P1 are represented by (4, 3), irrespective of
their exact values.
Representation of an Image Contd...
• There are special procedure which determine, which pixel will
provide best approximation to the desired picture or graphic
objects.
• The process of determining the appropriate pixels for
representing picture or graphic object is called rasterization.
• The process of representing continuous picture or graphic object
as a collection of discrete pixels is called scan conversion.
Computer Graphics vs Computer Vision

Computer Graphics Computer Vision


• Its about drawing things on the • Itimages
is concerned with
& videos
interpretation of

screen with pixels, using


• It takes and incoming an image(or series )
mathematics & physics concepts & uses it to create new image information.
to give impression of objects to • Locating & identifying faces, license plates,
human view. street signs etc. in random imagery.
• Used to analyse & pull sematic content
from images & videos of real world.
Computer Graphics vs Image Processing

Computer Graphics Image Processing


• Its about drawing things on the • It is about taking a digital input (color
screen with pixels, using or black n white photo), scanned
image etc. and using mathematics &
mathematics & physics concepts to physics concepts to extract details of
give impression of objects to object in that i/p .
human view • o/p requirements may be simple like
finding lines or detecting colors or
complex like finding faces or detecting
emotions.
Applications of Computer Graphics
• Computer Aided Design (CAD)
• Presentation Graphics
• Computer Art
• Entertainment
• Education & Training
• Visualization
• Image Processing
Applications of CG: User Interfaces
• Types of interfaces: Command Line & GUI.
• Graphical interfaces provide an attractive and easy interaction
between users and computers.
• Built in graphics provided with user interfaces use visual
control items like buttons, menus, icons, scroll bars etc.
• Hence allowing user to interact with computer by mouse click.
Applications of CG: Plotting of graphics &
chart
• Computer Graphics is most commonly used to create 2D, 3D
graphs of mathematical, physical & economic functions in form
of histograms, bars, charts and pie charts.
• Essential in fields like industry, business, government and
educational organizations.
• Plays vital role in decision making process.
Applications of CG: Office Automation &
Desktop Publishing
• Desktop publishing allows the use of graphics for creation and
dissemination of information.
• Many organizations does in-house creation & printing of
documents which contain text, tables, graphs and other form of
drawn or scanned images.
• Computer Graphics plays vital role in design of Office
Automation tools, which plays huge role in automating the day
today activities of an office of any organization.
Applications of CG: Simulation &
Animation
• Use of graphics in simulation makes mathematic models and
mechanical systems more realistic and easy to study.

• The interactive graphics supported by animation software proved


their use in production of animated movies and cartoon films.
Applications of CG: Art & Commerce
• There is lot of development in the tools provided by computer
graphics.
• Computer Graphics application in Art and commerce field allows
user to create artistic pictures which express messages and attract
attention.
• They increase the expressiveness of the object and hence are very
useful in advertising.
Applications of Computer Graphics: CAD

• Computer Aided Design (CAD) is the use of computers to aid in


the creation, modification, analysis and optimization of a design.
• Its major use is in design processes, particularly for engineering &
architectural systems.
• Its routinely used in design of buildings, automobiles, aircraft,
spacecraft, textiles etc.
• It increases the productivity of designer & improve quality of
design.
Applications of CG: Process Control
• By the use of computers, it is possible to control various
processes in industry from a remote control device.
• In such systems, process systems and process parameters are
shown on computer with graphic symbols and identifications.
• It makes easy for operator to monitor and control various
processing parameters at a time.
Applications of CG: Education & Training

• Computer graphics can be used to generate models of physical,


financial and economic systems.
• These models can be used as educational aids to impart more
interactiveness and understandability to the content.
• Models of physical systems, physiological systems, population
trend or equipment, such as colour coded diagram can help
trainees to understand the operation of system.
Applications of CG: Cartography
• Cartography is the science and art of map making. i.e. field of
study dealing with conception, production and study of maps.
• Computer graphics is also used to represent geographic maps,
weather maps, oceanographic maps, population density maps and
so on.
• It enhances the visual clarity and accurateness of all kind of maps
in cartography.
Applications of CG: Image Processing
• Computer Graphics is used to create picture and images while Image
Processing is used to apply techniques to modify or interpret existing pictures
.
• These two are combined in many applications to model and study physical
functions, to design artificial limbs and practice surgery.

• Image processing techniques are commonly used for picture enhancement to


analyse satellite photos, X-ray photography and so on.
Advantages of Computer Graphics
• High quality graphics displays of personal computer provide one
of the most natural means of communicating with a computer.
• It provides tools for providing not only concrete real world
objects, but also of abstract, synthetic objects, such as
mathematical surfaces in 3D and of data that has no inherent
geometry, such as survey results.
• It has ability to show moving pictures and thus it is possible to
produce animations with computer graphics.
Advantages of Computer Graphics Contd..

• With computer graphics, we can control the animations by


adjusting the speed, the portion of the total scene in view, the
geometric relationship of the objects to one another , the amount
of detail shown and so on.
• It provides motion dynamics tools through which user can move
and tumble object with respect to a stationary observer, or he can
make objects stationary and the viewer moving around them.
• Another tool, Update dynamics, user can change the shape,
colour or other properties of the objects being viewed.
H/W for Computer Graphics: Visual
Display Unit
• Visual Display Units (VDU), commonly known as monitors, are
the prominent output devices to show the output on screen.
• The operation of most video monitors are based on standard
CRT design.
• CRT stands for Cathode Ray Tube.
H/W for Computer Graphics: Visual
Display Unit
• A Cathode Ray Tube is a specialized vacuum tube, in which
images are produced when an electron beam strikes a
phosphorescent surface.
• It modulates, accelerates and deflects electron beams on to the
screen to create the images.
• Most desktops computers displays makes use of CRT for image
displaying purpose.
Concept of Pixel
• Pixel stands for Picture Element.
• It carries information about intensity of colour under it. e.g.
brightness level, illumination level.
• A pixel carries three basic color, Red, Blue Green. With the help
of theses three colors, 16777216 different colours can be formed,
just by controlling and manipulating their intensities.
• 2160 X 3840 : Ultra HD Meaning ??
Pixel Density
• Pixel density is the number of pixels present in square unit area.
• What is the pixel density of 1080 X 1920 HD screen ?
• Unit: pi (pixel per inch)
• Resolution of an image is the Number of Pixels in an image.
• Aspect Ratio is the relationship (ratio) between height and width
of screen. Whenever scaling of an image is done, its aspect ratio
needs to be maintained same.
Hardware for Computer Graphics
• Hardware can be categorized in form of
• Input Devices
• Output Devices
• Storage Devices
• Processing Devices
Hardware for Computer Graphics
• Mouse: It is used to navigate around digital graphics software. It is also
used to navigate around a computer, and to launch programs/applications.
• Keyboard : It is used to type instructions plus navigate from one interface to
another.
• Monitors/Screen: It displays picture or image output, that u may editing
using digital graphics software.
• RAM: It is a volatile memory, which stores data & instructions which are
needed by CPU in current state.
Hardware for Computer Graphics
• Hard Disk: It is a type of magnetic memory, which stores data and
instruction in bulk form permanently.
• Digital Camera: It is used to take pictures and videos, which later can be
used by graphics software for manipulation and editing.
• CPU: Central Processing Unit executes commands that are given to it. It
executes the instructions from graphics software and provides the output,
• Printer: It is used to produce the printout (hard copy) of outputs, produced
by CPU.
Hardware for Computer Graphics
• Scanner: It is used to produce digital copies of images from real world hard
copies of images. Later these digital copies can be manipulated using
appropriate software.
• Graphic Tablet : It is used to navigate around graphics software or to
enhance, manipulate or create digital images.
• Light Pens: It is a pen like device used to digitally write in an graphics
interface.
Hardware for Computer Graphics
• Graph Plotter: It is a graphical device to plot and produce hard copies of
graphs from some graphics software.
• Joystick : It is a pointer device which is used to navigate in an graphic
interface environment like games etc.
• SOFTWARES:
• Adobe Photoshop: (Raster Graphics): It is used to enhance and manipulate photos
and create original digital art.
• Adobe Illustrator: ( Vector Graphics): It is program used by both artists and graphic
designers to create vector images. These images are then uxed for company logos,
promotional
Software for Computer Graphics
• Adobe Photoshop: (Raster Graphics): It is used to enhance and
manipulate photos and create original digital art.
• Adobe Illustrator: ( Vector Graphics): It is program used by both
artists and graphic designers to create vector images. These images are
then used for company logos, promotional material both in print and
digital form.
• Others like Page maker, Corel Draw, Paint etc.
Vector Images Vs Raster Images

Vector Images Raster Image


• A vector graphic file is composed • A raster graphic such as .jpeg, or
of path or lines, that are either .gif is composed of pixels, is an
straight or curved array of pixels of various colours,
which together form an image.
• The data files for a vector image
• Its data file contains the
contains the points from where a information about properties of
path start and ends. pixels at various locations of image.
Conceptual Framework of Interactive
Graphics
• It consist of input and output devices, graphics systems, application program
and application model.
• A computer receives input from input devices, and output images to a display
device.
• There are three software components of conceptual framework :
• Application Model
• Application Program
• Graphic System
Conceptual Framework of Interactive
Graphics
• Application Model :
• It captures all the data and objects to be pictured on the screen. It also captures the
relationship among them.
• These relationships are stored in the database called application database, and
referred by the application programs.
• Application Programs:
• It creates application model and communicates with it to receive and store data and
information of object’s attribute.
• It also handles user input and produces views by sending series of graphic output
commands to the graphics system.
• It is also responsible for interaction handling by event handling loops.
Conceptual Framework of Interactive
Graphics
• Application Model :
• It captures all the data and objects to be pictured on
the screen. It also captures the relationship among
them.
• These relationships are stored in the database called
application database, and referred by the application
programs
Conceptual Framework of Interactive
Graphics
• Application Programs:
• It creates application model and communicates with it to
receive and store data and information of object’s attribute.
• It also handles user input and produces views by sending series
of graphic output commands to the graphics system.
• It is also responsible for interaction handling by event handling
loops.

Conceptual Framework of Interactive
Graphics
Graphics Systems:
• It accept the series of graphics output commands from application
program.
• The output command contains both a detailed geometric
description of what is to be viewed and the attributes, describing
how the objects should appear.
• The graphics system is responsible for actually producing the
picture from the detailed description and for passing the user’s
input to application program for processing.
Scan Conversion
Manoj Mishra
Scan Conversion
• The process of representing continuous graphics objects as a
collection of discrete pixels is called Scan Conversion, also called
rasterization.
• For example, line is defined by its two end points, and the line
equation, where a circle is defined by its radius, center position
and circle equation.
Scan Conversion
• It is the responsibility of graphics system or application program to
convert each primitive from its geometric definition into a set of
pixels that make up the primitive in image space. This conversion
task is generally referred as scan conversion or rasterization.

• In case of line, it can be possible that any pixel may have any floating
value like, (2.7, 9), which will not be considered by the system.
Scan Conversion
• Therefore, the process of representing these coordinates
according to system assumption . i.e (3,5) to plot the pixel comes
into the process of scan conversion.
• Points to remember:
• All the objects should be drawn with constant brightness.
• Objects should be independent of length and orientation
Scan Conversion : Points
• A Point is the fundamental element of the picture representation.
• It is a position in a plane defined as either pair or triplets of
numbers depending on whether the data is two or three
dimensional
• Thus (x1,y1) or (x1,y1,z1) would represent a point in either two or
three dimensional space.
Scan Conversion : Points
• Each pixel on graphic display doesn’t represent a mathematical
point, Instead, it means a region which theoretically can contain
infinite no of points.
• Scan converting a point involves illuminating the pixel that
contains the point.
• Example: Display coordinates P (2.25, 1.75) and Q (2.36, 1.25).
Scan Conversion : Points
Scan Conversion : Points
• In general, a point P(x,y) is represented by the integer part of x &
integer part of y, that is pixels (int(x), int(y)).
• In the given figure, P and Q will be represented by (2,1) and (3,1).
Scan Conversion LINES
• A straight line is defined by two end points & an equation. The
points are represented as (x1,y1) & (x2,y2) and the equation of
line is used to determine the x, y coordinates, that lie between the
end points.
• Using equation, y=mx+c where m= (Δy/ Δx) & c is the Y
intercept, we can find the values of y, by incrementing x from
x=x1 to x2.
• By scan converting these calculated x, y values, we represent the
line as a sequence of pixels.
Scan Conversion LINES
• Properties of Good Line Drawing Algorithm:
• Lines should appear straight. We must choose addressable points close to
it.
• Lines should terminate accurately. They should not terminate at wrong
place.
• Lines should have constant density. Line density is proportional to the
no of dots displayed divided by length of line. Dots should be equally
spaced.
• Line density should be independent of line length and angle.
Direct Use of Line Equation
• It is the simplest form of conversion. Firstly, P1 and P2 points are scanned.
P1 has (x1,y1) and P2 has (x2, y2) coordinates.
• Slope is calculated: m= (y2-y1)/(x2-x1)
• Put the value of slope in y=mx+c;
• Now put either of coordinates of P1 or P2 and find out the value of c.
• Use multiple values of X coordinates and put it in y=mx+c, and find the pair
of points lying in the line.
Direct Use of Line Equation
EXAMPLE: A line with starting point as (0, 0) and ending point (6, 18)
is given. Calculate value of intermediate points and slope of line.
DDA (Digital Differential Analyser)
Algorithm
• DDA stands for Digital Differential Analyser algorithm, for scan
conversion of lines.
• It is incremental method of scan conversion of lines. In this method,
calculation is performed at each step but by using results of previous
steps.
• The characteristic of the DDA algorithm is to take unit steps along
one coordinate and compute the corresponding values along the other
coordinate.
DDA (Digital Differential Analyser)
Algorithm
• Step 1: Get the input of two end points (X0, Y0) and (X1, Y1).
• Step 2: Calculate the difference between two end points.
• dx = X1 - X0 ; dy = Y1 - Y0
• Step 3: Based on the calculated difference in step-2, you need to
identify the number of steps to put pixel. If dx > dy, then you
need more steps in x coordinate; otherwise in y coordinate
DDA (Digital Differential Analyser)
Algorithm
Step4: if(absolute(dx) > absolute(dy))
• Steps= absolute(dx); else Steps = absolute(dy);
• Step 5: Put the pixel by successfully incrementing x and y
coordinates accordingly and complete the drawing of the line.
• for(int v=0; v < =Steps; v++)
• { x = x + Xincrement; y = y + Yincrement;
putpixel(Round(x), Round(y));
}
Algorithm (DDA (x1,y1,x2,y2))
{ dx=x2-x1; for(i=1; i<= steps; i++)
dy=y2-y1; { putpixels(xi,yi);
if(abs(dx)> abs(dy)) X1=x1+X Increment
then steps=abs(dx)
Y1= y1+ Y Increment
else: steps = abs(dy)
X Increment= Δx/steps; }
Y Increment = Δy/steps;

}
DDA Algorithm
OR
1- Read the line end points (x1, y1) and (x2, y2)
2- Δ x = | x2 – x1|
Δ y = |y2 – y1|
3. If (Δ x > Δ y ) then
length = Δ x
else
length = Δ y
DDA Algo Contd….
4- select the raster unit i.e.,
Δ X = (x2 – x1)/length
Δ Y = (y2 – y1)/length
5. x = x1 + 0.5 * sign (Δ X)
y = y1 + 0.5 * Sign (Δ Y)
6. Now plot the points
DDA Algo Contd….
i=1
while (i ≤ length)
{
plot (integer(x), integer (y))
x=x+Δx
y=y+Δy
i = i +1
}
7. STOP
Some Important point regarding DDA
Algo.
1- Either ΔX or ΔY will be one because length is either x2 – x1 or
y2 – y1. Thus the incremental value for x or y will be one.
2- Sign function makes the algorithm work in all quadrant. It
returns -1, 0, 1 depending on whether its agreement is <0, =0, >0
respectively.
3- The factor 0.5 makes it possible to round the values in the integer
function rather than truncating them.
Example 1
• Draw a line from (0,0) to (6,6) using DDA algorithm.
Solution
x1 = 0, y1 = 0
x2 = 6, y2 = 6
Now, Δx = dx = x2 – x1
=6–0=6
Δy = d y= y2 – y1
=6–0=6
Here Δx = dx = Δy = dy
Solution Contd….
Hence, steps or length = dx = 6
Now the raster unit = ΔX = Xincrement = Δ x/ steps = (6-0)/6 = 1
ΔY = Yincrement = Δ y/ steps = (6-0)/6 = 1
Hence ,
X= x1 + 0.5 sign(1) = 0 + 0.5 = 0.5
Y= y1 + 0.5 sign (1) = 0 + 0.5 = 0.5
Plot( integer (0.5), integer(0.5)) i.e, plot (1,1)
Solution Contd…
Now , X= x + Δx = 0.5 + 1 = 1.5
& Y = y + Δy = 0.5 + 1 = 1.5
Plot (integer(1.5), integer(1.5)) = plot (2,2)
Similarly we can find next plotting point.
i Plot X Y
0.5 0.5

1 (1,1) 1.5 1.5

2 (2,2) 2.5 2.5

3 (3,3) 3.5 3.5

4 (4,4) 4.5 4.5

5 (5,5) 5.5 5.5

6 (6,6) 6.5 6.5


Question?
• Consider a line from (0,0) to (4,6). Use the simple DDA
algorithm to rasterize this line.
Solution
• Δx = 4 – 0 = 4
• Δy = 6 – 0 = 6
Here , Δx < Δy
Hence, length = Δy = 6
Therefore, Δx = (x2-x1)/length
= 4/6 = 0.666 = 0.667
Δy = (y2 – y1)/6
= 6/6 = 1
Solution contd…
x = 0 + 0.5 sign(4/6) = 0.5
y = 0 + 0.5 sign (1) = 0.5
Hence plotting point is (integer(0.5), integer (0.5)) = (1,1)
Now x = x + Δx = 0.5 + 0.667 = 1.167
y = y + Δy = 0.5 + 1 = 1.5
Plot (integer(1.167), integer(1.5)) = (1,2)
Similarly we can find next plotting point as (2,3), (3,4) and (3,5)
DDA Algorithm

oAdvantages
o It is the simplest algorithm and doesn’t require special skills for
implementation.
o It is a faster method for calculating pixel position than the
direct use of equation y=mx+c.
DDA Algorithm
Disadvantage
• Floating point arithmetic in DDA algorithm is still
time consuming.
• It is orientation dependent. Hence, endpoint accuracy
is poor.
Bresenham’s Line Algorithm
• This algorithm, like DDA is used for scan converting a line.
• It is an efficient method because it involves only integer addition,
subtraction and multiplication. These operations can be
performed very rapidly so lines can be generated quickly.
• In this method, next pixel selected, is that one which has least
distance from true line
Bresenham’s Line Algorithm
• The basic principle of Bresenham’s line algorithm is to select the
optimum raster location to represent a straight line.
• To accomplish this, the algorithm always increment either x or y
by one unit, depending on the slope of line.
• The increment in the other variable is determined by examining
the distance between the actual line location and nearest pixel.
This distance is called decision variable.
Bresenham’s Line Algorithm
• In mathematical terms, decision variable is defined as
e=DA - DB ;
• If e> 0 then it implies that DB >DA; the pixel above the line is closer to
the true line.

• If e<0 then implies DA < DB, then we can say that pixel below the
line is closer to the true line.
Bresenham’s Line Algorithm
• The initial value of decision variable s set as :
e = 2Δy-Δx; where Δy= y2-y1 & Δx= x2-x1
• Then according to values of e following actions are taken
while(e>=0) {
y=y+1;
• x = x + 1; e1=e0- 2Δx + 2Δy
}
else
• x= x+1; e1= e0+2Δy (If e<0),
• In both cases, x is incremented by 1. But if e<0, y is unchanged, till it becomes
positive.
Δy = |y2 - y1|

Bresenham’s Line Algorithm


1. Read the line end points (x1,y1) and (x2,y2) such that they are not
equal.
2. Δx=|x2-x1| and Δy= |y2-y1|
3. [Initialize starting point]
x=x1; y=y1
4. e= 2* Δ y- Δ x; [Initialize value of decision variable or error.]
5. i=1 [Initialize counter]
Bresenham’s Line Algorithm
6. Plot (x,y)
7. While(e>=0)
{ y=y+1;
x = x +1;
e= e-2*Δx + 2* Δy
}
else
x=x+1; e= e+ 2*Δy
8. i=i+1
9. if(i<= Δx) then go to step 6
10. STOP
Bresenham’s Algo.
OR
Step 1: Input the two line end points and store the left end point in (X0, Y0)
Step 2: Load (X0, Y0) into the frame buffer that is plot the first point.
Step3: Calculate constants Δx, Δy, 2Δy, and obtain the starting value for the
decision variable or parameter as:
d0= 2Δy – Δx
Step 4: At each Xk along the line, starting at k = 0, perform the following test:
Bresenham’s Algo. Contd…
if dk < 0 then next point to plot is (Xk + 1, Yk)

And dk+1= dk + 2Δy


Otherwise, the next point to plot is (Xk + 1, Yk + 1 )
And dk+1= dk + 2Δy – 2Δx
Step 5: Repeat step 4, Δx time.
Step 6: Stop.
Example
• Using Bresenham’s algo. Draw a line with end points (10,5) and (15,9)
x1 = 10 x2 = 15
y1 =5 y2 =9
First plotting point = (10,5)
d0 = 2Δy –Δx
2*4–5=3>0
Second plotting point = (11,6)
d1 = d0 + 2Δy - 2Δx
3 + 8 – 10 = 1 > 0
Third plotting point = (12,7)
d2 = -1 < 0
Fourth plotting point = (13,7)
d3 = d2 + 2Δy = 7>0 .
…..
Similarly we can tabulated value as
k dk Plot

0 d0 = 3> 0 (11,6)

1 d1= 1> 0 (12,7)

2 d2 = -1<0 (13,7)

3 d3 = 7 >0 (14,8)

4 d4 = 5>0 (15,9)
Bresenham’s Line Algorithm
Scan Converting
Circle
By Manoj
Mishra
Antialiasing
• In line drawing algorithms, we have seen that all rasterized locations
do not match with the true line, and we have to select the optimum
raster locations to represent a straight line.
• This problem is severe in low resolution screens, where line appears
like a stair step. This effect is known as aliasing.
• It is dominant in lines having sharp and gentle slopes.
Antialiasing
• The aliasing effect can be reduced by adjusting the
intensities of pixels along the line.
• The process of adjusting intensities of the pixels along the
line to minimize the effect of aliasing is called antialiasing.
• The aliasing effect can be minimised by increasing the
resolution of raster display.
Antialiasing
Antialiasing
• But this improvement comes at the price of quadrupling the cost of
memory, bandwidth of memory and scan-conversion time. Thus
increasing resolution is an expensive method for reducing aliasing
effect.
• With raster system that are capable of displaying more than two
intensity levels (colour and gray scale), we can apply antialiasing
methods to modify pixel intensities. By appropriately varying the
intensities of pixels along the line or object boundaries, we can
smooth the edges to lessen the stair-step or the jagged appearance.
Antialiasing Methods: Supersampling or
Postfiltering
• Supersampling or Postfiltering is the process by which aliasing effects
in graphics are reduced by increasing the frequency of the sampling
grid and then averaging the results down.
• This process means calculating a virtual image at a higher spatial
resolution than the frame store resolution and then averaging down to
the final resolution.
• It is called Postfiltering as the filtering is carried out after sampling.
Antialiasing Methods: Supersampling or
Postfiltering
• Supersampling is basically a three stage process:
• A continuous image I(x , y) is sampled at n times the frame resolution.
This is a virtual image.
• The virtual image is then lowpass filtered.
• The filtered image is then resampled at the final frame resolution.
Antialiasing Methods: Area Sampling or
Prefiltering
• In this antialiasing method pixel intensity is determined
by calculating the area of overlap of each pixel with
objects to be displayed.
• Anti aliasing by computing overlap area is referred to as
area sampling or pre filtering.
Basic Concepts in Circle Drawing
• A circle is a symmetrical figure which has eight way symmetry.
• Any circle generating algorithm can take advantage of the circle symmetry to
plot eight points by calculating the coordinates of any one point.
• For example in given figure, if point A(a,b) is calculated using a circle
algorithm, seven more point could be found just by reflection
Polynomial Method
Polynomial Method
• The first method defines a circle with the second-order polynomial
equation as shown in fig:
• y2=r2-x2 ; where x = the x coordinate
y = the y coordinate
r = the circle radius
• With the method, each x coordinate in the sector, from 90° to 45°, is
found by stepping x from 0 to (r/sqrt(2)) & each y coordinate is found
by evaluating sqrt(r2- x2) for each value of x.
Trignometric or Polar Method
Trignometric or Polar Method
• The second method of defining a circle makes use of polar
coordinates as shown in fig: x=r cos θ y = r sin θ
• Where θ=current angle; r = circle radius ; x = x coordinate; y
= y coordinate
• By this method, θ is stepped from 0 to ∏/4 & each value of
x & y is calculated.
Midpoint circle Algo:
• To apply the mid point method, we define the equation of a circle with (0,0)
as its centre as Fcircle (x,y) = x2+y2-r2
The relative position of any point (x,y) can be determined by
checking the sign of the circle function
Fcircle (x,y) = {<0 if (x,y) is inside the circle boundary
Fcircle (x,y) = { =0 if (x,y) is on circle boundary
Fcircle (x,y) = { >0 if (x,y) is outside the circle boundary
Midpoint circle algo. Contd….
• Thus circle function is the decision parameter in the midpoint algorithm and
we can set up calculations for this function as we did in the line algorithm.
• The initial value of decision parameter can be obtained by evaluating the
circle function at the start position (x0,y0) = (0,r)
p0 = fcircle(1, r-1/2) = 1+ (r-1/2)2 –r2 = 1.25 – r
If radius r is an integer we can simply round p0 = 1-r
Midpoint circle Algo:
1- Input radius r and centre (xc,yc) and obtain the first point on the circumference of a circle centered on the origin as (x0,y0) =
(0,r) i.e.
Initialize starting point as, x = 0, y=r
2- Calculate the initial value of the decision parameter as:
P0 =1-r
3- do
{ plot(x,y)
if (p0<0)
x = x+1
y=y
p1 = p0+2x+1
}
Midpoint Circle algo Contd…
Else
{
x = x+1
y = y-1
p1= p0+2x-2y+1
}
While (x<y)
4. Determine symmetry points in the other seven octants.
5. STOP.
Example
Question: Using mid-point circle algo. plot a circle whose radius is 10 units.

Solution: given r = 10
then initial point (x.y) = (0,r) = (0,10)
X= 0, y = 10
P0 = 1-10 = -9 <0
X = 0+1 = 1
Y = y = 10
P1= -9+2*1+1 = -6 <0
Plot(1,10)
X = 1+1 = 2
Y = 10
P2 = -6+2*2+1 = -1 <0
Plot(2,10)
Solution Contd….
• P = -1+2*3+1 = 6>0
• X = 3+1 = 4
• Y = y-1 = 10-1 = 9
• Plot(4,9)
• P = 6+2*4 - 2*9+1= -3<0
• X = 4+1 = 5
• Y=9
• Plot(5,9)
Solution Contd…
• P = -3+10+1 = 8>0
• Plot(6,8)
• P = 8+12-16+1 = 5>0
• Plot(7,7) x<y
• Stop.
Question:
1. Using mid point circle algo. plot a circle whose radius is 12 unit.
2. Given a circle radius r = 5. using midpoint circle algorithm determine
position along the circle octants in the first quadrant from x = 0 to x = y.
ELLIPSE(Basic Concept)

• The general equation for an ellipse with major axis 2a and minor axis 2b,
centered at the origin is:
(x/a)2 + (x/b)2 = 1 ------------(1)
where, 2a = length of major axis
2b = length of minor axis
Eqn.(1) can be written as,
b2x2 + a2y2 – a2b2 = 0
Ellipse Contd…
• For any given value of x, let xp it will give two values of y such as,
y = ± b√1- x2/a2

And for any given value of y, let yp it will give two values of x such as,
x = ± a√1- y2/b2
Parametric equations for an ellipse
• The parametric form of the equations for the ellipse are,
x = a.cosɵ
y = b. sinɵ
Where ɵ ranges from 0 to 2∏
Now
y/x = b. sinɵ/ a.cosɵ
Or tanα = b/a tanɵ
Ellipse Contd….
From co-ordinate geometry, we get
F(x,y) = b2x2 + a2y2 – a2b2 { <0 implies (x,y) inside the ellipse
{ = 0 implies (x,y) on the ellipse
{ >0 implies (x,y) outside the ellipse
Ellipse Contd…
• An ellipse in standard position is symmetric between quadrants but unlike a
circle, it is not symmetric between the two octants of a quadrant.
• Thus we have to calculate pixel positions along the elliptical arc throughout
one quadrant, then we obtain positions in the remaining 3 quadrants by using
symmetry property .
UNIT-II

Display Technologies
Display Technologies

This includes:
 Cathode ray Tube
PLASMA
LCD
Raster Graphics
Construction of Cathode Ray Tube
• The primary components are heated metal cathode and a control
grid.
• The heat is supplied to the cathode, by passing electron through
electron gun, through the filament.
• This way, the electrons get heated up, and start getting ejected out
of cathode filament.
• This stream of negatively charged electron is accelerated towards
the phosphor screen by supplying high positive voltage.
Construction of Cathode Ray Tube Contd..
• This acceleration is produced by means of an accelerating anode.
Next component is Focussing system.
• Focussing system is used to force the electron beam to converge
to small spot on the screen. Without it, electrons will get scattered
because of their own repulsions, due to which we wont get a
sharp image.
• The focussing can be done either by means of electrostatic
means or magnetic fields.
Construction of Cathode Ray Tube Contd..

• The deflection systems of the CRT consists of two pairs of parallel


plates , referred as vertical and horizontal deflective plates.
• The voltage applied to vertical plates controls the vertical deflection,
of electron beam & voltage applied to horizontal deflection plates
control the horizontal deflection of electron .
• As the electron beam strikes the positively charged phosphorous
screen at a specific position, it emits light and enables screen to be
visible.
Operation of Cathode Ray Tube Contd..
• The operation of CRT is very simple:
• The electron gun, emits a beam of electrons (cathode rays).
• The electron beam passes through focussing and deflection plates
that direct it towards specified positions on the phosphor coated
screen.
• When the beam hits the screen, the phosphor emits a small spot
of light at each position contacted by the electron beam.
• It redraws the picture by directing the electron beam back over
same screen points quickly
Colour CRT Monitors
• A CRT monitor displays colour pictures by using a combination of
phosphors that emit different coloured light.
• It generates a range of colours by combining the emitted light from
different phosphors
• Basic techniques for produced coloured displays:
• Beam penetration technique
• Shadow mask technique
Beam Penetration Technique
• This technique is used with random-scan monitors, where the inside
of CRT screen is coated with two layers of phosphor, usually red and
green.
• The displayed colour depends upon how far the electron beam
penetrates into the phosphor layer. The outer layer is of red phosphor
and inner layer is of green phosphor
• A beam of slow electrons excites only the outer red layer.
Beam Penetration Technique Contd..
• A beam of very fast electrons penetrates through red layer and excites the
inner green layer.
• An intermediate beam speeds, combinations of red and green light are
emitted and two additional colors orange and yellow are displayed.
• The beam acceleration voltage controls the speed of the electrons and hence
the screen colour at any point on the screen
Beam Penetration Technique:
Merits & Demerits
• It is inexpensive technique to produce colour in random scan
monitors.
• It can only display four colours.
• The quality of picture produced by this technique is not as good as
compared to other techniques.
Shadow Mask Technique
• The shadow mask technique produces much wide variety of colours,
hence is more commonly used in raster scan displays including colour
TV
• In shadow mask technique, CRT has three phosphor colour dots at
each pixel position. One phosphor dot emits red light, another emits
green light and the third emit a blue light.
• It has three electron guns, one for each colour dot, and a shadow mask
grid just behind the phosphor coated screen.
Shadow Mask Technique
Shadow Mask Technique

• The shadow mask grid consists of series of holes aligned with


phosphor dot pattern. The three beams are deflected and focussed as
a group on to the shadow mask and when they pass through a hole in
the shadow mask , they excite a dot triangle.
• A dot triangle consists of three small phosphor dots of red, green and
blue colour.
• These phosphor dots are arranged in such a manner that each electron
beam can activate its corresponding colour dot, when it passes
through the shadow mask.
Shadow Mask Technique
• A dot triangle when activated appears as a small dot on the screen which has
colour of combination of three small dots in the dot triangle.
• By varying the intensity of the three electron beams we can obtain different
colours in the shadow mask CRT.
Vector Scan Display
• Vector scan display uses electron beam circuitry , which will cause
beam to go directly from a point (A) to another point (B), to draw
a line AB.
• Electron beam has two modes: ON and OFF. For a continuous
line, beam starts hitting phosphorous screen from a start point and
keep on moving linearly till end point is reached.
• Vector Scan Display is only used to draw points, line and
characters.
Vector Scan Display: Architecture &
Working
• Display Buffer Memory:
• It contains the instruction list, which will be used to draw
a line or curve.
• It contains display computer produced list or programs,
containing commands which provides information to
electron beam of where and how to hit.
Vector Scan Display: Architecture &
Working
• Display Controller:
• The command list goes to display controller, which
interprets the commands received.
• It converts the instructions into digital signals in form of
point coordinates and forward it to graphic generator.
Vector Scan Display: Architecture &
Working
• Vector Graphic Generator:
• It receives these digital coordinates and converts them into their analog
(voltage) form.
• Then it sends this information to electron beam circuitry
• Electron Beam Circuitry receives the information about WHERE AND
HOW TO STRIKE beam for how much illumination and intensity, and
uses electron gun to fire on phosphorous screen according to it.
Vector Scan Display
• In vector displays, beam is deflected from end point to end point,
hence this technique is also called random scan.
• On being hit with electron beam, phosphor screen emits light, but
it decays after few milli seconds.
• Therefore it is necessary to repeat through the display list to
refresh the phosphor at least 30 times per second, to avoid flicker,
that’s why display list buffer is also called refresh buffer
Raster Scan Display
• In Raster Scan Display, images are represented in form of 0 & 1. It writes 1
in area where picture needs to displayed & 0 where there is no illumination
required.
• It is the most common method of displaying images in CRT screen, where
horizontal and vertical deflection signals are generated to move beam all over
the screen in a pattern, as shown in figure.
• Here the beam is swept back and forth from left to right across the screen.
When beam is moved from left to right, it is ON, and when it moves right to
left, to retrace next row, (just like reading a book),it is turned OFF.
Raster Scan Display
Raster Scan Display: Working
• Refresh Buffer also known as frame buffer, is special area of memory
dedicated to graphics only.
• It stores picture design in form of stream of 0s and 1s. This memory area
holds the set of intensity values for all the screen points
• Stored intensity values are then retrieved from refresh buffer & painted on
the screen one row at a time.
Raster Scan Display: Working
• Video Controller fetches the data from refresh buffer (
containing series of 0s and 1s.).
• Each screen point is referred as pixel. At the end of each scan
line, the electron beam returns to the left side of the screen to
displaying the next scan line.
• When the beam reaches the bottom of screen, it is made OFF
and retraced back to top left to start again.
Vector Images Vs Raster Images

Vector Images Raster Image


• A vector graphic file is composed • A raster graphic such as .jpeg, or
of path or lines, that are either .gif is composed of pixels, is an
straight or curved array of pixels of various colours,
which together form an image.
• The data files for a vector image
• Its data file contains the
contains the points from where a information about properties of
path start and ends. pixels at various locations of image.
PLASMA Display
Plasma Contd…
LCD
Clipping Algorithm
Manoj Mishra
Clipping
• The procedure that identifies the portion of a picture that are either inside or
outside of a specified region of space is referred as clipping.
• The region against which an object is clipped is called clip window or
clipping window.
• It is usually in rectangular shape.
Clipping
Point Clipping
• Point clipping tells us whether the given point (X, Y) is within the given
window or not; and decides whether we will use the minimum and maximum
coordinates of the window.
• The X-coordinate of the given point is inside the window, if X lies in
between Wx1 ≤ X ≤ Wx2. Same way, Y coordinate of the given point is inside
the window, if Y lies in between Wy1 ≤ Y ≤ Wy2.
• The concept of line clipping is same as point clipping. In line clipping, we
will cut the portion of line which is outside of window and keep only the
portion that is inside the window.
Point Clipping
Line Clipping
• In computer graphics, line clipping is the process of removing lines or
portions of lines outside an area of interest. Typically, any line or part
thereof which is outside of the viewing area is removed.
• Given a set of lines and a rectangular area of interest, the task is to remove
lines which are outside the area of interest and clip the lines which are
partially inside the area.
Line Clipping
• There are three possible cases for any given line.
• Completely inside the given rectangle : Bitwise OR of region of two end
points of line is 0 (Both points are inside the rectangle)
• Completely outside the given rectangle : Both endpoints share at least one
outside region which implies that the line does not cross the visible region.
(bitwise AND of endpoints != 0).
• Partially inside the window : Both endpoints are in different regions. In this
case, the algorithm finds one of the two points that is outside the rectangular
region. The intersection of the line from outside point and rectangular
window becomes new corner point and the algorithm repeats
Cohen Sutherland Line Clipping Algorithm

• In the algorithm, first of all, it is detected whether line lies inside the
screen or it is outside the screen.
• All lines come under any one of the following categories:
• Visible
• Not Visible
• Clipping Case(Partial Visible)
Cohen Sutherland Line Clipping Algorithm

• Cohen-Sutherland algorithm divides a two-dimensional space into 9


regions and then efficiently determines the lines and portions of lines that
are inside the given rectangular area.
• First of all, the category of a line is found based on nine regions given below.
All nine regions are assigned codes
• Each code is of 4 bits. If both endpoints of the line have end bits zero, then
the line is considered to be visible.
Cohen Sutherland Line Clipping Algorithm
Cohen Sutherland Line Clipping Algorithm

• We will use 4-bits to divide the entire region. These 4 bits represent the Top,
Bottom, Right, and Left of the region as shown in the following figure:
• Here, the TOP and LEFT bit is set to 1 because it is the TOP-LEFT
corner.
Cohen Sutherland Line Clipping Algorithm
Cohen Sutherland Line Clipping Algorithm
• Step 1 − Assign a region code for each endpoints.
• Step 2 − If both endpoints have a region code 0000 then accept this
line.
• Step 3 − Else, perform the logical AND operation for both region
codes.
• Step 3.1 − If the result is not 0000, then reject the line.
• Step 3.2 − Else you need clipping.

Cohen Sutherland Line Clipping Algorithm
• Step 3.2.1 − Choose an endpoint of the line that is outside the window.
• Step 3.2.2 − Find the intersection point at the window boundary (base
on region code).
• Step 3.2.3 − Replace endpoint with the intersection point and update
the region code.
• Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially
accepted or trivially rejected.
• Step 4 − Repeat step 1 for other lines.
Assigning a binary code to a point P(x,y)
• Following procedure is used:
(1) Compute:
Bit1- T sign(y – ymax) for top ( since y > ymax)
Bit 2- B sign (ymin – y) for bottom ( since ymin > y)
Bit 3- R sign (x – xmax) for right
Bit 4 - L sign (Xmin – x) for left
(2) Sign value
+ve 1
-ve 0
Example
• Consider the windowport given by (Wxmin, Wymin, Wxmax, Wymax) = (5,
15, 5, 25). Give the binary code for the points.
P1(10,10), P2(20,10), P3(10,30) and P4(20,30).
Solution
For point P1(10,10):
x = 10, y = 10
Now we will find TBRL as,
Sign(y-ymax) = sign(10-25) = -ve → T=0
Sign(ymin – y) = sign (15 – 10) = +ve → B = 1
Sign(x – xmax) = sign (10 – 5) = +ve → R = 1
Sign ( xmin – x) sign (5 – 10) = -ve → L=0
Hence binary code for P1 is 0110.
Solution Contd…
• Similarly we can find binary code for P2, P3 and P4.
P2(20,10) x = 20, y =10
10- 25 = -ve = 0
15 – 10 = +ve = 1
20- 5 = +ve = 1
5-20 = -Ve = 0
P2(20,10) = 0110
Question?
• Using Cohen-Sutherland algorithm to clip line P1(70,20)P2(100,10) against a
clip window whose lower left corner (50,10) and upper right corner is
(80,40).
Solution
Solution Contd…
• According to Cohen-Sutherland Algo,
4-Bit binary code for P1 = 0000
4-Bit binary code for P2 = 0010
Here, Both code are not 0000
Hence we will take AND operation:
Solution Contd…
Solution Contd…
• AND operation gives 0000 i.e this is case of partial visibility,
• Now find the intersection of line P1P2 with right edge of window
• Slope of P1P2, m = (y2-y1)/(x2-x1) = (10-20)/(100-70) = -1/3
• Let intersection point be (x,y)
• Here x = 80, y ?
• P2(x2,y2) = (100,10)
• m = (y – y2)/(x-x2) = (y-10)/(80-100) = -1/3

• i.e → y = 16.66

• Hence intersection point P3 = (80,16.66)
• New line will be P1P3.
After clipping
Short cut method for finding Intersection
point
For left window edge, intersection point will be (XL,y)
y = m(XL – x1) + y1 m≠∞
For right window edge, intersection point will be (XR,y)
y = m(XR – x1) + y1 m≠∞
For top window edge, intersection point will be (x,YT)
x = x1 + 1/m(YT – y1) m≠0
For Bottom window edge, intersection point will be (x,YB)
x = x1 + 1/m(YB – y1) m≠0
Question?
• Given a clipping window A(20,20), B(60,20), C(60,40) and D(20,40). Using
Cohen-Sutherland algo find the visible portion of line segment joining the
points P(40,80), Q(120,30).
Solution (Solve yourself)?
• Region code for point P = ?
• Region Code for point Q = ?
Question?
• Let R be the rectangular window whose left-lower hand corner is at L(-3,1) and upper-right
hand corner is at R(2,6).
(i) Find the region code for the endpoints.
(ii) Find the clipping categories for the line segment
(iii) Use Cohen-Sutherland algorithm to clip the line segment
The lines are given as:
Line AB: A(-4,2), B(-1,7)
Line CD: C(-1,5), D(3,8)
Line EF: E(-2,3), F(1,2)
Line GH: G(1,-2), H(3,3)
Solution
• Clip window:
Lower left corner = (-3,1)
Right Upper Corner = (2,6)
Wxmin = -3
Wxmax = 2
Wymin = 1
Wymax = 6
Solution Contd…
(i) The region code(outcode) for point (x,y) is set to
For Top(Bit 1): sign(y-ymax)
For Bottom(Bit 2): sign(ymin – y)
For Right(Bit 3): sign(x – xmax)
For left(Bit 4): sign(xmin – x)
For Line AB:
A = (-4,2) : T = sign( 2 – 6) = -ve = 0
B = sign(1 – 2) = -ve = 0
R = sign(-4 – 2) = -ve = 0
L = sign ( -3 – (-4)) = +ve = 1
A= 0001
B = 1000
C = 0000
D = 1010
Solution
E = 0000
F = 0000
G = 0100
H = 0010
(ii) For line AB:
A = 0001
B = 1000 AND = 0000 -------- Partial Visible
For Line CD:
C = 0000
D = 1010 AND = 0000 ---------- Partial Visible
For line EF :
E = 0000
F = 0000 ----------------------- Visible
Solution Contd…
• For line GH :
G = 0100
H = 0010 AND = 0000 ------------ Partial Visible
Before clipping
Solution Contd…
(iii) The clipping Lines are AB, CD and GH:
For Line AB:
m = (7-2)/(-1+4) = 5/3
5/3 = (y – y2)/ (x – x2)
5/3 = (y – 7) / (-3 + 1) [ since x = -3
y = 11/3
Thus the resulting intersection point is I1 ( -3, 11/3)
Now we clip AI1 segment and work on I1B
Solution Contd…
• The code of I1 is 0000 and category of I1B is partial visible.
Hence B is out side the window its out code = 1000
Hence Taking intersection with top window edge:
5/3 = (y-y2)/(x – x2)
5/3 = (6-11/3)/( x + 3) { since y = 6

x = -8/5
I2(-8/5, 6) = 0000
I1I2. Visivle
Solution Contd…
For line CD:
Ymax = 6
m = (y2-y1)/(X2-x1)
(8-5)/ (3+1) = ¾
¾ = (6-5)/ (x+1)
x = 1/3
I3(1/3, 6) = 0000
Solution Contd…
Foe line GH:
G = 0100
I4(7/3, 1) = 0010
Now we will take I4H.
But segment I4H is not displayed since (0010) AND (0010) = 0010.
Here this is not = 0000.
After Clipping
Mid Point Subdivision Line Clipping
Algorithm
• It is used for clipping line where the line is divided in two parts.
• Mid points of line is obtained by dividing it in two short segments. Again
division is done, by finding midpoint. This process is continued until line of
visible and invisible category is obtained. Let (xm,ym) are midpoint then,
Mid Point Subdivision Line Clipping
Algorithm
Mid Point Subdivision Line Clipping
Algorithm
• Step1: Calculate the position of both endpoints of the line
• Step2: Perform AND operation on both of these endpoints
• Step3:
Perform AND operation on both endpoints.
If AND ≠ 0000
then the line is invisible
else
AND=0000
then the line is clipped case.(Partial Visible)
Mid Point Subdivision Line Clipping
Algorithm
• Step4: For the line to be clipped. Find midpoint
Xm=(x1+x2)/2
Ym=(y1+y2)/2
Xmis midpoint of X coordinate.
Ymis midpoint of Y coordinate.
• Step5: Check each midpoint, whether it nearest to the boundary of a window
or not.
• Step6: If the line is totally visible or totally rejected not found then repeat
step 1 to 5.
• Step7: Stop algorithm.
Example
Find the visible segment to be display in the viewport for the line from
P(60,140) to Q(220,40) in the windowport having range (Wxmin,Wxmax) =
(40,200), (Wymin, Wymax) = (20,120).
P = 1000
Q= 0010 AND = 0000 (partial visible)
Solution
Start Point End Point Mid Point Location of mid point

P(60,140) Q(220,40) M(140,90) inside

P(60,140) M(140,90) M1(100,115) inside

P(60,140) M1(100,115) M2(80,128) outside

M2(80,128) M1(100,115) M3(90,122) outside

M3(90,122) M1(100,115) M4(95, 119) Inside

M3(90,122) M4(95,119) M5(92,120) On the boundary


Example
A clipping window ABCD is specified as A(0,0), B(40,0), C(40,40) and D(0,40).
Using midpoint subdivision algorithm find the visible portion, if any of the
line segment joining the points P(-10,20) and Q(50,10).
Solution?

Solve yourself. All of you have to submit as


assignment.
Question?
• Example: Window size is (-3, 1) to (2, 6). A line AB is given having co-
ordinates of A (-4, 2) and B (-1, 7). Does this line visible. Find the visible
portion of the line using midpoint subdivision?
Question?
• Use the cohen-sutherland algorithm to clip the line P1(70,20) and P2(100,10)
against a window whose lower left corner (50,10) and upper right corner is
(80,40).
Cyrus -Beck Algorithm
• The Cyrus–Beck algorithm is a generalized line clipping algorithm. It was
designed to be more efficient than the Cohen–Sutherland algorithm, which
uses repetitive clipping and which can be used only on a rectangular clipping
area.
• Cyrus Beck is a line clipping algorithm that is made for convex polygons. It
allows line clipping for non-rectangular windows, unlike Cohen
Sutherland. It also removes the repeated clipping needed in Cohen
Sutherland.
Cyrus Beck Algorithm
• Choose a point called P0 from the two points of the line (P0P1).
• Now for each edge of the polygon, calculate the normal pointing away from
the center of the polygon, namely N1, N2, etc.
• Now for each edge choose PEi (i -> ith edge) (choose any of the vertices of
the corresponding edge, eg.: For polygon ABCD, for side AB, PEi can be
either point A or point B) and calculate

PEi - P0
P1 - P0

Cyrus Beck Algorithm Contd…


Cyrus Beck Algorithm
• Then club the ‘t’ values for which the Ni . (P1 – P0) came out to be negative
(denominator –ve) and take the largest of all of them.
• Similarly club all the ‘t’ values for which the Ni . (P1 – P0) came out to be
positive(denominator +ve) and take the smallest of all of the clubbed ‘t’
values.
• Now the two ‘t’ values obtained from this algorithm are plugged into the
parametric form of the ‘to be clipped’ line and the resulting two points
obtained are the clipped points.
Cyrus Beck Algorithm Contd…
Parametric equation is given as: P(t) = P0 + t(P1 – P0) ----------(A)
Cyrus Beck Algorithm
Cyrus Beck Algorithm
Example
Solution
• Main equation:
P(t) = P0 + t(P1 –P0) ---------------(A)
ti =
Solution Contd….
First of all we will calculate normal point on each edge:
N1 = (-1,-1)
N2 = (-1,0)
N3 = (-1,1)
N4 = (1,1)
N5 = (1,0)
N6 = (1,-1)
Solution Contd…
Now we will find Pei:
Pe1 = (3,0)
Pe2 = (1,2)
Pe3 = (1,4)
Pe4 = (3,6)
Pe5 = (5,6)
Pe6 = (5,2)
=

Solution Contd…
Calculate ti :
t1=
Solution Contd…
Here denominator < 0(-10) i.e it is entering point
Solution Contd…
Similarly we can calculate
t2
Solution Contd…
Again D<0(-8) i.e t2 is also entering point.
Solution Contd…
Similarly we get,
t3 = 0/-6 [ Entering point, D<0
t4 = 10/10 [ Leaving point, D>0
t5 = 7/8 [ Leaving point, D >0
t6 = 6/6 [ Leaving point, D>0
Entering Point Leaving Point
-4/-10, -3/-8, 0/-6 10/10, 7/8, 6/6
Solution Contd…
• Now we will take largest value from entering and smallest value from leaving.
Hence; 4/10 and 7/8
Now, at t = 4/10
P(t) = P0 + t(P1 – P0)
= (-2,1) + 4/10[(6,3) – (-2,1)]
= (-2,1) + 4/10(8,2)
= (-2,1) + (16/5, 4/5)
= (-2 +(16/5), 1 + (4/5))
= (6/5, 9/5) Entering Intersection
Solution Contd….
Now at t = 7/8,
P(t) = (-2,1) + 7/8[8,2]
= (5, 11/4) Leaving Intersection

Hence intersection points are: (6/5,9/5) and (5,11/4)


Solution Contd…
(After Clipping)
UNIT -III

Transformations
Transformation
• Transformation means changing some graphics into something else
by applying rules. All graphics systems allow the programmer to
define picture that include a variety of transformation.
• e.g. the programmer is able to magnify the picture so that it appears
clearly, reduce it, to make it visible or rotate it so that it can be seen in
different angles.
• We can have various types of transformations such as translation,
scaling up or down, rotation, shearing, etc. When a transformation
takes place on a 2D plane, it is called 2D transformation.
2 D Transformation

• There are three types of transformations :


• Translation:
• Rotation :
• Scaling
Translation
• It is a process of repositioning of an object, in a straight line path
from one co-ordinate location to another..
• We can translate a two dimensional point by adding translation
distances, tx and ty to the original coordinate position (x,y) to move
the point to a new position (x’,y’)
• x’=x+tx y’= y + ty
Translation
Translation
• The pair (tx, ty) is called the translation vector or shift vector.
The above equations can also be represented using the
column vectors.
• It is possible to represent the translation equations as a
single matrix equation by using column vectors to represent
co-ordinate positions and the translation vector:
Transformation Formula
[Transformed object matrix] = [Original object matrix] x
[Transformation matrix]

[X*] = [X] x [T] ………………….(1)


Question?
• Translate a square ABCD with the co-ordinates A(0,0),B(5,0),C(5,5) and
D(0,5) by 2-unit in x-direction and 3-unit in y-direction.
Solution
Solution Contd…
Solution contd…
Solution Contd….
Solution Contd…
Solution Contd…
Rotation
• In rotation, we rotate the object at particular angle θ (theta) from its origin. A
two dimensional rotation is applied to an object by repositioning it along a
circular path in XY plane.
• To generate a solution, we specify a rotation angle θ and the position of the
rotation point about which the objet is to be rotated.
• Let us suppose you want to rotate it at the angle θ. After rotating it to a new
location, you will get a new point P’ (X’, Y’).
Rotation
Rotation contd…
• Here r is the constant distance of the point from origin, angle Ф is
the original angular position of the point from the horizontal and θ is
the rotation angle.
• Using standard trigonometric equations we can express transformed
coordinates in terms of above angles
• x’ =rcos(Ф+ θ )=rcos Ф cos θ - rsin Ф sin θ
• y’ =rsin(Ф+ θ )=rcos Ф sin θ - rsin Ф cos θ
Rotation Contd…
for point P,
x = rcos(ф) --------------------(1)
y = rsin(ф) ----------------------(2)
For point P’,
x’ = rcos(ɵ + ф ) = rcos(ɵ)cos(ф) – rsin(ɵ)sin(ф)
= xcos(ɵ) – ysin(ɵ) [ put value of x & y from Eqn 1 & 2
y’ = rsin(ɵ+ ф) = rsin(ɵ)cos(ф) + rcos(ɵ)sin(ф)
= xsin(ɵ) + ycos(ɵ)
Rotation contd…
Rotation Contd…
Question?
• Rotate an object defined by A(0,0), B(1,0), C(1,1) and D(0,1) by 45 degree
anticlockwise about the origin.
Solution
Solution Contd….
Solution Contd….
Solution Contd…
Solve above matrix multiplication and get ,
A’ =?
B’=?
C’=?
D’=?
Rotation
• It is important to note that positive values for rotation values define counter
clockwise rotations about rotation point and negative values rotate objects in
the clockwise sense.
• EXAMPLE: A point (4,3 ) is rotated counter clockwise by an angle of 45
degree. Find the rotation matrix and the resultant point.
Main formula of transformation
[ Transformed object matrix] = [Original object matrix] x
[Transformation matrix]

[X*] = [X] x [T] ………(1)


Question?
• Translate a square ABCD with the coordinates A(0,0), B(5,0), C(5,5) and
D(0,5) by 2-units in x-direction and 3-units in y-direction.
Solution
Given:
Object = ABCD(square)
tx = 2-unit, ty = 3-unit
We know that,
[X*] = [X] x [T]
Solution Contd…
Solution Contd…..
Solution Contd…
Solution Contd….
Solution Contd…
Assignment
• Rotate an object defined by A(0,0), B(1,0), C(1,1) and D(0,1) by 45 degree
about origin.
Scaling
• A scaling transformation changes the size of an object the size of an object.
• In the scaling process, you either expand or compress the dimensions of the
object.
• Scaling can be achieved by multiplying the original coordinates of the object
with the scaling factor to get the desired result.
• Let us assume that the original coordinates are (X, Y), the scaling factors are
(SX, SY), and the produced coordinates are (X’, Y’). This can be
mathematically represented as shown below −
X' = X . SX and Y' = Y . SY
Scaling
• The scaling factor SX, SY scales the object in X and Y direction
respectively. The above equations can also be represented in matrix
form as below:
• Any positive values are valid for scaling factors for SX, SY .Values less
than 1 reduce the size of objects, and greater than 1 produce enlarged
object.
• For both SX, SY equal to 1 will have no effect on the size of object.
• For uniform scaling, it is necessary to assign same values to SX, and SY.
Unequal values for SX, SY result in a differential scaling.
Assignment
• Scale the square ABCD, 3-unit in x-direction and 3-unit in y-direction w.r.to
origin. Given:
A = (0,0)
B = (3,0)
C = (3,3)
D = (0,3)
Scaling
• EXAMPLE: Scale the polygon with
coordinates A(2,5), B(7,10) and C (10, 2) by two
units in X and two units in Y direction?
Assignment
• Rotate an object defined by A(0,0), B(4,0), C(4,4) and D(0,4),
(i) counter clockwise by Pie.
(ii) clockwise by Pie/2
Homogenous Coordinates
• The rotation of a point, straight line or an entire image on the
screen, about a point other than origin, is achieved by first moving
the image until the point of rotation occupies the origin, then
performing rotation, then finally moving the image to its original
position.
Homogenous Coordinates Contd..
• A translation may be done by adding or subtracting to each point,
the amount, by which picture is required to be shifted. Translation
of point by the change of coordinate cannot be combined with
other transformation by using simple matrix application.
Homogenous Coordinates Contd..
• Such a combination is essential if we wish to rotate an image about a
point other than origin by translation, rotation again translation. To
combine these three transformations into a single transformation,
homogeneous coordinates are used.
• In homogeneous coordinate system, two-dimensional coordinate
positions (x, y) are represented by triple-coordinates. Homogeneous
coordinates are generally used in design and construction
applications. Here we perform translations, rotations, scaling to fit the
picture into proper position.
Composite Transformation:
• A number of transformations or sequence of transformations can be
combined into single one called as composition. The resulting matrix
is called as composite matrix. The process of combining is called as
concatenation.
• Suppose we want to perform rotation about an arbitrary point, then we
can perform it by the sequence of three transformations
• Translation
• Rotation
• Reverse Translation
Composite Transformation Contd..
• The ordering sequence of these numbers of transformations must not be
changed.
• If a matrix is represented in column form, then the composite
transformation is performed by multiplying matrix in order from right to left
side.
• The output obtained from the previous matrix is multiplied with the new
coming matrix.
Reflection
• It is a transformation which produces a mirror image of an object. The mirror
image can be either about x-axis or y-axis. The object is rotated by180°.
• Types of Reflection:
• Reflection about the x-axis
• Reflection about the y-axis
• Reflection about line y=x
• Reflection about an axis perpendicular to xy plane and passing through the origin
• Reflection about line y=-x
Shearing
• It is transformation which changes the shape of object. The sliding of layers
of object occur. The shear can be in one direction or in two directions.
• Shearing in the X-direction: In this horizontal shearing sliding of layers
occur. The homogeneous matrix for shearing in the x-direction is shown
below:
Shearing
Shearing
• Shearing in the Y-direction: Here shearing is done by sliding along vertical
or y-axis

• Shearing in X-Y directions: Here layers will be slided in both x as well as y


direction. The sliding will be in horizontal as well as vertical direction. The
shape of the object will be distorted. The matrix of shear in both directions
is given by:
Windowing & Viewport
• The process of selecting & viewing the picture with different views is
called windowing. The process which divides element of the picture
into its visible and invisible portions, allowing invisible portion to be
discarded is called clipping.
• A picture is stored in computer memory using any convenient
Cartesian coordinate system, reffered as world coordinate
system.(WCS). But when a picture is to be displayed on a display
device, it is measured in physical device coordinate system (PDCS).
Windowing & Viewport
• Hence displaying an image of a picture involves mapping of the
coordinates of the points and lines that form the picture into
appropriate physical coordinate where the image is to be displayed .
• This mapping is achieved with the use of coordinate transformation
known as viewing transformation.
• It is also known as window to view or windowing transformation.
Window
• The method of selecting and enlarging a portion of a drawing is
called windowing. The area chosen for this display is called a window.
The window is selected by world-coordinate.
• Sometimes we are interested in some portion of the object and not in
full object. So we will decide on an imaginary box. This box will
enclose desired or interested area of the object. Such an imaginary
box is called a window.
Viewing transformation in several steps:
Viewing transformation in several steps:

• First, we construct the scene in world coordinate using the output


primitives and attributes.
• To obtain a particular orientation, we can set up a 2-D viewing
coordinate system in the window coordinate plane and define a
window in viewing coordinates system.
• Once the viewing frame is established, are then transform description
in world coordinates to viewing coordinates.
Viewing transformation in several steps:

• Once the viewing frame is established, are then transform description


in world coordinates to viewing coordinates.
• Then, we define viewport in normalized coordinates (range from 0 to
1) and map the viewing coordinates description of the scene to
normalized coordinates.
• At the final step, all parts of the picture that (i.e., outside the viewport
are dipped, and the contents are transferred to device coordinates).
Window :Definition
• A world-coordinate area selected for display is called a window.
• In computer graphics, a window is a graphical control element.
• It consists of a visual area containing some of the graphical user
interface of the program it belongs to and is framed by a window
decoration.
• A window defines a rectangular area in world coordinates. You can
define the window to be larger than, the same size as, or smaller than
the actual range of data values, depending on whether you want to
show all of the data or only part of the data.
Viewport: Definition
• An area on a display device to which a window is mapped is called a
viewport.
• A viewport is a polygon viewing region in computer graphics. The viewport
is an area expressed in rendering-device-specific coordinates, e.g. pixels for
screen coordinates, in which the objects of interest are going to be rendered.
• A viewport defines in normalized coordinates a rectangular area on the
display device where the image of the data appears. You define a viewport
with the GPORT command. You can have your graph take up the entire
display device or show it in only a portion, say the upper-right part.
Window to Viewport Transformation:
• Window-to-Viewport transformation is the process of transforming a two-
dimensional, world-coordinate scene to device coordinates.
• In particular, objects inside the world or clipping window are mapped to the
viewport. The viewport is displayed in the interface window on the screen.
• In other words, the clipping window is used to select the part of the scene
that is to be displayed. The viewport then positions the scene on the output
device.
Window to Viewport Transformation:
Workstation Transformation
 The object together with its window is translated until
the lower left corner of the window is at the origin.
 Object and window are scaled until the window has
dimension of the viewport.
 Translate the viewport to its correct position on the
screen.
Assignment
• Clip the line P0(-2,2)P1(8,4) against a polygon ABC.
Given: A= (5,4)
B = (3,0) and
C = (6,0)
UNIT-IV

Curve & Surfaces


Comparison between Spline, B-
Spline and Bezier curve
Spline B-Spline Bezier

1- A Spline curve can be 1- B-Spline curves are 1- Bezier curves can be


specified by giving a specified by Bernstein specified with boundary
specified set of basis function that has conditions with a a
coordinate positions limited flexibility charecterizing matrix or
called control points with blending function
which indicate the
general shape of the
curve.
2- It follows the general 2- These curves are a 2- The curve generally
shape of the curve result of the use of follows the shape of a
open uniform basis defining polygon
function
3- Typical CAD 3- These curves can be 3- These are found in
application for Spline used to construct painting and drawing
Parametric Surfaces

Explicit versus Implicit


Quadric surfaces

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy