Você está na página 1de 125

PRAFUL BAGUL

COMPUTER GRAPHICS
SYLLABUS

CHAPTER 1 INTRODUCTION →
Elements of a Graphics work station.
What is Graphics

Video display devices –


Random Scan System & Raster Scan System, Input devices –
Graphics Software, co-ordinate representation, fundamental problems in Geometry.

CHAPTER 2 ALGORITHMS → Line drawing algorithm, DTA algorithm, Presentian’s


algorithm, frame buffers, Circle & ellipse generating algo, midpoint circle alg., midpoint

ellipse algo, Polynomial & spline curves –


inside, outside text, scan, line, file of curved
boundary areas, Boundary fill algo, flood fill algo, characters generation attributes of
lines, curves, filling character, etc.

CHAPTER 3 GRAPHICS PRIMITIVES The display file interpretes, display file



structure, display file algorithms.

CHAPTER 4 ATTRIBUTES OF OUTPUT PRIMITIVES


attributes, file attributes and character attributes.
→ Line attributes colour

CHAPTER 5 GEOMETRIC TRANSFORMATION → Matrices, scaling transformations,


(sine & cos rotation), homogeneous rotation & translation, Rotation about on arbitrary
point, inverse transformation.

CHAPTER 6 2-D VIEWING → Viewing pipeline, viewing co-ordinates reference frame,


window to view part co-ordinate transformation, 2-D viewing function, clipping operations,
port clipping, line dipping, Sutherland / Cohens line clipping algo, polygon clipping algo,
Sutherland/Hodgeman polygon clipping algorithm.

CHAPTER 7 3-D CONCEPTS → 3-D Display methods, parallel projection, perspective


projection, visible line and surface identification, Bergier Curves & V spline curves.
CHAPTER 8 VISIBILITY Z BUFFER ALGORITHM

CHAPTER 9 Computer Animations, design of animation sequence, Raster animations,


morphing motion specification, kinematics & dynamics.
1
* INTRODUCTION TO COMPUTER GRAPHICS *
INTRODUCTION  What is Graphics?
Elements of a Graphics work station.
Video display devices – Random Scan System & Raster Scan System, Input devices –
Graphics Software, co-ordinate representation, fundamental problems in Geometry.

Computer Graphics

Computer Graphics is the pictorial representation of information using a computer


program.

In Computer Graphics, pictures as graphical subjects are represented as a collection of


discrete picture element called pixels.

Pixel is smallest addressable screen element.

Pixel Column

P1 & P2 are represented as one pixel (4, 3)

The process of determining the appropriate pixels for representing pictures or object
is Rasterization & the process of representing continuous pictures as graphical object as
a collection of discrete pixel is called Scan Conversion.

Applications:-

Some of the areas of applications of computer graphics is CAD (Computer Aided


Design). This is issued by civil, mechanical, algbrical & electronic engineers to build a
model of building, bridges, PCB circuit, etc.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
They can also be used for developing a model of bridge & various effect and stimulate
the situation in Developing a model of a bridge and testing it over a simulator for
earthquake resistance.
Medical Imaging – It can be used to train new doctors on understanding and
experimenting surgery.

It is used in molecular biology to study the biological model in genes.

CATHODE RAY TUBE (CRT)

Simplified representation of CRT:-

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
BASIC OPERATION

A beam of electrons (i.e. cathode rays) is emitted by the electron gun, it passes
through focusing and deflection systems that direct the beam towards the specified
position on the phosphor screen. The phosphor then emits a small spot of light at every
position contacted by the electron beam. Since light emitted by the phosphor fades very
quickly some method is needed for maintaining the screen picture. One of the simplest
way to maintain pictures on the screen is to redraw the image rapidly. This type of display
is called Refresh CRT.

Primary components of CRT are as follows:-

1 HEATER ELEMENT AND CATHODE

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Heat is supplied to the cathode by passing current through heater element. Cathode
is cylindrical metallic structure which is rich in electrons. On heating the electrons are
released from cathode surface.

2 CONTROL GRID

It is the next element which follows cathode. It almost covers cathode leaving small
opening for electrons to come out. Intensity of the electron beam is controlled by setting
voltage levels on the control grid. A high negative cottage applied to the control grid will
shut off the beam by repelling electrons and stopping them from passing through the
small hole at the end of control grid structure. A smaller negative voltage on the control
grid will simply decrease the number of electrons passing through. Thus we can control
the brightness of a display by varying the voltage on the control grid.

3 ACCELERATING ANODE

They are positively charged anodes who accelerate the electrons towards phosphor
screen.

4 FOCUSING & DEFLECTION COILS

They are together needed to force the electron beam to converge into a small spot
as it strikes the screen otherwise the electrons would repel each other and the beam
would spread out as it approaches the screen. Electrostatic focusing is commonly used in
television and computer graphics monitor.

5 PHOSPHOR COATING

When the accelerating electron beam (collides) is incident on the phosphor cooling,
a part of Kinetic Energy is converted into light and heat. When the electrons in the beam
collide with the phosphor coating they are stopped and their kinetic energy is absorbed
by the phosphor.

 There are two techniques for producing images on the CRT screen

1 Vector Scan / Random scan Display


2 Raster Scan display

1 VECTOR / RANDOM SCAN DISPLAY

A Vector scan display directly traces out only the desired lines on the
CRT tube i.e. a CRT has the electron beam directed only to the
parts of the screen where a picture is to be drawn. Random scan
monitors draw a picture one line at a time and for this reason are
also known as Vector Scan Displays.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
If we want a line connecting point A with B on the vector graphics display, we simply drive
the beam deflection circuiting, which will cause the beam to go directly from point A to B.
If we want to move the beam from point A to point B without showing a line between
points, we can blank the beam as we move it.

INTERNATIONAL OPERATION

An application program along with graphics package is present in the system


memory. The graphic commands is the program and translated by the graphics package
and stored in the display file. In other records the file used to store the commands
necessary for drawing the line segments is called the Display file. The program which
converts these commands into actual picture is called the Display file Interpreter. It is an
interface between the graphics representation in the display file and display device. The
display processor is connected to the display device, processes and manages the display
process.

The commands present in the display file contains two fields, an operation code (opcode)
and operands. Opcode identifies the commands such as line draw, move cursors, etc
and the operands provide the co-ordinate of a point to process the commands.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
One of the way to store opcode and operands of series of commands is to use to
separate arrays, one for opcode, one for x-coordinate and one for y-co-ordinate of the
operand. It is also necessary to assign meanings to the possible opcodes before we can
proceed to interpret them.

e.g. COMMAND OPCODE


MOVE 1
LINE 2

The figure below shows how these commands are interpreted and plotted.

Command 1: 1, 30, 30
Moves the current cursor
0
position to point (30, 30) (30 , 30)

(50, 80)
Command 2: 2, 50, 80
Draws line between
point (30, 30) & (50, 80)
(30, 30)

(50, 80)
Command 3: 2, 70, 30
Draws line between
points (70, 30) & (50, 80)

(30,30) (70,30)

(50,80)
Command 4” 1, 40, 55
It makes current cursor position to
point (40, 55)

(30,30) (30,30)

(50,80)
Command 5: 2. 60, 55
It draws the line between point (60, 55) (40,50) (60,55)
and current cursor
position (40, 55)

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
(30,30) (70,30)

RASTER SCAN DISPLAY


This is the most common method of drawing images on the
CRT screen. In this method. Horizontal and vertical
deflection signals are generated to move the beam all over
the screen in a pattern as shown in figure i.e. the electron
beam is swept across the screen one row at a time from top
to bottom.

Here the beam is swept back and forth from left to right
across the screen. When the beam is moved from left to
right it is ON. The beam is OFF when it moves from right to
left and is called as Horizontal Retrace and is shown by dotted lines.

When the beam reaches the bottom of the screen it is turned off and is rapidly retraced
back to the top to start again. This is called the Vertical Retrace. In the Raster Scan
display the screen image is maintained by repeating scanning of the same image. The
process is shown as Refreshing of screen.

INTERNAL OPERATION

Fig  PROCESS – RASTER SCAN SYSTEM

Picture definition is stored in a memory area called Refresh buffer or Frame Buffer for
which a fined area of the system memory is kept reserved. The frame buffer holds the set

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
of intensity values for all the screen points. Stored intensity values are then retrieved from
the refresh buffer and displayed on the screen one row at a time. Video controller has
direct access to memory locations in the frame buffer. It is responsible for retrieving data
from the frame buffer and passing it to the display device.

Frame buffer maps the screen into cartesian co-ordinates. Generally, the screen co-
ordinates are taken as positive (x, y) plane. Hence the screen is continuously refreshed
by scanning from maximum value of y-coordinate down to y = 0.

Distinguish between Raster & Random Scan

RASTER SCAN DISPLAY RANDOM SCAN DISPLAY

i) It draws the image by i) It draws the image by directing the electron


scanning one row at a time beam directly to the part of the screen
where the image is to be drawn.

ii) They generally have resolution ii) They have higher resolution than Raster
limited to pixel size. Scan System

iii) Lines are jaggered and curves iii) Line plots are straight and curves
are less smoother are smooth.

iv) They are more suited to geometric iv) They are more suited to line
area drawing applications e.g. drawing application e.g. CRO’s
monitors, Tele vision , pen plotter.

 COLOUR DISPLAYS
There are 2 methods for producing colour displays.
A. Beam Penetration technique
B. Shadow – Mask technique

BEAM PENETRATION TECHNIQUE


This technique is used in Random Scan Monitors. In this technique, the inside of
CRT is coated with two layers of phosphor, usually red & green. The displayed colour
depends on how far the electron beam penetrates into the phosphor layers. 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. A beam of fast electrons penetrates the outer red layer
and excites the inner green layer. At intermediate beam speeds, combination of red and
green light are emitted and two additional colours 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.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
SHADOW MASK TECHNIQUE
The shadow mask technique produces a much wider range of colours than the
beam penetration technique. Hence this technique is commonly used in raster scan
displays including colour T.V.

In shadow mask technique, the CRT screen has three phosphor colour dots at each pixel
position. One phosphor dot emitts red light, another emits a green light and the third one
emits a blue light. The CRT has three electron guns one for each dot, a shadow mask
grid just behind the phosphor coated screen.

Fig  SHADOW MASK TECHNIQUE

The shadow mask grid consists of series of holes aligned with the phosphor dot patterns.
As shown in figure, the three electron beams are deflected and focused as a group onto
the shadow mask and when they pass through a hole onto a shadow mask they excite a
dot triangle. A dot triangle consists of 3 small phosphor dots of red, green and blue
colour. These phosphor dots are arranged so that each electron beam can activate only
its corresponding colour dot when it passes through the shadow mask. A dot triangle
when activated appears as a small dot on the screen which has colour 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.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
* INPUT DEVICES *

Following are the commonly used input devices


1 Keyboard
2 Mouse
3 Scanner
4 Trackball / Spaceball
5 Joystick
6 Digitizer / Graphical tablet

1 KEYBOARD
Keyboard is the primary input device for any graphics system. It is used for entering
text and numbers. Keyboards are available in various sizes, shapes & styles. The
standard keyboard consists of
1 Alphanumeric keys
2 Function keys
3 Modifier keys
4 Cursor Movement keys
5 Numeric Keypad

Fig  KEYBOARD PROCESS

When we press a key on the keyboard, the keyboard controller places a code
corresponding to the key pressed, in a part of its memory called keyboard buffer. This
code is called the scan code. The keyboard controller informs the CPU of the computer
about the key pressed with the help of interrept signals. The CPU then reads the scan
code from the Keyboard Buffer.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
2 MOUSE  A mouse is a palm sized box used to position the screen cursor. It consists
of a ball on the bottom connected to wheels to provide the amount and direction of
movement. One, two or three buttons are usually included on the top of the mouse for
signaling the execution of same operation. Now-a-days mouse consists of one more
wheel on top to scroll the screen pages.
3 TRACL BALL & SPACEBALL

Fig  TRACKBALL

A trackball is a ball that can be rotated with the finger or palm of the hand to produce the
screen cursor movement. Potentiometers attached to the ball measure the amount and
direction of rotation.

While the trackball is used for 2D positioning, the spaceball is used for 3D positioning &
selection of operation in virtual reality system unlike the trackball the spaceball does not
actually move. It consists of strain gauges which measures the amount of pressure
applied to the spaceball to provide input for spatial positioning & orientation of the ball is
pushed a pulled in various directions.

4 SCANNER
Scanner have become an important part of the home, office over the last few years. It is a
device which can be used to store drawings, graphics, photos as text available in the
printed form for computer processing.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Fig  PHOTO SCANNER

As shown in the fig the photograph is mounted on a rotating drum. A finely collimated
light beam is directed at the photo, and the amount of light reflected is measured by a
photocell. As the drum rotates the light source slowly moves from one end to the other,
thus doing a raster scan of the inter photograph.

5 JOYSTICK

Fig (A)  JOYSTICK


(B)  CIRCUIT DETAILS

A joystick has a small vertical lever mounted on the base and used to steer the
screen cursor around. It consists of two potentiometers attached to a single liver. Moving
the liver changes the settings on the potentiometer. The left or right movement is
indicated by other one potentiometer & the forward or backward movement is indicated
by other potentiometer. Thus with a joystick box x & y co-ordinate positions can be
simultaneously altered by the motion of a single lever.

Some joysticks may return to this zero (centre) positions when released. Joysticks
are inexpressive and quiet commonly used where only rough positioning is needed.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
6 DIGITIZER / GRAPHICAL TABLET
For applications such as tracing we need a device called a Digitizer or Graphical
Tablet. It consists of a flat surface, ranging in size from about 6 x 6 inches upto 48 to 72
inches or more, which can direct the position of a movable styles.

In this arrangement a grid of wires of ¼ to ½ inch centers is embedded in the tablet


surface. Electromagnetic signals generated by electrical pulses applied in sequence to
the wires in the grid induce an electrical signal in a wire cod in the styles. The strength of
the signal induced by each pulse is used to determine the position of the styles.



pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
2
LINE DRAWING ALGORITHM
ALGORITHMS  Line drawing algorithm, DTA algorithm, Presentian’s algorithm, frame
buffers, Circle & ellipse generating algo, midpoint circle alg., midpoint ellipse algo,
Polynomial & spline curves – inside, outside text, scan, line, file of curved boundary
areas, Boundary fill algo, flood fill algo, characters generation attributes of lines, curves,
filling character, etc.

DDA ALGORITHM [DIGITAL DIFFERENTIAL ALGORITHM]

The slope of a straight line is given as


y y 2  y1
m    1
n x 2  x1

The above differential Eqn. Can be written as

y 2  y1
y  x
x 2  x1
x 2  x1
& n  y  2
y 2  y1

Once the intervals are known, the values for rent x & y can be obtained as follows
xi+1 = xi + x

x 2  x 1
x i  1  x i   y  3
y 2  y 1

y 2  y 1
& y i  1  y i   x  4
x 2  x 1

The eqns 3 & 4 are called as the recursive eqns for finding out the successive values of x
& y along a required line. Such a way of rasterising a line is called Digital Differential
Algorithm.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
If | x |  | y |, then x = 1
else y = 1
If, x = 1, then

y 2  y1
y i1  y i 
x 2  x1
x i1  x i  1

If, y = 1, then

x 2  x1
x i1  x i 
y 2  y1
y i1  y i  1

DDA Line ALGORITHM

Step 1 Read the line end points (x1, y1) & (x2, y2) such that they are not equal

2 x = | x2 – x1 | &
y = | y2 – y1 |

3 If x  y, then length = x, else


length = y
x 2  x 1 y 2  y 1
 x  &  y 
Length Length

[This makes either x & y = 1 because length is either absolute value of (x2 – x1) or
absolute value of (y2 – y1). Therefore the incremental value for either x or y is 1]

5 x = x1 + sign (x) & y = y1 + sign (y)


[The sign function makes the algorithm work is all the quadrants]

6 i = 1 (counter)
while (i  length)
{
Plot (Integer (x), Integer (y))
x = x + x
y = y + y
i=i+1

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
}

7 Stop.

Q. Consider the line from (0, 0) to (4, 6). Use the DDA algorithm to rasterize the line.

Step 1. x1 = 0, y1 = 0, x2 = 4, y2 = 6

2. x = |4 – 0| = 4, y = |6 – 0| = 6

x 2  x1 4 y 2  y1 6
4 x   , y    1
Length 6 Length 6
3. Length = y = |y2 – y1| = 6

5. x = x1 + Sign (x) 6. y = y1 + Sign (y)


= 0 + 0.67 =0+1
= 0.67 =1

i Plot x t
0.67 1
1 (1, 1) (1.34) 2
2 (1, 2) 2.01 3
3 (2, 3) 2.68 4
4 (3, 4) 3.35 5
5 (3, 5) 4.02 6
6 (4, 6) 4.69 7

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Q. Consider a line from (0, 0) to (6, 6) use the DDA algorithm to rasterize.

1. x1 = 0 x2 = 6
y1 = 0 y2 = 6

2. x = | 6 – 0 | = 6
y = | 6 – 0 | = 6

3. length = x = | x2 – x1 | = 6

x 2  x1 6
4 . x    1
Length 6
y 2  y1 6
y    1
Length 6

5. x = x1 + Sign (x), y = y1 + Sign (y)


=0+1 =0+1
=1 =1

i Plot x y
0 1 1
1 (1, 1) 2 2
2 (2, 2) 3 3
3 (3, 3) 4 4
4 (4, 4) 5 5
5 (5, 5) 6 6

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
6 (6, 6)

BRESENHAM’S LINE DRAWING ALGORITHM

Bresenham’s Algorithm uses only integer addition, subtraction and multiplication by


2 which the computer can perform rapidly. Hence, it is an efficient method for scan
converting the straight line.

The basic principle is to select an optimum raster location to present a straight line.
The algorithm always increments either x or y by one unit depending on the slope of the
line. The increment in the other variable is determined by examining the distance
between the actual line location and the nearest pixel. This distance is called the
Decision Variable or error represented as ‘e’. If e  0, it implies that the pixel above the
line is closes to the true value. if e  0, it implies the pixel below the line is closer to the
true value.

Thus by checking the sign of the error term, it is possible to determine the better
pixel to represent the line path.

e = 2 * y - x, where y = y2 – y1
x = x2 – x1
According to the value of e, the following actions are taken,
while (e  0)
{
y=y+1
e = e – 2 * x
}
x=x+1
e = e + 2 * y

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
ALGORITHM

STEP 1. Read the line end points (x1, y1) & (x2, y2) such that they are not equal.

2. x = x2 – x1 & /
y = y2 – y1

3. Initialize starting point as


x = x1 & y = y1

4. e = 2 * y - x
[Initialize value of decesion variables or error]

5. Initialize counter i = 1

6. Plot (x, y)

7. while (e  0)
{
y=y+1
e = e-2 * x
y
x=x+1
e = e + 2 * y

8. i = i + 1

9. If (i  x) go to step 6

10. Stop.

Ex 1. Consider a line from (5, 5) to (13, 9). Use the B. L. DAL to rasterize the line.

1. x1 = 5 x2 = 13
y1 = 5 y2 = 9
2. x = |x2 – x1| = 13 – 5 = 8
y = |y2 – y1| = 9 – 5 = 4
3. x = 5, y = 5
4. e = 2 * y - x
=2*4–8
=0
5. i = 1

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
i Plot x y e
5 5 0
1 (5, 5) 6 6 -8
2 (6, 6) 7 6 0
3 (7, 6) 8 7 -8
4 (8, 7) 9 7 0
5 (9, 7) 10 8 -8
6 (10, 8) 11 8 0
7 (11, 8) 12 9 -8
8 (12, 9) 13 9

Ex. 2. Consider a line from (2, 5) to (10, 10). Apply Bresenham’s line drawing algorithm to
plot the line.

1. x1 = 2 x2 = 10
y1 = 5 y2 = 10
2. x = |x2 – x1| = |10 – 2| = 8
y = |y2 – y1| = |10 – 5| = 5
3. x = 2
y=5
4. e = 2 * y - x = 2 x 5 – 8 = 2
e=2
5. i = 1

i Plot x y e
2 5 2
1 (2, 5) 3 6 -4

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
2 (3, 6) 4 6 6
3 (4, 6) 5 7 4
4 (5, 7) 6 8 2
5 (6, 7) 7 8 +8
6 (7, 8) 8 9 2
7 (8, 9) 9 10 -4
8 (9, 10) 10 10

CIRCLE GENERATING ALGORITHM


A Circle is a symmetric figure. It has 8-way symmetry. Thus a circle generating algorithm
can take advantage of circle symmetry to plot 8 points by calculating the co-ordinate of
any one point.
e.g. If point A is calculated with circle generating algorithm then 7 more points can be
drawn by just reflection.

MIDPOINT CIRCLE GENERATING ALGORITHM

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
The Midpoint Circle Generating algorithm uses 8-way of symmetry of the circle
th
generated. If plots 1/8 part of a circle is from 90 to 45. So the x-coordinate who is in
+ve direction & y-coordinate who is in –ve direction. We take unique steps in x direction
and make use of decision parameters to determine which of the 2 possible y-positions
are closer to the circular path of each step. The 2 possible y positions are yi and yi-1 and
at same position xi and xi+1. We have to determine whether the pixel at position (xi+1, yi)
as (xi+1, yi-1) is close to the circle. So for that purpose the decision parameter is used
which uses the circle function.
2 2 2
Parde (x, y) = x + y – r
The decision parameter
di = Parde (xi + 1, yi – ½)
2 2 2
= (xi + 1) + (yi – ½) – r  1

If di < 0, the midpoint is inside the circle and the pixel on the scan line yi is closer to the
circle boundary.

If di  0, then the midpoint is outside or on the circle boundary & yi-1 is closer to the circle
boundary. The incrementry calculation can be determined to obtain the successive
decision parameter.
2 2 2
di+1 = (xi+1 + 1) + (yi+1 – ½) – r
2 2 2
= (xi+1) + 2xi+1 + 1 + (yi+1) – yi+1 + ¼ - r
2 2 2
di+1 = (xi+1) + 1 + 2xi+1 + (yi+1) – yi+1 + ¼ - r
2 2 2
From 1, put (xi+1) – r = di – (yi – ½)
2 2
di+1 = di –(yi – ½) + 1 + 2xi+1 + (yi+1) – yi+1 + ¼
2 2
= di – yi – ¼ + yi + 1 + 2xi+1 + (yi+1) – yi+1 + ¼
2 2 i
= di – [(yi) – (yi+1) ] – [yi+1 – y ] + 1 + 2xi+1
2 2
di+1 = di [(yi+1) – (yi) ] – [yi+1 – yi] + 1 + 2xi+1

where yi+1 is either yi or yi-1


1) If di < 0 then yi+1 = yi
di+1 = di + 2(xi+1) + 1

2) If di > 0 then yi+I = yi-1


2 2
di+1 = di + [(yi-1) – (yi) ] – [yi –1 – yi] + 1 + 2xi+1

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
2 2
di+1 = di + 2xi+1 + 1 + [(yi) – 2yi + 1 – (yi) ] – [yi – yi + 1]
di+1 = di + 2xi+1 + 1 – 2yi

Initial decision parameter at start position (x0, y0) = (0, r)


d0 = Farde (0, r – ½)
2 2 2
= (0 + 1) + (r – ½) – r
2 2
=1+r –r+¼-r
=1+¼-r
= 5/4 – r
d0 = 1.25 - r
ALGORITHM

Step 1. Read the radius r of the circle.


Step 2. Initialize the starting point x = 0 & y = r
Step 3. Calculate the initial value of the decision parameter as d0 = 1.25 – r
Step 4. Do
{
Plot(x, y)
If (d < 0)
{
x=x+1
y=y
d = d + 2x + 1
}
else
x=x+1
y=y–1
d = d + 2x – 2y + 1
}
}
while (x < y)
Step 5. Determine the symmetry points
Step 6. Stop.

ELLIPSE GENERATING ALGORITHM


Ellipse is an elongated circle with a major axis & a minor axis.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
x2 y2
Eqnofellip seis  1
rx 2 ry 2
2 2 2 2 2 2
ry x + rx y = rx ry
2 2 2 2 2 2
ry x + rx y – rx ry = 0

Midpoint ellipse algorithm

The midpoint ellipse algorithm is applied throughout the first quadrant in two parts. We
process this quadrant by taking unit steps in x direction where the slope of the curve has
a magnitude less than 1, and taking unit step in the y direction where the slope has a
magnitude greater than 1.

We start at position (0, ry) and step clockwise along the elliptical path in the first quadrant
shifting from unit steps in x to unit steps in y when the slope becomes less than –1.
2 2 2 2 2 2
We define an ellipse function as ellipse (x, y) = ry x +rx y – rx ry which has the
following properties

  0 ( x , y ) insideelli pseboundar y

fellipse ( x , y )   0 ( x , y ) anellipseb oundary
  0 ( x , y ) outsideell ipsebounda ry

The ellipse slope is calculated as


2 2
rx y  ry 2 x 2  rx 2 ry 2
dy d d
 rx 2 ( y 2 )  ry 2 (x 2
)  ( rx 2
ry 2
)
dx dx dx
dy
 rx 2 . 2 y  ry 2 . 2 x  0
dx
dy
 2 y . rx 2   2 x . ry 2
dx
dy  2 x . ry 2
   2
dx 2 yrx 2
pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Differentiating the eqn

Let the boundary between region 1 &2


dy
Slope   1
dx
 2 x.ry 2
 1 
2 y.rx 2
 x 2 .ry 2  2 y.rx 2
2 2
We move out of region 1 whenever 2x.ry  2yrx

Region 1

The decision parameter at midpoint is


1
P k = fellipse (xR + 1, yR – ½)
2 2 2 2 2 2
= ry (xR+1) + rx (yK-1/2) – rx ry  3

If P1k < 0, the midpoint is inside the ellipse and the pixel of scan line yk is closer to
the ellipse boundary. Otherwise, the midposition outside or on the ellipse boundary, and
we select the pixel on the scan line yk-1

at the next sampling position

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
1
P k+1= fellipse (xk+1 + 1, yk+1 – ½)
2 2 2 2 2 2
= ry [(xR+1) + 1] + rx [yR+1 – ½] – rx ry
 from
1 2 2 2 2 2 2
P k+1 = ry [(xR+1) + 2(xR+1) + 1] + rx [(yR+1) – (yR+1) + ¼] – rx ry
1 2 2 2 2 2 2 2 2 2 2
P k+1 = ry (xR+1) + 2ry (xR+1) + ry + rx (yR+1) – rx (yR+1) + rx – rx ry
1 1 2 2 2 2 2 2
P k+1 = P k – rx (yk – ½) + 2ry (xR+1) + ry + rx (yR+1 – ½)

From Eqn 3
1 1 2 2 2 2 2 2
P k+1 = P k + 2ry (xR+1) + ry + rx (yR+1 – ½) – rx (yR – ½)  4
1
If P k < 0, yk+1 = yk
1 1 2 2
P k+1 = P k +2ry (xR+1) + ry
1
& If P k  0, yR + 1 = yk – 1
1 1 2 2 2 2 2
P k+1 = P k + 2ry (xR+1) + ry + rx [(yR – 1 – ½) – (yR – ½) ]
1 1 2 2 2 2 2
P k+1 = P k + 2ry (xR+1) + ry + rx [(yR – 3/2) – (yR – ½) ]
1 1 2 2 2
P k+1 = P k + 2ry (xk+1) + ry + rx (2 – 2yR)
1 1 2 2 2
P k+1 = P k + 2ry (xR+1) + ry – 2rx (yR-1)

In region 1, the value of decesion parameter is obtained by evaluating the ellipse function
at the start position (0, ry)
1
P 0 = fellipse (0+1, ry-1/2)
1 2 2 2 2 2
P 0 = r y + rx (ry – ½) – rx ry
1 2 2 2
P 0 = r y +r xry + rx /4

Region 2

Over region 2, we sample unit steps in negative y direction and the midpoint is now taken
between the horizontal pixels at each step. In this region the decision parameter is
evaluated as
2
P k = fellipse (xR + ½, yk – 1)

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
2 2 2 2 2 2 2
P k = ry (xk + ½) + rx (yk – 1) – rx ry
2
If P k > 0, the midpoint is outside the ellipse boundary and we select the pixel at position
2
xR+1. If P k < 0 then at the next sampling position

2
 1
i.e.P k 1  ry  x R  1    rx 2 ( y k  1  1) 2  rx 2 ry 2
2 2

 2
 1
P 2 k 1  ry 2 ( xR 1 ) 2  ( x R  1)    rx 2 [( y R 1 ) 2  1  2( y R 1 )]  rx 2 ry 2
 4
 P 2 k 1  P 2 k  rx 2 ( y k  1) 2  ry 2 ( xk  1)
2
2 2 2 2

2 1  1 
P k P k  2rx  2rx ( yk  1)  rx  ry  xk 1     y k   
 2  2  

 1 
P 2 0  fellipse x  , y0  1
 2 
2
2  1
P 0  ry  x0    rx 2 ( y0  1)  rx 2 ry
2

 2

POLYLINE

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
A polyline is a chain of connected line segments. It is specified by giving the vertices P0,
P1, P2, & so on. The first vertex is called the initial or starting point & the last vertex is
called final or terminal point.

POLYGON

When starting point & the terminal point of any polyline is same i.e. when polyline is
closed then it is called as a polygon.

TYPES OF PLYGON

 The classification of polygons is based on where the line segment is joining any two
points within the polygon is going to lie.
 Types are – convex & concave polygon

1. CONVEX POLYGON

A convex polygon is a polygon in which the line segment joining any 2 points within the
polygon lies completely inside the polygon.

2. CONCAVE POLYGON

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
A Concave Polygon is a polygon in which the line segment joining any 2 points
within the polygon lies partially outside the polygon.

Inside – Outside or Odd Even Test


To show that a polygon is a solid object we need to set pixel inside the polygon as
well as on the boundary. One simple method to determine whether a point is inside a
polygon or not is to determine an inside outside test.

Construct the line segment between the point in question and a point known to be outside
the polygon. Now count the number of intersections of the line segments with the polygon
boundary. If there are odd number of intersections then the point is inside the polygon
otherwise it is outside the polygon. This method is also known as even off method of
determining the points inside the polygon.

POLYGON FILLING

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Filling in the polygon means highlighting all the pixels while lie inside the polygon
with any colour other than the background colour. There are 2 basic approaches to fill the
polygon.
1. Flood – Fill Method
2. Scan – Line Method

FLOOD FILL METHOD


 In this approach we start from a given seed point known to be inside the polygon and
highlight outwards from this point until we encounter the boundary pixels.
 This approach is called the flood fill because colour flows from the seed pixel until
reaching the polygon boundary like water flooding on the surface of a container.
 There are 2 methods for proceeding to the neighboring pixels.

1. 4 Connected
In this case, the pixel-position that are to the right, left, above and below. The current
pixel are tested.

2. 8 Connected
In this case, along with the 4 pixel positions used in the 4-connected method, 4-diagonal
pixels are also tested.

SCANLINE ALGORITHM

 The fig illustrates the scanline algorithm for filling of the polygon.
 For each scan line crossing the polygon, this algorithm locate the intersection points
of the scan line with the polygon edges.
 These intersection points are sorted from left to right, and the corresponding
positions between each intersection pair are set to the specified fill colour.
 The scanline algorithm first finds the largest & the smallest of y values of the polygon,
it then starts with the largest y value and works its way down, scanning from left to
right, in the manner of a Raster display.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 The important task in this algorithm is to find the intersection points of the scan line
with the polygon boundary.
 According to inside-outside tests, when the intersection points are even, they are
sorted from left to right the paired & pixels between the paired points are set to the fill
colour. But in some cases, intersection point is a vertex. When scan line intersects
polygon vertex, a special handling is required t find the exact intersection points.

 As shown in the figure above each scan line intersects the vertex of the polygon.
 For scan line 1, the other end points (B & D) of the two line segments of the polygon
lie on the same side of the scan line. Hence it is considered an even point i.e. they
are considered as 2 intersecting points.
 For scan line 2, the other end points D & F, of the two line segments of the polygon
lie on opposite side of the scan line, hence they are considered as a single
intersection point as odd point.

Raster Algorithms

2.1 Line Drawing Algorithms –


In computer graphics, complex objects are formed using graphics primitives. These
graphics primitives are pixel, line, curve, polygon, text, circle, ellipse etc. Let us start with
the drawing algorithms.

2.1.1 DDA (Digital Differential Analyzer) Algorithm –

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
The DDA is an algorithm for calculating the pixel positions along a line. This is done, by
taking 7 unit steps with one of the coordinates and calculating corresponding values for
other coordinated case-1 If absolute value of the slope is less than or equal to 1, then x
coordinate is changed in unit steps and corresponding change in y is calculated.

The equation of the line is given as,


y = mx + h

Differentiating the above equation with respect to x we get,


dy/dx = m
 dy = mdx

Since, x is changed in unit steps,


dx = 1 and dy = m

From the above equations, we can write,


x1 + 1 = x1 + 1
y1 + 1 = y1+m

Case-2 If absolute value of slope is greater than 1, then y is changed in unit steps and
corresponding change in x is calculated.

Differentiating the equation of the line with respect to y we get,

dx
1  m
dy
dx = (1/m) dy

Since, y is changed in unit steps,


dy = 1 and dx = (1/m)
2.1 Prepared by Samir Lele

From the equations of dx and dy, we can write,

x1+1 = x1 + 1/m
y1+1 = y1 + 1

Thus, in both the cases, if we know (x1, y1), then we are in position to determine (x1+1,
y1+1). The process is started from the endpoints of the line and is stopped when
other end-point reached. The above process can be written in steps as follows,

Algorithm:
1) Read both the end points as (x1, y1) and (x2, y2).

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
2) Calculate chx and chy as,
chx  x2 - x1
chy  y2 - y1
3) If abs (chx) > abs (chy) Then steps  abs (chx)
Else steps  abs (chy)
4) Calculate xinc and yinc as,
xinc  chx / steps
yinc  chy / steps
5) Start with first endpoint and display it,
x  x1 y  y1
putpixel (x, y)
6) Repeat following, steps times.
a) Increment x as, x  x + xinc
b) Increment y as, y  y + yinc
c) Display the pixel, putpixel (x, y)

Disadvantatge – Since, DDA algorithm uses division operations, involves floating point
operations and hence requires more time.

2.1.2 Bresenham’s Line Drawing Algorithm –


This algorithm use only integer arithmetic and hence it is more efficient.

As shown in the diagram, say a point (4, 5) is drawn.


Now, we have to decide the next point in the line. It
can be (5, 5) or (5, 6). This is because, actual line is
passing through such a point, which can not be
represented on the screen. Hence, we have to select
nearer integer value.

Let us consider a line, with positive slope that is less


than or equal to 1. Therefore, x is changed in unit
steps. Let us assume that, a point (x1, y1) is drawn
and we have to decide the next point. We have two options, either (x1 + 1, y1) or (x1 + 1,
y1 + 1). One of these two points is selected, whichever is nearer to actual position.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
From this diagram, we can write following equations,
y = m (x1 + 1) + h
 d1 = y – y1
 d1 = m (x1 + 1) + h – y1

d2 = (y1 + 1) – y
 d2 = y1 + 1 – m (x1 + 1) – h
The difference d1 – d2 is calculated as,

d1 – d2 = m (x1 + 1) + h – y1 – y1 – 1 + m (x1 + 1) + h
 d1 – d2 = 2m (x1 + 1) – 2y1 + 2n-1
Substitute m as y / x

 d1 – d2 = (2y / x) (x1 + 1) – 2y1 + 2h-1


 x (d1 – d2) = 2y (x1 + 1) – 2y1x+ (2h – 1) x
Let us call x (d1 – d2) as P1.

 P1 = 2y (x1 + 1) - 2xy1 + (2h – 1) x - 1


From the eqn. 1, we can calculate P1 + 1 as follows,

 P1+1 = 2y (x1+1 + 1) - 2xy1+1 + (2h-1) x


 P1+1 = 2y (x1 + 2) – 2xy1+1 + (2h-1) x - 2
The eqn. 2 – 1 gives,

P1+1 = 2y (x1 + 2 – x1 – 1) - 2xy1+1 + 2xy1


 P1+1 = P1 + 2y - 2x (y1+1 – y1) -3

If P1 is negative, then d1 < d2 and hence y1+1 = y1. By substituting this condition, in eqn 3
we get,
P1+1 = P1 + 2y -4

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
If P1 is zero or positive then d1  d2 and hence y1+1 = y1 + 1.
By substituting this condition in eqn 3 we get,
P1+1 = P1 + 2y - 2x -5

Thus, from eqn 4 and 5 we can calculate P1+1, if we know P1. In this case, P1 should be
known.
P1 = 2y (x1 + 1) – 2y1x + (2h-1) x
 P1 = 2y (x1 + 1) – 2y1x + (2h-1) x
Let us substitute, h – y1 – mx1 in the above equation.
 P1 = 2y (x1 + 1) – 2xy1 + (2y1 – 2mx1 – 1) x

 y
 P 1  2  y ( x 1  1 )  2  xy 1  (2 y1  2 x1  1)  x
 x
 P 1  2  yx 1  2  y  2  xy 1  2  xy 1  2  yx 1   x
 P1  2  y   x

Thus, we can summarize above calculations as,


P1 = 2y - x
P1+1 = P1 + 2y if P1 < 0
P1+1 = P1 + 2(y - x) if P1  0

Similar equations can be obtained for the line whose absolute of the slope is greater than
1. In that case, y is changed in units steps and the corresponding change in x is
calculated. The equations in this case will be as follows,
P1 = 2x - y
P1+1 = P1 + 2x if P1 < 0
P1+1 = P1 + 2 (x - y) if P1  0

All the six equations do not involve floating point calculations and hence it will be faster
than DDA line drawing algorithm.

The complete process can be written in steps as follows.

Algorithm
1) Read both the end points of a line as (x1, y1) and (x2, y2).
2) Calculate x and y as
x  abs (x2 – x1)
y  abs (y2 – y1)
3) Initialize the value of (x, y) as (x1, y1)
x  x1
yy

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
4) Plot the pixel
putpixel (x, y)
5) Decide the increment value of x and y
If (x1 < x2) Then xinc  1 Else xinc  -1
If (y1 < y2) The yinc  1 Else yinc  -1
6) Decide whether change in x is greater or change in y is greater and change the
corresponding coordinate in unit steps and calculate other coordinate accordingly.
If (x  y) Then
Begin
a) Initializing the parameter
P  2y - x
b) While x < > x2 do
Begin
x  x + xinc
If P < 0
Then P  P + 2y
Else
Begin
P  P + 2 (y - x)
y  y + yinc
end
putpixel (x, y)
End

Else
Begin
a) Initialize the parameter as
P  2x - y
b) While y < > y2 do
Begin
Y  y + yinc
If ( P < 0)
Then, P  P + 2x
Else,
Begin
P  P + 2 (x - y)
X  x + xinc
end
putpixel (x, y)
end
end

Problem – Apply Bresenham’s line drawing algorithm to the end points,


(x1, y1) = (20, 20) and (x2, y2) = (12, 15)

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Ans –
x  abs (12 – 20)  8, y  abs (15 – 20)  5
Since x1 < x2 i.e. 20 < 12 is false, xinc  -1
Since y1 < y2 i.e. 20 < 15 is false, yinc  -1
Since x < y is true, then part of step 6 of the algorithm will come in picture. The
calculations can be done as shown below.

xi yi Pi Pi+1 Plotted pixel


xi+1 yi+1
20 20
20 20 2 -4 19 19
19 19 -4 6 18 19
18 19 6 0 17 18
17 18 0 -6 16 17

xi yi Pi Pi+1 Plotted pixel


xi+1 yi+1
16 17 -6 4 15 17
15 17 4 -2 14 16
14 16 -2 8 13 16
13 16 8 2 12 15

2.2 Circle Drawing Algorithms


There are two different types of algorithms to draw the circle.

2.1.1 Bresenham’s Circle Drawing Algorithm –

In the Bresenham’s circle algorithm, the process is similar to the drawing algorithm. The
parametric equations Pi and Pi+1 are calculated in the same manner. Let us say that, a
point (xi, yi) is drawn. The next point to be drawn is to be decided. It can be either (xi+1,
yi) (xi + 1, yi – 1).

2 2 2
The equation of the circle is x + y = r

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
2 2 2
y =r –x

The circle drawing is started from a point (0, r) assuming (0, 0) as center of the circle.
From the diagram-2, we can write,
2 2 2 2
d1 = yi – y and d2 = y – (yi – 1)
2 2 2 i2 2 2
 d1 = yi (r – x ) = y – (r – (xi + 1) ) -1 x = xi + 1
2 2 2
 d1 = yi – (r – (xi+1) )
Similarly,
2 2 2 2 2
d2 = y – (yi – 1) d2 = (r – x ) – (yi – 1)
2 2 2
 d2 = (r – (xi + 1) ) – (y1 – 1) -2 x = xi + 1
The parameter Pi is given as, Pi = d1 – d2
2 2 2 2 2 2
 Pi = yi – (r – (x1 + 1) ) – (r – (xi + 1) – (yi – 1) )
i 2 2 2 2 2 2
P = yi + r + (xi + 1) – r + (xi +1) + (yi – 1)
2 2 2 2
 Pi = 2 (xi + 1) + yi + (yi-1) – 2r -1

From the equation we can write,


2 2 2 2
Pi+1 = 2(xi+1 + 1) + yi+1 + (yi+1 – 1) – 2r
2 2 2 2
 Pi+1 = 2 (xi+1 + 1) + yi+1 + (yi+1 – 1) – 2r
2 2 2 2
 Pi+1 = 2(xi + 2) + yi+1 + (yi+1 – 1) – 2r -2

The eqn 2 –1 gives,


2 2 2 2 2 2 2 2
Pi+1 – Pi = 2 (xi+2) + y i+1 + (yi+1 – 1) – 2r – 2 (xi+1) – yi – (yi – 1) + 2r
2 2 2 2 2 2
Pi+1 – Pi = 2[(xi+2) – (xi+1) ] + yi+1 + (yi+1 – 1) – yi – (yi - 1)
2 2 2 2 2 2
Pi+1 – Pi = 2[xi +4xi+4-xi -2xi-1] + yi+1 + (yi+1 – 1) – yi – (yi – 1)
2 2 2 2
Pi+1 – Pi = 2(2xi+3) + yi+1 + yi+1 – 2yi+1 + 1 – yi – yi + 2yi – 1
2 2
Pi+1 – Pi = 4xi + 6 + 2yi+1 – 2yi+1 – 2yi + 2yi
2 2
Pi+1 = Pi + 4xi + 6 + 2 (yi+1 – yi ) –2 (yi+1 – yi) ------ 3

If Pi is negative, then it means that, d1 < d2 and hence yi+1 = yi


Pi+1 = Pi + 4xi + 6 ----- 4
If Pi is positive or zero, then it means that, d1f  d2 and hence
Yi+1 = yi –1
2 2
Pi+1 = Pi + 4xi + 6 + 2 [(yi – 1) – yi ] – 2[yi-1 – yi]
2 2
Pi+1 = Pi + 4xi + 6 + 2 [yi – 2yi + 1 – yi ] + 2
Pi+1 = Pi + 4xi + 6 + 2 [-2yi + 1] + 2
Pi+1 = Pi + 4xi + 6 – 4yi + 2 + 2
Pi+1 = Pi + 4(xi – yi) + 10 ---- 5

From equations 4 and 5 we can say that, we are in position calculate Pi+1 if we know Pi.
However, we must know Pi. Let substitute I = 1 in equation 1 and hence,
2 2 2 2
P1 = 2(x1 + 1) + y1 + (y1 – 1) – 2r

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
The first point to be drawn is (x1, y1) = (0, r)
2 2 2 2
P1 = 2(0 + 1) + r + (r – 1) – 2r
2 2 2
P1 = 2 + r + r – 2r+1 – 2r
2 2
P1 = 2 + 2r – 2r + 1 –2r
P1 = 3 – 2r ---- 6
The above process can be summarized in steps as follows

Algorithm –
1) Read the radius r and center coordinates as (xc, yc).
2) Select first point for display, (x1, y1) = (0, r)
3) Calculate the first parameter as,
P  3 – 2r
4) While (x < = y) do following steps (step 5, 6 & 7)
5) Call display routine
6) If P < 0 Then P  P + 4x + 6
Else
Begin
P  P + 4 (x – y) + 1
yy–1
7) Increment x in unit steps as, x  x + 1

Let us assume that (xi, yi) is drawn. The next point to be drawn is to be determined. It will
be either (xi+1, yi) or (xi+1, yi-1). If the midpoint is inside the circle, then (xi+1, yi) is closer
to circle path. If the midpoint is outside the circle, then (xi+1, yi-1) is closer to the circle
path. The decision parameter Pi is calculated as follows,
Pi = fcircle (xi + 1, yi – ½)
2 2 2
Pi = (xi + 1) + (yi – ½) – r --- 1

The successive decision parameter Pi+1 is obtained as follows,


Pi+1 = fcircle (xi+1 + 1, yi+1 – ½)
2 2 2
Pi+1 = (xi+1 + 1) + (yi+1 – ½) – r
2 2 2
Pi+1 = (xi + 2) + (yi+1 – ½) – r --- 2
The equation 2 – 1 gives,
2 2 2 2 2 2
Pi+1 – Pi = (xi+2) + (yi+1 – ½) – r – (xi+1) – (yi – ½) + r
2 2 2 2
Pi+1 – Pi = (xi + 4xi + 4) + (yi+1 – ½) – (xi + 2xi + 1) – (yi – ½)
2 2
Pi+1 – Pi = 2xi + 3 + (yi+1 – ½) – (yi – ½)
2 2
Pi+1 = Pi + 2xi + 3 + (yi+1 – ½) – (yi – ½) ---- 3

If Pi is negative, then the midpoint lies inside the circle.


 Yi+1 = yi. By substituting this condition in eqn 3, we get
Pi+1 = Pi + 2xi + 3 --- 4

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
If Pi is positive or zero, then midpoint lies outside the circle or on the circle.  yi+1 = yi –
1. By substituting this condition in equation 3 we get,
2 2
Pi+1 = Pi + 2xi + 3 + (yi – 3/2) – (yi – ½)
2 2
Pi+1 = Pi + 2xi + 3 + yi – 3yi + 9/4 – yi + yi – ¼
Pi+1 = Pi + 2xi + 3 – 2yi + 2
Pi+1 = Pi + 2 (xi – yi) + 5 --- 5

From equations 4 and 5 we can say that, we are in position to calculate Pi+1, if we know
Pi. However, we must know Pi. Let us substitute i = 1 in eqn 1 and hence,
2 2 2
P1 = (x1 + 1) + (y1 – ½) – r
2 2
P1 = (0 + 1)2 + (r – ½) – r (x1, y1) = (0, r)
2 2
P1 = 1 + r – r + ¼ - r
P1 = 5/4 – r --- 6
The above process can be summarized in steps as,
Algorithm –
1) Read the radius as r and center coordinates as (xc, yc)
2) Select first point for display as (x1, y1) = (0, r).
3) Calculate the first parameter as P
P  5/4 – r 1–r
4) While (x < = y) do following steps (step 5, 6 & 7)
5) Call display routine
6) If P < 0 Then P  P + 2x + 3
Else
Begin
P  P + 2(x – y) + 2
yy–1
end
7) Increment x in unit steps as x  x +1

Display Routine –
i) putpixel (xc+x, yc+y) ii) putpixel (xc+x, yc–y)
iii) putpixel (xc–x, yc+y) iv) putpizel (xc–x, yc–y)
v) putpixel (xc+y, yc+x) vi) putpixel (xc+y, yc-x)
vii) putpixel (xc-y, yc-x) viii) putpixel (xc-y, yc-x)

Display Routine
i) putpixel (xc+x, yc+y) ii) putpixel (xc+x, yc–y)
iii) putpixel (xc–x, yc+y) iv) putpizel (xc–x, yc–y)
v) putpixel (xc+y, yc+x) vi) putpixel (xc+y, yc-x)
vii) putpixel (xc-y, yc+x) viii) putpixel (xc-y, yc-x)

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Problem – Using Bresenham’s Circle Algorithm, produce the sequence of at least five
points along the circumference of the circle with the radius 20, centered at (50, 50).
Y = 20
xi yi Pi Pi+1 xi+1 yi+1 Plotted pixel
0 20 50, 70
0 20 -37 -31 1 20 51, 70
1 20 -31 -21 2 20 52, 70
2 20 -21 -7 3 20 53, 70
3 20 -7 11 4 20 54, 70
4 20 11 -43 5 19 55, 69
5 19 -43 -17 6 19 56, 69
6 19 -17 13 7 19 57, 69
7 19 13 -25 8 18 58, 68

Midpoint Circle Algorithm –


In this algorithm also, the x is incremented in unit steps and the corresponding value of y
th
is calculated. In this algorithm also, the points are calculated only for 1/8 of circle. The
remaining 7/8 of the circle is achieved using symmetry. This process is same as that of in
Bresenham’s algorithm. In midpoint circle algorithm, a circle function is calculated as,
2 2 2
Fcircle (x, y) = x + y – r

From the above equation, we can obtain following points,

< 0 if (x, y) lies inside the circle


fcircle (x, y) = 0 if (x, y) lies on circle boundary
> 0 if (x, y) lies outside the circle

[DIAGRAM]

Ellipse Drawing Algorithm (Midpoint)


st
The midpoint ellipse drawing algorithm is applied throughout the 1 quadrant according to
the slope of the tagent. In region 1, the magnitude of the slope is less than 1 & hence the
x is incremented in unit steps & y is calculated. The process can be started from (0, ry) in
region 1. In region 2, the magnitude of the slope is greater than 1 and hence y is changed
in unit steps and x is calculated accordingly.

The function of the ellipse can be calculated from the equation of the ellipse.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
x2 y2
  1
rx 2 ry 2
2 2 2 2
 r y x 2  rx y 2  rx r y
2 2 2 2 2
 r y x 2  rx y  rx r y  0

2 2 2 2
f ellipse ( x , y )  r y x 2  r x y 2  r x r y
The function will have following properties,
< 0 if (x, y) is inside the ellipse,
fellipse (x, y) = 0 if (x, y) is on the ellipse,
> 0 if (x, y) is outside the ellipse.

The new point to be drawn is decided on the sign of the above function. The slope of the
ellipse is to be calculated after defining every point. This is done to check whether the
region 1 is finished or not.

The slope of the tangent to the ellipse at (x, y) can be calculated as shown follows,
2 2 2 2 2 2
ry x + rx y –rx ry = 0
Differentiating the above equation with respect to x, we get

2 2 dy
2 x . ry  2 y .r x  0
dx
2 2
 2 x .r y dy  xr y
 dy / dx  2
 
2 yr x
dx yr x 2

AT the junction of two regions, the slope becomes –1. In the first region, xi+1 = xi + 1.
The decision parameter is calculated as
P1i = fellipse (xi + 1, yi – ½)
2 2 2 2 2 2
P1i = ry (xi + 1) + rx (yi – ½) – rx ry --- 1

The successive decision parameter P1i+1 can be calculated as,

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
2 2 2 2 2 2
P1i+1 = ry (xi+1 + 1) + rx (yi+1 – ½) – rx ry
2 2 2 2
P1i+1 = ry2 (xi+2) + rx2 (yi+1 – ½) – rx ry --- 2

The equation 2 – 1 can be given as,


2 2 2 2 2 2 2 2 2 2
P1i+1 – P1i = ry (xi+2) + rx (yi+1-1/2) – rx2ry – ry (xi+1) – rx2 (yi-1/2) + rx ry
2 2 2 2 2 2
P1i+1 – P1i = ry [ xi + 4xi + 4 – xi – 2xi – 1] + rx [(yi+1 – ½) – (yI - 1/2) ]
2 2 2 2
P1i+1 – P1i = ry (2xi + 3) + rx [(yi+1 – ½) – (yi – ½) ]
2 2 2 2
P1i+1 = P1i + ry (2xi + 3) + rx [(yi+1 – ½) – (yi – ½) ] ---- 3

If P1i is negative then yi+1 = yi. By substituting this condition in equation 3, we get,
2
P1i+1 = P1i + ry (2xi + 3) -- 4

If Pi is positive or zero, then yi+1 = yi – 1


2 2 2 2
P1i+1 = P1i + ry (2xi+3) + rx [(yi – 3/2) – (yi – ½) ]
2 2 2 2
P1i+1 = P1i + ry (2xi+3) + rx [yi – 3yi + 9/4 – yi + yi – ¼]
2 2
P1i+1 = P1i + ry (2xi+3) + rx (-2yi + 2) --- 5

Let us calculate P1i using (x1, y1) = (0, ry)


2 2 2 2 2 2
P1i = ry (xi+1) + rx (yi – ½) – rx ry
2 2 2 2 2 2
P1i = ry (0+1) + rx (ry-1/2) – rx ry
2 2 2 2 2
= ry + rx (ry – ry + ½) – rx ry
2 2 2 2 2 2 2
P1i = ry + rx ry – rx ry + ¼ rx – rx ry
2 2 2
P1i = ry – rx ry + ¼ rx --- 6

With the above process, we can complete region-1. When absolute of slope becomes 1,
the region 1 is finished and the region 2 gets started. In region 2, the y coordinate is
decremented in unit steps. Let us calculate, parametric equations in region 2. The point
(xi, yi) is drawn. The next point can be either (xi, yI - 1) or (xi + 1, yi – 1). The decision
parameter is calculated as,

P2i = fellipse (xi + ½, yi – 1)


2 2 2 2
P2i = ry (xi + ½) + rx (yi – 1)2 – rx ry --- 7
2 2 2 2 2 2
P2i+1 = ry (xi+1 + ½) + rx (yi+1 – 1) – rx ry
2 2 2 2 2 2
P2i+1 = ry (xi+1 + ½) + rx (yi – 2) – rx ry --- 8

The equation 8 – 7 gives,


2 2 2 2 2 2
P2i+1 – P2i = ry [(xi+1 + ½) – (xi + ½) ] + rx [(yi – 2) – (yi – 1) ]
2 2 2 2 2 2
P2i+1 – P2i = ry [(xi+1 + ½) – (xi + ½) ] + rx [yi – 4yi + 4 – yi + 2yi
2 2 2 2
P2i+1 = P2i + ry [(xi+1 + ½) – (xi + ½) ] + rx (-2yi + 3) --- 9

If P2i is negative, then midpoint lies inside the circle.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
xi+1 = xi + 1
2 2 2 2
P2i+1 = P2i + ry [(xi + 3/2) – (xi + ½) ] + rx (-2yi + 3)
2 2 2 2
P2i+1 = P2i + ry [xi + 3xi + 9/4 – xi – xi – ¼] + rx (-2yi + 3)
2 2
P2i+1 = P2i + ry (2xi + 2) + rx (-2yi + 3) --- 10

If P2i is positive or zero, then midpoint is outside the ellipse or on the ellipse. xi+1 = xi
By putting this condition in eqn 9 we get,
2
P2i+1 = P2i + rx (-2yi + 3) --- 11

The P2i will be calculated from the last point of region-1.


2 2 2 2 2 2
P2i = ry (x2 + ½) + rx (y2 – 1) – rx ry --- 12

Algorithm –
The overall process can be summarized in steps as follows,
1) Read the coordinates (xc, yc) and also read rx and ry.
2) Calculate the initial value of parameter in region 1.
2 2 2
Pi  ry – rx ry + (1/4) rx
3) Select the first point for display as (0, ry) i.e. x = 0, y = ry
4) Calculate slope as
2 2
- (ry x / rx y)
5) Repeat steps 6, 7, 8, 9 while (abs (slope) < 1)
6) Call display routine
2
7) If P1 < 0 Then P1  P1 + ry (2x + 3)
Else
Begin
2 2
P1  P1 + ry (2x + 3) + rx (-2y + 2)
yy–1
end
8) Increment x in unit steps as x  x + 1
2 2
9) Update the slope as – (ry x / rx y)
10) Calculate the decision parameter for region 2
2 2 2 2 2 2
P2  ry (x + ½) + rx (y – 1) – rx ry
11) Repeat steps 12, 13, 14 while (y > = 0)
12) Call display routine
13) If P2 < 0 Then
Begin
2 2
P2  P2 + ry (2x+2) + rx (3-2y)
x  x+1
end
2
Else P2  P2 + rx (3-2y)

Boundary – Fill Algorithm –

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
An area can be filled, by starting at a point inside the figure and painting the interior in a
specified color or intensity. The painting proceeds until the figure’s boundary is
encountered. This method is called as Boundary – fill algorithm.

A boundary-fill algorithm accepts the interior coordinate point (x, y) accepts the fill color
and boundary color, as input parameters. Starting from the given interior point, four
neighbouring points are tested. These points are above, below, right and left to the
starting point. Areas filled by this method are called as 4-connected areas.

The boundary-fill algorithm can also be implemented using 8-connected areas. In this
case, alongwith four neighbouring pixels, four diagonal pixels are also tested.

[DIAGRAM]
4-connected areas 8-connected areas

The algorithm can be written in recursive manner. If the neighbouring point is not having
boundary color as well as not having the fill color, then that point is painted with a fill
color. The recursive procedure is written as shown below.
void boundary-fill (int x, int y, int fc, int bc)
{ int pc;
pc = getcolor (x, y);
if ( (pc ! = bc)& & (pc ! = fc) )
{ putpixel (x, y, fc);
boundary-fill (x+1, y, fc, bc);
boundary-fill (x-1, y, fc, bc);
boundary-fill (x, y+1, fc, bc);
boundary-fill (x, y-1, fc, bc);

Flood-fill algorithm-
Sometimes, an area is not defined with a single color boundary. In the
given diagram, the area is surrounded by areas of different colors. Thus,
the boundary color is not unique. Such areas are filled by replacing the old
color by new color instead of checking boundary colors. This approach is
called as flood-fill algorithm. The algorithm starts from a given interior
point 9x, y) and uses either 4-connected or 8-connected areas method. If
the neighbouring points are of old color, then these points are recolored
with flood color. The flood-fill algorithm when reaches towards any
boundary of any other color, then algorithm finds, that the point is of some
different color and hence it is not required to be recolored. The algorithm
can be written recursively as follows,
void flood-fill (int x, int y, int fc, int oc)
{

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
if (oc = = getcolor (x, y) )
{ putpixel (x, y, fc);
flood-fill (x+1, y, fc, oc);
flood-fill (x-1, y, fc, oc);
flood-fill (x, y+1, fc, oc);
flood-fill (x, y-1, fc, oc);
}
}

 Both the algorithms are recursive and these algorithms works only for small areas.
 These algorithms can also be made non-recursive, but then the logic is slightly
complicated than recursive algorithms.

Text Generation –
Letters, numbers, digits and other special symbols can be displayed in variety of sizes
and styles. The overall design style for a set of characters is called as typeface. The
typeface and font are used interchangeably. The typefaces can be divided into two broad
groups as serif and sans-serif. The serif type has small lines called as accents at the
ends of main character strokes. The sans-serif font does not have accents.
 The text in serif font can be like ABCDEF.
 The text in sans-serif font can be like ABCDEF.

Two different representations are used for storing fonts. A simple method to represent
character fonts is to use rectangular grid patterns. The sets of character shapes are
referred as bitmap fonts.

Another method to describe the character shapes in particular font, is using straight lines
or curve sections. In this case, set of characters is called as outline font. To display
characters in outline form, the interior of the character outline is to be filled using some
algorithm.

Bit map fonts are simplest to define and display. The character grid is to be mapped to a
frame buffer position. the bit map fonts can be used to display the characters in different
styles and sizes.

Text Attributes –
The appearance of the characters can be changed by changing the attributes of the
characters. The attributes can be defined as font, size, color and orientation. Attributes
can be set for a single character or group of characters.

There are no. of fonts which are developed for displaying characters, such as Times New
Roman, New York, Courier, Wild Latin, Algerian, Arial etc. These characters can be
displayed with different styles as, italics, boldface, underline. Every graphics package

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
provides these types of facilities. The characters can also be displayed in different sizes
as,
CG, CG, CG,CG,CG,CG

2.7 Bezier Curves -


This method of constructing curves was developed by the French
Engineer Bezier. For any given set of control points, an approximate curve
is formed by adding sequence of polynomial functions, which are formed
from the coordinates of the control points.
The curve is formed by accepting n+1 control points. These points are represented as Pk
(xk, yk, zk) for k varying from a to n. Using these points, the Bezier function p(u) is
calculated as,

n
p (u )   Pk . Bk , n (u )
k  0

where,

n!
Bk , n ( u )  c ( n , k ).u k (1  u ) n  k andc n , k 
k ! ( n  k )!

The equation 1 can be written as,

n
x(u)   xk .Bk , n (u)
k 0
n
y(u )   yk .Bk , n (u )
k 0
n
z (u )   zk .Bk , n (u )
k 0

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
The polynomials Bk,n (u) are called as Blending functions. This is because, these
functions blend (mix) the control points to form composite function. The blending
functions will be polynomials of degree n, if n+1 control points are given.

If the curves are restricted on xy plane for z = 0 then z(u) = 0. The Bezier curve always
lies inside the CONVEX HULL represented by central points. The following diagrams
represents different curves alongwith convex hull represented with dotted lines.

If the curve is defined by 4 points, it means that n+1 = 4. Hence n = 3. In this case, k will
be varying from 0 to 3. Thus, there will be 4 Blending functions as, B0,3(u), B1,3(u), B2,3(u)
and B3,3(u). All these functions can be calculated using Bk,n(u).

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
n
Since , P (u )   Pk .B k ,n (u )
k  0
it means that, while defining the curve, all the blending functions are used and hence all
of them have some effect to determine each point on the curve. For different ranges of u,
different blending functions are dominent than other blending functions. This feature
provides facility of localized control over the curve.

2.8 B-Spline Curves –


The spline is a flexible strip, used to produce the smooth curve, through set of given
points. In B-spline curve, n+1 control points are given. These points are denoted as Pk

n
P (u )   Pk . N k , t ( u )
k 0
(xk, yk, zk), where k varies from 0 to n. the B-spline curve can then be defined as,

Where, Nk,t(u) can be defined as polynomials of degree t-1. A polynomial form of the
blending function can be defined recursively, over various sub-intervals of range of u.
This range depends on n and t. The u varies from 0 to n – t + 2.

 The blending functions are recursively defined as,


Nk,t = 1 if uk  u < uk+1
=0 otherwise

u  uk ukt  u
N k ,t (u )  N k ,t 1 (u )  N k  1,t 1 (u )
u k  t 1  u k u k  t  u k 1

 Any term divided by 0 in above calculation is assumed as zero.


 The positions uj are defined as break-points. The break-points are defined as follows,

 0 ifj  t

u j   j  t  1 ift  j  n
 n  t  2 ifj  n

 The j varies from 0 to n + t.
 Using the recursive blending functions and by putting proper values of uj, the
Blending functions Nk,t(u) are evaluated with respect to u.
 Let us take 5 control points. n + 1 = 5 n=4

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Let us take t = 3. The typical blending functions are defined as follows,
u varies from 0 to n – t + 2 i.e. 0 to 4 – 3 + 2 i.e. 0 to 3.
j varies from 0 to 4 + 3 i.e. 0 to 7.
u0 = 0, u1 = 0, u2 = 0
u3 = 1, u4 = 2
u5 = 3, u6 = 3, u7 = 3

Using these break-points, the blending functions are plotted with respect to u.

2.9 Properties of Curves (Bezier as well as B-spline)


Following are the general properties of the curves.
1) Control Points – The shape of the curve is controlled by the location of control points.
If the curve passes through the control points, then they are called as knots. A curve
is said to interpolate, the control points if it passes through them. The curve often
remains within the CONVEX HULL, which is formed by joining control points.
2) Multiple Values – In general, a curve is not a graph of a single valued function of a
coordinate.

It means that f(x) can have two or more values for the same value of x. Similarly, f(y) can
have two or more values for the same value of y.

From the diagram, we can see that, at value y, there


1 11
are three different values of x on the curve as x , x
111
&x .
Similarly, at value x, there are two different values of
1 11
y on the curve as y and y .

3) Axis Independence – The shape of an object


must not change when control points are
measured in a different coordinate system. For
e.g. if the control points are rotated (means
coordinate axis is) by 90, the curve should
rotate by 90, but the shape will not change.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
4) Global or Local Control – When the designer manipulates (modifies) a particular
control point, then it may change the shape throughout, or a curve may change
shape only in the region near the control point. The first behaviour is called as global
control and the second behaviour is called as local control. The global control may be
annoying for designer if he is trying for fine adjustment.
5) Variation-diminishing property – Some mathematical functions used to determine the
curve are such, that curve oscillates heavily, whereas some mathematical functions
are such that curve goes smoothly. This is because, these functions have variation-
diminishing property. It means that, |f (uk+1) – f(uk)| decreases as k increases.

heavy-ascillations variasion-diminishing curve.

6) Versatility – A curve representation that allows limited variety of shapes can frustrate
designer. More flexible techniques allow the designer to control the versatility of a
curve, by adding or removing control points. For e.g. if two points are given and if we
get a line, then just by placing the third control point, number of additional shapes
can be achieved. Ore to control points more the accuracy.
Order of continuity – Usually, a complex shape is not modelled by a single curve, but by
several curves pieced together. Such joints are to achieve sharp corners. While creating
joints, designer will have options to control the order of continuity.



pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
5
* 20 GEOMETRIC TRANSFORMATION *
GEOMETRIC TRANSFORMATION  Matrices, scaling transformations, (sine & cos
rotation), homogeneous rotation & translation, Rotation about on arbitrary point, inverse
transformation.

1. Two Dimensional Transformation


1.1 Translation
1.2 Rotation
1.3 Scaling

2. Homogeneous Coordinates For


2.1 Translation
2.2 Rotation
2.3 Scaling

3. Rotation about an arbitrary point.

4. Reflection & shear.

5. Inverse Transformations.

1.1 TRANSLATION

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 Translation is a process of changing the position 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
1 1
the original co-ordinate position (x, y) to move the point to a new position (x , y ) as
shown in the figure above.
1
x = x + tx  1
1
y = y + ty  2
 The translation distance pair (tx, ty) is called a translation vector or shift vector.
 Equations 1 & 2 can be expressed in the form of following translation vector.
1
 x  1
 x   t x 
P    P    T   
 t
1
 y   y  y 
The 2 dimensional translation equations is the matrix form:
1
P +P+T

 x1   x  t x 
i .e .  1       
 y   y  t y 
Ex. Translate a polygon with co-ordinates A (2, 5), B (7, 10) and C (10, 2) by 3 units in x
direction and 4 units is y direction.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 2  3  5 
A1  A  T         
5   4  9 
7  3  10 
B1  B  T         
10   4  14 
10   3  13 
C1  C T         
2  4 6 
1.2 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 rotation angle 0 and the position of the
rotation about which the object is to be rotated.

 Let us consider the rotation of an object about the origin as shown in the fig. below.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 Here, r  constant distance of point from the origin,
  original angular position of point from horizontal.
  Rotation Angle.

  Using trignometary,
1
x = r cos( + ) = r cos  cos  - r sin  sin 
1
y = r sin ( + ) = r cos  sin  + r sin  cos   1
 The original co-ordinates are
x = r cos 
y = r sin   2

 Substituting 2 in 1, we get,
1
x = x cos  - y sin 
1
y = y sin  + y cos   3
 The above equations can be represented in the matrix form

1 1  cos  sin  
[ x y ]  [ xy ]  
  sin  cos  
1
 P  P .R
Where R  Rotation Matrix and it is given as

 cos  sin  
R    sin  cos   Note, For negative values of 0,
 

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 cos(   ) sin(   ) 
R   
  sin(   ) cos(   ) 
 cos   sin  
 R   
 sin  cos  
Ex. A point (4, 3) is rotated conter clockwise by an angle of 45. Find the rotation matrix
and the resultant point.
Sol.

 cos  sin    cos 45  sin 45  


R     sin 45  cos 45  
  sin  cos    
1 / 2 1 / 2 
 
  1 / 2 1 / 2 

1
1 / 2 1 2 
 P  [ 43 ]  
  1 / 2 1 2 
 [4 / 2 3/ 24/ 2  3 2]
 [1 / 27 / 2
1.3 SCALING
A scaling transformation changes the size of an object. This operation can be carried out
for polygons by multiplying the co-ordinate values (x, y) of each vertex by scaling factors
Sx and Sy to produce the transformed co-ordinates (x1, y1)
1
x = x.Sx
1
& y = y. Sy  1

Scaling factor Sx scales object in x direction and scaling factor Sy scales object in y
direction.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 The equation 1 can be written in matrix form as

S x 0
[ x 1 y 1 ]  [ xy ]  
0 S y 
 [ x .S x y .S y ]
 P .S
Values assigned to Sx & Sy that are less than 1, reduce the size of the object and values
greater than 1 enlarge the size of the object.

Ex. Scale a polygon with co-ordinates A (2, 5), B (7, 10), C (10, 2) by 2 units in x direction
& 2 units in y direction.
Soln. Here Sx = 2 & Sy = 2
Transformation matrix is given as

 20 
S   
 02 
Theobjectm atrixisA [ 25 ]
B [ 710 ]
C [ 102 ]
1 1 1  20 
 A  [ x 1 y 1 ]  [ 25 ]    [ 410 ]
 02 
1 1 1  20 
 B  [ x 2 y 2 ]  [ 710 ]    [ 1420 ]
 02 
1 1 1  20 
C  [ x 3 y 3 ]  [ 102 ]    [ 204 ]
 02 

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
2. HOOGENEOUS COORDINATES

 In design and picture formation process, many times we may require to perform
translation, rotations and scaling to fit the picture components into their proper
positions.
 Each of the basic transformation can be expressed in the general matrix form as
1
P = P . M1 + M2  1

1  10   tx 
ForTransla tionP  P     ty 
 01   
i .e . M 1  IdentityMa trix
M 2  Translatio nMatrix
1  cos  sin   0 
ForRotatio nP  P     
  sin  cos   0 
M 1  Rotational Matrix
M 2  0

1
 S x 0  0 
ForScaling P  P     
0 S y  0 
i .e . M 1  ScalingMat rix
M 2  0
 To produce a sequence of transformations with the above equations, we must
calculate the transformed co-ordinates are translated, then they are scaled and finally
rotated. But this sequential approach is not efficient.
 A more efficient approach is to combine sequence of transformations into one
transformation so that the final co-ordinate positions are obtained directly from the
initial co-ordinates. This eliminates the calculation of intermediate values.
 To achieve this we have to eliminate the matrix addition associated with the
translation terms in M2 of eqn 1.
 We have to represent matrix M1 as 3 x 3 matrix instead of 2 x 2 introducing an
additional demmy co-ordinate w. Here, points are specified by 3 numbers instead of
2.
 This co-ordinate system is called Homogeneous co-ordinate system and it allows us
to express all transformation equations as matrix multiplication.
 The homogeneous co-ordinate is represented as a triplet.
(Xw, Yw, W) where

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Xw Yw
x  & y 
W W
Each 2 dimensional position can be represented with homogeneous coordinate as (x,
y, 1)

Summary 
Homogeneous coordinates allow combined transformation, eliminating the calculation of
intermediate co-ordinate values and thus save required time for transformation and
memory required to store the intermediate coordinate values.

2.1 HOMOGENEOUS COORDINATES FOR TRANSLATION


The homogeneous co-ordinates for translation are

 100 
 
T   010 
txt y1
 
 100 
1 1  
 wehave [ x y 1 ]  [ xy 1 ]  010 
txt y1
 
 [ x  txy  ty 1 ]
2.2 HOMOGENEOUS COORDINATES FOR ROTATION
Homogeneous Coordinates for

 cos  sin  0 
RotationR    sin  cos  0 
 001 
 cos  sin  0 
 [ x y 1 ]  [ xy 1 ]   sin  cos  0 
1 1

 001 
[ x 1 y 1 1 ]  x cos   y sin  x sin   y cos  1 ]

2.3 HOMOGENEOUS COORDINATES FOR SCALING


Homogeneous Co-ordinates for scaling are

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 S x 00 
 
S   0 S y 0 
 001 
 
 S x 00 
1 1  
 [ x y 1 ]  [ xy 1 ]  0 S y 0 
 001 
 
 [ x . S x y . S y 1 ]
Note  In the above texts 2.1 to 2.3 the object matrix is written first and is then multiplied
by required transformation matrix. If we wish to write the transformation matrix first and
then the of object matrix we have to take the transpose of both the matrices and post
multiply the object matrix.

x1   10 t x   x 
 1  
i . e .  y    01 t y   y 
1   001   1 
   
Ex 1. Consider a square ABCD with co-ordinate position A (1, 1), B (3, 1), C (3, 3), & D(1,
3). Consider the centre position (2, 2). Perform the following transformations.
Reduce it to ½ its size with centre still at (2, 2)

The transformation is carried out in the following sequence.


1. Translate the square such that its centre coincides with origin.
2. Scale the square with respect to the origin.
3. Translate the square back to the original position.
Thus overall transformation matrices is formed by multiplication of 3 matrices.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 100   0 . 500   100 
T   010  S   00 . 50  T
   010 
D   2 
  2  21   001   221 
 100   0 . 500   100 
 T . S .T   010  .  00 . 50  .  010 
1 2      
  2  21   001   221 
 0 . 500   100 
  00 . 50   010 
   
  1  11   221 
 0 . 500 
  00 . 50 
 
 111 
 0 . 500 
A 1
 A .[ T 1 S .T 2 ]  [ 111 ]  00 . 50 

 111 
A 1  [ 1 . 51 . 51 ]
 0 . 500 
B 1
 B .[ T 1 . S .T 2 ]  [ 311 ]  00 . 50 

 111 
1
B  [ 2 . 51 . 51 ]
 0 . 500 
C 1
 C .[ T 1 . S .T 2 ]  [ 331 ]  00 . 50 

 111 
1
C  [ 2 . 52 . 51 ]
 0 . 500 
D 1
 D .[ T 1 . S .T 2 ]  [ 131 ]  00 . 50 

 111 
 [ 1 . 52 . 51 ]
1 1
 A  ( 1 . 5 ,1 . 5 ) C  ( 2 .5 ,2 .5 )
1
B  ( 2 .5 ,2 .5 ) D 1  (1 . 5 , 2 . 5 )

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
2. Give a 3 x 3 homogeneous coordinate transformation matrix for each of the following
translations.
a) Shift the image to the right 3 unit
b) Shift the image up 2 unit
c) Move the image down ½ unit and right 1 unit.
d) Move the image down 2/3 unit and left 4 units.

Soln. Homogeneous Co-ordinates for translation are

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 100 
T   010 
 
 txty 1 
a ) Heretx  3 , ty  0
 100 
 T   010 
 
 301 

b ) Heretx  0 , ty  2
 100 
 T   010 
 
 021 

c ) Herety   0 . 5 , tx  1
 100 
T   010 
 
 10 . 51 

d ) Heretx   4 , ty  0 . 66
 100 
T   010 
 
  40 . 661 

3. Find the transformation of a triangle A(1,0), B(0,1), C(1,1) by


a) Rotating 45 about the origin and translating one unit in x & y direction.
b) Translating one unit in x and y direction and then rotating 45 about the origin.
Soln.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
The Rotation matrix is

 cos 45 sin 450 


R    sin 45 cos 450 
 
 001 
 1 / 2 1 / 2 0 
 
 R    1 / 2 1 / 2 0  &
 001 
 
Translatio nmatrixis
 100 
T   010 
 
 111 
 1 / 2 1 / 2 0   100 
 
a )  R .T    1 / 2 1 / 2 0   010 
 
 001   111
   
 1 / 2 1 / 2 0 
 
   1 / 2 1 / 2 0 
 111 
 
1
 A  A .[ R .T ]
 1 / 2 1 / 2 0 
 
 [ 101 ]   1 / 2 1 / 2 0 
 111 
 
 1 1 
   1  11 
 2 2 
1  1 1  1  1 1 
 A    1 ,  1  , B     1 ,  1 
 2 2   2 2 
1
C  (1 , 2  1 )

 100   1 / 2 1 / 2 0 
b ) T . R   010  .   1 / 2 1 / 2

0 
  
 111   001 
 
 1 / 2 1 / 2 0 
 
   1 / 2 1 / 2 0 
 
 0 2 1 
1
 A  A .[ T . R ]
 1 / 2 1 / 2 0 
 
 [ 101 ]   1 / 2 1 / 2 0 
 
 0 2 1 
 [1 / 2 3 / 2 1 ]
1
 A  (1 / 2 , 3 / 2 )

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
1
B  B .[ T . R ]
1 / 21 / 2 0 
 
 [ 011 ]   1 / 21 / 2 0 
 
 0 2 1 
 [ 1 / 2 3 / 2 1]
1
 B  ( 1 / 2 ,3 / 2 )
1
C  C .[ T . R .]
1 / 2 1 / 2 0 
 
 [ 111 ]  1 / 2 1 / 2 0 
 
 0 2 1 
 [ 02 / 2 1]
1
 C  (0 ,2 2 )
3. Rotation about an arbitrary point
To rotate an object about an arbitrary point we have to carry out 3 steps.
1. Translate point (xp, yp) to origin
2. Rotate it about the origin.
3. Finally, translate the centre of rotation back where it belongs.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
1. The translation matrix to move point (xp, yp) to the origin is

 100 
T 1   010 

  xp  yp 1 

2. The rotation matrix for counter clockwise rotation of point below the origin is

 cos  sin  0 
R    sin  cos  0 
 001 

3. The translation matrix to move the centre point back to its original position is given as

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
100 
T 2   010 
 xpyp 1
Therefore, the overall transformation matrix for a counter clockwise rotation by an angle
& about the point (xp, yp) is given as

100  cos sin  0  100 


T1.R.T2  010   sin cos 0 010 
  
 xp  yp1 001   xpyp1
cos sin 0 
  sin  cos 0 

 xp cos  yp sin  xp  xp sin   yp cos  yp1
Ex. 1. Perform a counterclockwise 45 rotation of triangle A(2,3), B(5,5), C(4,3) about
point (1,1)

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Soln. Here xp = 1, yp = 1  = 45

 100   100 
T1   010  , T   010
 2 


  1  11   111 
1 / 21 / 2 0  We have
 cos 45 sin 450 
 
R    sin 45 cos 450    1 /
  2 1 / 2 0 
 001  
 001


the standard formula.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 cos  sin  0 
T 1 . R .T 2    sin  cos  0 

  xp cos   yp sin   xp  xp sin   yp cos   yp 1 
 Substituti ngvalueswe get ,
1 / 21 / 2 0 
 
T 1 . R .T 2   1 / 21 / 2 0 
 
  1 2  1 / 2  1 / 2  1 / 2  11 
1 / 21 / 2 0 
 
  1 / 2 1 / 2 0 
 
 1  2  11 
1
 A  A .[ T 1 . R . T 2 ]
1 / 2 1 / 2 0 
 
 [ 231 ]  1 / 21 / 2 0 
 
 1  2  11 
 3 3 
  2   1 2   2  11 
 2 2 
1  1 3 
 A     1 ,1  
 2 2 

1
B  B [ T 1 . R .T 2 ]
1 / 2 1 / 2 0 
 
 [ 551 ]  1 / 21 / 2 0 
 
 1  2  11 
 5 5 5 5 
    1   2  11 
 2 2 2 2 
1  8 
 B   1,  1 
 2 
1
C  C [ T 1 . R .T 2 ]
1 / 2 1 / 2 0 
 
 1 / 21 / 2 0 
 [ 431 ]  
 1 / 21 / 2 0 
1  2  11 
 
 4 3 4 3 
    1   2  11 
 2 2 2 2 
 1 5 
   11  1
 2 2 
1  1 5 
C    1,  1 
 2 2 

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
4. REFLECTION & SHEAR
Besides the 3 basic transformations, there are some other transformations which are
useful in certain applications. Two such transformations are Reflection & Shear.

4.1 REFLECTION
 A reflection is a transformation that produces a mirror image of an object relative to
an axis of reflection.
 We can choose an axis of reflection in the xy plane or perpendicular to the xy plane.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
COMMON REFLECTIONS

4.2 SHEAR
 A transformation that slants the shape of an object is called the shear transformation.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 Two common sharing transformations are used.
One shift x co-ordinate values and other shifts y co-ordinate values. In both cases
only one co-ordinate (x or y) changes its co-ordinate while the other preserves it.

4.2.1 X SHEAR
The x shear preserves the y coordinate but changes the x values which causes vertical
lines to the left or right as shown below. The transformation matrix for x shear is given as

4.2.2 Y SHEAR
The Y shear preserves the x co-ordinate, but changes the y values which causes
horizontal lines to transform into lines which slope up as down as shown in figure. The
transformation matrix for y shear is given as

1Shy 0
 
Y _ sh  010 
001 
 
 X1  X &
y1  y  Ysh.X

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
4.2.3 Shearing Relative to other Reference Line
We can apply x shear & y shear transformations relative to other reference lines. In x
shear transformation we can use y reference line & in y shear transformation we can use
x reference line.
Transformation matrices are

Ex. 1. Apply the shearing transformation to square with A(0,0), B(1,0), C(1,1), D(0,1) as
below.
a) Shear parameter value of 0.5 relative to line yref = -1
b) Shear parameter of 0.5 relative to line xref = -1.

 100 
 
Xshearwith yreference line   Sh x 10 
  sh x . y ref 01 

 1 Sh y 0 
 
yshearwith xreference line   010 
 0  Sh y x ref 1 

a) Soln. Here Shx = 0.5 and yref = -1

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
1
 A  A
1
B  B
1
C  C
 100 
1  
D  D  Sh 10 
  Sh x .Y ref 01 
 
 001 
 101   100 
    0 . 510 
 111   
   0 . 501 
 011 
A 1  [ 0 . 501 ]
1
B  [ 1 . 500 ]
1
C  [ 211 ]
1
D  111 ]

1 1
 A  ( 0 .5 ,0 ) C  ( 2 ,1 )
1 1
B  (1 . 5 , 0 ) D  ( 1 ,1 )

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
b) Here Shy = 0.5 and Xref = -1

1
 A   A 
 1  B   1 Shy 0 
 B     
 C 1  
 C   010 
     0  Sh y X ref 1 

 D 1
  D 
 001 
 101   10 . 50 
    0 . 510 
 111   
   0 . 50 . 51 
 011 
 00 . 51 
 111 
  
 121 
 
 01 . 51 
1
 A  ( 0 , 0 . 5 )
1
B  ( 1 ,1 )
1
C  (1 , 2 )
1
D  ( 0 ,1 . 5 )

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
NOTE:- It is important to note that shearing operations can be expressed as sequence of
basic transformations. The sequence of basic transformation involves series of rotation
and scaling transformation.

Ex. Show how shear transformation may be expressed in terms of rotation & scaling.
Soln.
 The shear transformation matrix for x and y can be combinely given as

 1 Shy 0 
  Shx 10 

 001 
 We have the scaling and rotation matrix as

 S x 00   cos  sin  0 
     sin
S   0 S y 0  R    cos  0 
 001


  001 
 If we combine scale matrix & rotation matrix we have

 S x Cos  S x Sin  0 
 
S . R    S y Sin  S y Cos  0 
 001 
 
Comparing shear matrix & S. R. matrix we have
Shx = - Sy Sin 
Shy = Sx Sin 
SxCos = 1
SyCos = 1

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
1
 Sx  and
cos 
1
S y 
cos 
Substituting values for Sx & Sy we get,

 1
Sh x  Sin    tan 
cos 
1
Sh y  Sin   tan 
cos 
The shear transformation matrix expressed in terms of rotation & scales is

 1 tan  0 
  tan  10 
 
 001 
 S x Cos   S y Cos   1
  AngleofRot ation
S x  xscale
S y  yscale



pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
6
2-D VIEWING
Viewing pipeline, viewing co-ordinates reference frame, window to view part co-ordinate
transformation, 2-D viewing function, clipping operations, port clipping, line dipping,
Sutherland / Cohens line clipping algo, polygon clipping algo, Sutherland/Hodgeman
polygon clipping algorithm.

 We can use variety of transformations like scaling, rotation, reflection etc to generate
a variety of different views of a single picture e.g. a map, or any other picture.

1. In a map, we might be interested in the northern region only, in such a case we need
some method do display only those portions of the drawing that are of immediate
interest. This gives the effect of looking at the image through a window.
The process of selecting and viewing the picture is called windowing.

2. CLIPPING
The remaining portion which are not of immediate interest must not be visible. The
technique to do so is called ‘CLIPPING’
The process of discarding the portion of a picture which is outside the window (in
which we are not interested) is called CLIPPING.

3. VIEWING TRANSFORMATION
 A picture is stored in the computer memory in WCS WORLD CO-ORDINATE
SYSTEM.
 However when the picture is displayed on the display device it is measured in
physical device co-ordinate system (PDCS) corresponding to the display device.
 Therefore displaying an image of a picture involves mapping the co-ordinates of the
points and lines that form the picture into the appropriate physical device coordinate
where the image is to be displayed. This mapping of co-ordinates is achieved with
the use of co-ordinate transformation known as viewing transformation i.e. the
viewing transformation maps picture co-ordinate in the WCS to display coordinates in
PDCS.

4. The Viewing Pipeline


 If an object is too complex to be shown entirely or we are particularly interested in
just a portion of it, we would like to imagine a box about a portion of the object and
display what is enclosed in the box. Such a box is called Window.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 In terms of co-ordinates it refers to the World Co-ordinate area for display.
 When we change the window parts of the object at the same position on display.
 It might happen that we don’t wish to use the entire screen for display, we would like
to image a box on the screen and have the image confined to that screen. Such a
box on the screen is called Viewport.
 An area on the display device / screen to which a window is mapped is called
Viewport.
 A window defines what is to be viewed and the viewport defines where it is to be
displayed.

5. Relation between the window co-ordinate and viewport co-ordinate


 Once we know the extend of the image in the window, we need to defiune or select
the extend of the viewport.
 While transforming the description from the window to the viewport we have to
maintain a relative placement of the object i.e. if a co-ordinate position is at the centre
of a window, it should be displayed at the centre of the viewport.

Xv  Xv min Xw  Xw min

Xv max  Xv min Xw max  Wx min
 The window defined is the world co-ordinate is transformed to viewport co-ordinates
by performing the following steps.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
1) The part of the object to be displayed is selected in the window.

2) The object together with its window is translated until the lower left corner of the
window is at the origin.

3) The object and the window are scaled until the window has the dimensions of the
viewport.

4) Translate the viewport to its correct position in the screen

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
The transformation is given as
W = T.S.T1

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
100 
T   010 

  X w min  Y w min 1
 S x 00 
 
S  0 S y 0
 001 
 
X v max  X v min
Sx 
X w max  X w min
Y v max  Y v min
Sy 
Y w max  Y w min
100 

T1   010 

 X v min Y v min 1
100   S x 00  100 
 
W  T .S .T1   010  0 S 0  010
 y 


  X w min  Y w min 1  001   X v min Y v min 1
 

 S x 00 
 
 0 S y 0 
X 
 v min  X w min S x Y v min  Y w min S y 1

6. 2D CLIPPING

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 The portion of the picture inside the window should be displayed and the other areas
should not be displayed. The technique used to do so is called CLIPPING.
 The process allowing the unwanted / invisible portion of the picture to be discarded is
called CLIPPING.
 The clipping algorithm determines which points, lines or portions of the lines be within
the window. These lines are retained for display. All others are discarded.

7. POINT CLIPPING
 The points are said to be interior to the clipping window if
Xwmin  X  Xwmax and
Ywmin  Y  Ywmax
The equal sign indicates that points on the window boundary are induced within the
window.

6. LINE CLIPPING
 The lines are said to be interior to the clipping window & hence visible if both end
points are interior to the window.
 If both the endpoints are completely to the right, left, above or below the window,
then the line is completely exterior to the window & hence invisible.
 If both endpoints of line are outside the window the line is not necessarily completely
outside.
 It requires the calculation of intersection points to decide the visible portion of them.
All this is done by following certain algorithms.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
SUTHERLAND & COHEN SUBDIVISION LINE CLIPPING ALGORITHM

 It is one of the oldest and most popular line clipping algorithm developed by Dan
Cohen and Ivan Sutherland.
 This algorithm uses a four digit (but) code to indicate which of the nine regions
contain the end points of line. The four bit codes are called region codes or outcodes.

 Once we have established the region codes for all the line endpoints we can
determine which lines are completely inside the clipping window & which are clearly
outside.
 This is done through logical AND operations. If the result of AND operation is not
0000, the line is completely outside the clipping region and if both points are inside
the window the line is completely outside & is visible.
 The lines which cannot be identified as completely inside or outside the window by
these tests are checked for intersection with window boundaries.

e.g. Consider the clipping window & the lines shown in fig below. Find the region codes
for each point & identify whether the line is completely visible, partially visible or
completely invisible.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Line Line Point Codes Logical AND Result
P1P2 0000 0000 0000 Comp. Visible
P3P4 0001 0001 0001 Comp. Invisible
P5P6 0001 0000 0000 Partially Visible
P7P8 0100 0010 0000 Partially Visible
P9P10 1000 0010 0000 Partially Visible

The Sutherland Cohen algorithm begins the clipping process for partially visible line by
comparing an outside endpoint to a clipping boundary to determine how much of the line
can be discarded. Then the remaining part of the line is checked against the other
boundaries & the process is continued until either the line is totally discarded as a section
is found inside the window.

a) The line P1P2 is partially visible.

b) Starting with P1, the intersection point P1 is found and we get


1 1
the 2 line segments P1-P1 & P1 -P2.

1
c) We know that for P1P1 one endpoint P1 is outside the window &
1
thus the line segment P1P1 is discarded. The line is now
1
reduced to the section from P1 to P2.

d) Since P2 is outside the window, it is checked again for


1
boundaries and intersection pt P2 is found. Again the line
1 1
segment is divided into 2 segments giving P1 P2 &P21P2.

1
e) For P2 P2 one endpoint P2 is outside the window & thus the
1
line segment P2 P2 is discarded. The remaining part of the
1 1
line segment P1 P2 is completely inside the clipping window
& hence made visible.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
The intersection points with a clipping boundary can be calculated using the slope
intercept form of the line equation. The equation for line passing through points
P1 (x1, y1) & P2 (x2, y2) is
Y = m(x – x1) + y1 or y = m(x – x2 ) + y2

y 2  y1
wherem  slopeoflin e
x 2  x1
SUTHERLAND & COHEN SUBDIVISION LINE CLIPPING ALGORITHM

1. Read the 2 line endpoints P1(x1, y1) P2(x2, y2)


2. Read the coordinates of window.
3. Assign region codes for nine region to find out which region has the end pts.
4. Check for visibility of line P1P2
a) If region codes for both endpoints are zero, then line is completely visible. Hence,
draw the line & go to step 9.
b) If the region codes for endpoints are not zero and logical ENDing of them is also
nonzero then the line is completely invisible so reject the line and go to step 9.
c) If the region codes for the 2 end points do not satisfy the above conditions a) & b)
then line is partially visible.
5. Determine the intersecting edge of the clipping window by inspecting the region
codes of 2 end points.
a) If the region codes for both the end points are non zero, find intersection points
1
P1 & P1 with boundary edges of clipping window with respect to point P1 & point
P2 respectively.
1
b) If region code for anyone end point is non zero then find intersection point P1 as
2
P2 with the boundary edge of the clipping window with respect to it.

6. Divide the line segments considering intersection points.


7. Reject the line segment if any one endpoint appears outside the clipping window.
8. Draw the remaining line segments.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
9. Stop.

9. POLYGON CLIPPING
 Polygon is a collection of lines. Therefore we might think that the line clipping can be
used directly for polygon clipping.
 However, when a closed polygon is clipped as a collection of lines with the line
clipping algorithm, the original closed polygon becomes one or more open polygon or
discrete lines. Thus we need to modify the line clipping algorithm to clip to clip
polygon.

 We consider a polygon as a closed solid area. Hence after clipping it should remain
closed. To achieve this we require an algorithm that will generate additional line
segment which make the polygon as a closed area.

 The lines a-b, c-d, d-e, f-g, g-h, I-j are added to polygon description to make it closed.

SUTHERLAND – HODGEMAN POLYGON CLIPPING


 A polygon can be clipped by processing its boundary as a whole against each
window edge. This is achieved by processing all polygon vertices against each clip
rectangle boundary is turn.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 Beginning with the original set of polygon vertices, we could first clip the polygon
against the left rectangle boundary to produce a new sequence of vertices.
 The new set of vertices could then be successively passed to a right boundary
clipper, a top boundary clipper & a bottom boundary clipper as shown in fig.

 At each step a new set of polygon vertices is generated and passed to the next
window boundary clipper. This is the fundamental idea in the Sutherland Hodgeman
algorithm.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 The output algorithm is a list of polygon vertices all of which are on the visible side of
the clipping plane. This is achieved by processing 2 vertices of each edge of the
polygon around the clipping boundary or plane.

1. If the first vertex of the edge is outside, the window boundary and the second vertex
of the edge is inside then intersection point of the polygon edge with the window
boundary & the second vertex are added to the output vertex list.
[DIAGRAM]

2. If both the vertices of the edge are inside the window boundary, only the second
vertex is added to the output vertex list.
3.

st
4. If the 1 vertex of the edge is inside the window boundary and the second vertex of
the edge is outside, only the edge intersection with the window boundary is added to
the output vertex list.

5. If both the vertices of the edges are outside the window boundary nothing is added to
the output list.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 Once all the vertices are processed for one clip window boundary, the output list of
the vertices is clipped against the next window boundary.
 Going through the above 4 cases we can realize that there are two key processes in
this algorithm.
1. Determining the visibility of a point or vertex (Inside – Outside Text) &
2. Determining the intersection of the polygon edge and the clipping plane.

Sutherland Hodgeman Clipping Algorithm

1. Read co-ordinates of all vertices of the polygon.


2. Read co-ordinates of the clipping window.
3. Consider the left edge of the window.
4. Compare the vertices of each edge of the polygon, individually with the clipping
plane.
5. Save the resulting intersections & vertices in the new list of vertices according to 4
possible relationships between the edge and the clipping boundary.
6. Repeat the steps 4 & 5 for remaining edges of the clipping window. Each time the
resultant list of vertices is successively passed to process the next edge of the
clipping window.
7. Stop.

CURVE GENERATION TECHNIQUES

There are 2 approaches to draw curved lines.


1) The first approach lies the Curve Generation Algorithms line mid-point circle to
midpoint ellipse algorithm to draw curved lines.
In this case only true curves can be drawn.
2) In the second approach curved lines are approximated by a no of small straight line
segments with the help of interpolation techniques.

PROBLEMS IN TRUE CURVE GENERATION APROACH

1. To specify a curve we need more information than just end-points.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
2. Using this approach only true curves like circular or elliptical are can be generated
and is not suitable for drawing other curves like wings or human faces.

INTERPOLATION TECHNIQUES
1. Lagrange’s Interpolation technique
2. Bezier generation technique
3. B-Spline curve generation technique

In practice, we have to deal with some complex curves for which no direct mathematical
expression is available. Such curve can be drawn using approximation techniques.

 If we have a set of sample points of the unknown curve, then we can draw the
required curve by filling the region with known sample point by pieces of true curves
which pass through the sample points.
 The gap between the curve and rest of the sample points can be filling by calculation
co-ordinate values along the known curve and joining them by small straight line
segments as shown in the figure above.

1. LAGRANGE’S CURVE GENERATION TECHNIQUE


 The main task in this process is to find a suitable mathematical expression for the
known curve.
 There are polynomial, trignometric, exponential and other classes of function which
can be used to approximate the curve. But polynomial functions are preferred.
 Polynomial function in the parametric form is given as
x = fx (u)
y = fy (u)
z = fz (u)

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 We have to construct the function as sum of terms, one term for each sample point.

n
f x (u )   x i B i (u )
i 1
n
f y (u )   y i B i (u )
i 1
n
f z (u )   z i Bi (u )
i 1

Bi(u) is called the Blending function.


 For each value of parameter x the function Bi(u) tells how much the current sample
point affects the curve. In other words each sample point tries to pull the curve in its
own direction and the function Bi(u) gives the strength of the pull.
 In general the ith value of Blending function for other integer values is given as

(u  1)u (u  1)    [u  (i  3)][u  (i  1)]  [u  (i  n)]


Bi (u ) 
(i  1)(i  2)(i  3)  1(1)    (i  n)
 Using the Blending function, the expression for the curve passing through sample
points can be realised as:

x = x1B1(u) + x2B2(u) + x3B3(u) + - - - - - -


y = y1B1(u) + y2B2(u) + y3B3(u) + - - - - - -
z = z1B1(u) + z2B2(u) + z3B3(u) + - - - - - -

2. BEZIER CURVE GENERATION TECHNIQUE


 This is the second approach for curve generation developed by French Engineer
Pierre Bezier.
 Bezier curve can be filled into any no. of control points.
 The degree of polynomial of the Bezier curve is determined by the no. of control
points.
 As a rule, the degree of polynomial of the Bezier curve is one less than the no. of
control points.

Ex. 3 points generate a parabola, 4 points generate a cubic polynomial.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 Bezier curve has a no. of properties which makes it useful and convenient for curve
and surface design. It is widely used in CAD systems.
 We use the midpoint approach for Bezier Curve.

1) The lines joining the 4 connecting points (A, B, C, D) are determined (AB, BC, CD)
2) Then their midpoints (AB, BC, CD) are determined & connected by line segments.
3) Then their midpoints (ABC, BCD) are determined.
4) Finally, midpoints are connected and their midpoint ABCD is determined.

 The point ABCD, divides the Bezier curves into 2 sections. This makes point A, AB,
ABC & ABCD as the control points for first section and point ABCD, BCD, CD & D as
control points for second section.
 By considering the 2 sections separately, the curve is divided into 2 more sections,
thus we get 4 curves from the original Bezier Curve.
 This process can be repeated on the curve can be split into smaller sections until use
how sections so small that they can be replaced by straight lines.

3. B-SPLINE CURVE GENERATION TECHNIQUE


 Spline is a tool made of thin flexible strip of metal or rubber used by draftsmen to aid
in drawing curved lines.
 The continuous curve of B-spline is defined by control points.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 While the curve is shaped by control points, it may or may not pass through all
control points.
 We can write a general expression for the calculation of co-ordinate position along a
B spline curve in a Blending function formulation as

n
P  u   Pk Bk , d (u ) 2  d  n  1
k 0
Where
 Pk  i/p set of n+1 control points.
 Bk, d  B-Spline Blending function which is a polynomial of degree d – 1
 D can be any integer value between 2 & n + 1
 Blending functions for B-Spline curves are defined by Can – De – Boor recursion
formula.

u  uk u d u
Bk , d (u )  Bk , d  1(u )  k Bk 1 , d  1(u )
uk  d  1  uk u k  d  u k 1

COMPUTER ANIMATION

Q. 1. What is Computer Animation?


Ans. It is defined as a time sequence of visual changes.
In addition to changes in position of object by translation, scaling & rotation, computer
generated animation can display time variations in object size, colour, texture, etc.
Computer animation can also be generated by changing the camera parameters such as
position, orientation & focal length.

Q. 2. What is segmentation?
Ans. Segmentation is the process in which the image related information present in the
display file is divided into segments.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!


pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
7
INTRODUCTION TO 3D
3-D Coordinate System –

The figure shows three dimensional cartesian


coordinate system. This is called as right-handed
system because right-hand thumb points in
positive z direction. Most Graphics packages
utilises right-handed system. Another possible
arrangement is left handed system.

Right-Hand Coordinate System

 Put fingers around the z axis and the thumb


should point the positive direction of z axis.

Cylindrical –

In this system, vertical cylinder with


radius r is taken. The surface of the
constant z is horizontal plane which will
be parallel to x-y plane. The surface of
constant  is a vertical plane which
contains z axis. Then x, y and z are
given as,
x = cos , y = rsin , z = z

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Spherical –
The surface of constant r is a sphere. The
surface of constant  is a vertical plane
which contains z axis. The surface with
constant  is a cone which is having apex
at origin.
From the diagram,
x = rcossin  y = rsinsin z = rcos

3-D Display Techniques


To obtain a display of three dimensional scene, we must set a view plane or display
plane.

The object coordinates are transferred to the display


plane coordinates and are projected onto the display
plane.

Parallel Projection –

One method of generating a view of solid object is to project points on the object
surface along parallel lines onto the display planes. By selecting different viewing
positions, different visible points are mapped onto the display plane to obtain different two
dimensional views.

Let us take a 3D object and let us show the different two dimensional views on different
display planes.

The following diagram shows 3D object and its views from two different directions. The
diagram shows these directions and also the display planes.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Perspective Projection –
Another method for generating a view of three dimensional scene is to project points to
the display the plane along converging paths. In this method, the objects away from
viewing position are displayed smaller than the objects of some size which are near to
the viewing position.

In perspective projection, parallel lines in a scene are not parallel on the display plane.
This is more realistic, because that is how our eyes understands any scene.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Depth Cuing –
Knowing the depth information of the object is important, because from this information
we can decide which is front and which is back of the displayed object.

From dia-a, it is difficult to decide whether the object is like dia-b or dia-c.

In depth wing, the lines which are closer to view position are displayed with more
intensity and lines away from view position are displayed with decreasing intensity. Depth
cuing can be applied by deciding maximum and minimum intensity values.

Visible line and Surface identification –


The visible lines and surfaces can be identified by the algorithms. There are different
methods to give 3D effects. Display visible lines in different color or highlight them. Draw
non-visible lines as dashed lines or simply remove non-visible lines. Applying shading to
visible surfaces, also gives the appearance of removal of hidden lines without actually
removing them.

Surface Rendering – Realistic images can be obtained by shading different surfaces with
different intensities. Using Ray-Tracing, the shiny surfaces are displayed. The objects
can be shown as shiny, transparent by illuminating objects with different styles.

Cutway Views – The objects can be defined by hierarchical structures, so that, by cutting
the object into different pieces, the internal details of an object can be shown.

Viewing Pipeline –
The following figure shows the general steps to be followed for 3-D viewing of the object.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 The conversion of modeling coordinates of the object into the world coordinate
system is referred as Modeling Transformation.
 Once the object is transferred into the world coordinates, it will be then transferred
into viewing coordinates. The process used to carry it out is referred as viewing
transformation. The viewing coordinate system is used as a reference for specifying
observer’s position.
 The viewing coordinates available in 3D coordinate system are to be projected on 3D
projection plane. The process is called as projection transformation.
 The projection coordinates, are finally mapped to device coordinates using
Workstation transformation.

The Xw-Yw-Zw specifies the world coordinate system. The object to be viewed is as
shown.
The P0 (X0, Y0, Z0) in the world coordinate system specifies the origin of the viewing
coordinate system Xv-Yv-Zv.

Viewing Coordinates

Generating a view of an object in


three dimensions is similar to
photographing the object.
We can walk around the object and
take its picture from any angle, at
various distances and with camera
orientations.
Whatever appears in the viewfinder is
projected onto the flat film surface.
The size of the camera lens
determines which part of the object appear in the final picture. The ideas will be similar in
the 3D viewing system.

 A particular view of the object is selected by establishing the viewing coordinate


system. It is also called as view reference coordinate system. A view plane or
projection plane, is then set up perpendicular to the viewing Zv axis.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 A particular point P0 (X0, Y0, Z0) in the world coordinate system is selected as origin
of viewing coordinate system. The point P0 will then be nothing but the reference
point for viewing.
The object is then to be converted from world coordinate system to viewing
coordinate system, for projection.

Transformation from World Coordinates to Viewing Coordinates –


Before object details can be projected to the view plane, they must be transferred to
viewing coordinates. Conversion of object details from world to viewing coordinates is
equivalent to transformation that superimpose the viewing reference frame onto the world
frame.

This transformation will require sequence as,


1) Translate the view reference point to the origin of the world coordinate system.
2) 3-D rotation required to coincide xv-yv-zv with xw-yw-zw.
3) All the back rotations required to bring xv-yv-zv at its original orientation.
4) Back translation to bring xv-yv-zv at its original position.

 The first step will require translation with Tx = -x0, Ty = -y0 & Tz = -z0
 The second step will require Rx(x) followed by Ry() as that of in 3D rotation (chap –
7).
 The third step will require Ry(-) followed by Rx(-x) as that of in 3D rotation (chap –
7).
 The fourth step will require back translation with Tx = x0, Ty = y0 & Tz = Z0.

Projections – Once the world coordinates are converted into view coordinates then the
three dimensional object can be projected onto two dimensional plane (view plane).
There are two basic methods of projection.
a) Parallel Projection
b) Perspective Projection

Parallel Projection –

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
In parallel projection, coordinate positions are transformed to a view plane along the lines
which are parallel. A parallel projection can be defined with the projection vector Vp which
defines direction of projection lines.
If projection vector is perpendicular to view plane, then the parallel projection achieved is
called as orthographic parallel projection.

If projection vector is not perpendicular to view plane, then


oblique parallel projection is achieved.

The transformation equations for orthographic parallel projection are simple. If the view
plane is placed at position Zvp along the Zv axis then (x, y, z) in viewing coordinates is
transformed to projection coordinates as,
xp = x yp = y zp = zvp

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
1000 
0100 
 [ x p y p z p 1]  [ xyz1] 
0000 
 
00 z v p 1
However, original z coordinates are stored for depth information.

Oblique Parallel Projection –

In the diagram, x is the angle made by


projection vector from (x, y, z) to view plane.
The (x, y) is the point corresponding to (x, y, z)
if orthographic parallel projection would have
been done.
From the diagram,
xp = x + Lcos 
yp = y + Lsin 

Z L 1
and tan    
L Z tan 
1 1
 L  Z.  ZL1 whereL1 
tan  tan 
 xp  x  zL1 cos 
yp  y  zL1 sin 

Any parallel projection can be defined as,

1000 
0100 
[ X p Y p Z p 1]  [ xyz1] 
 L1 cos L1 sin  00
 
00 Z v p 1 
0
When orthographic projection is done,  = y0

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
1
 L1  0
tan 
 x p  x, y p  y, z p  z  conditionsfororthographic

 Perspective Projection – Following diagram shows the perspective projection from


projection reference point.

(The objects of same size at different distances from view planes produces different sizes
of projected images in perspective projection.)

To obtain perspective projection of three dimensional objects, we can transform points


along projection lines which meets project reference point Zprp along Zv axis and view
plane is placed at zvp.
The coordinate positions can be defined in
parametric equations along projection line.
1
x = x – xu
1
y = y – yu
1
z = z – (z-prp) u

1 1
The parameter u can take value from 0 to 1. When u = 0, then (x , y1, z ) = (x, y, z)
1 1 1
whereas when u = 1 then (x , y , z ) = (0, 0, zprp). The projection reference point lies on zv
axis. On the view plane, u will be given as,

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
z vp Z
u
z prp  Z
1 1 1
By substituting this value into the equation of x , y & z we get,

 z vp  z 
x1  x p  x  x  
 z prp  z 
 z prp  z  z vp  z 
 x 
 z prp  z 
z prp  z vp
x p  x.
z prp  z
Similarly,
z prp  z vp
y p  y.
z prp  z
and
z p  z vp

Thus projection point on the view plane can be calculated. The orthographic projections
are not affected by plane position because projection lines are parallel and are
perpendicular to view plane.

Oblique parallel projections are affected by position of view plane, because angle of
projection vector with view plane can change. The perspective projection is affected by
relative position of object and view plane.

Clipping- and 3D viewing –


An algorithm for three dimensional clipping identifies and saves all surface segments
within a view volume, for display an output device. The parts which are outside the view
volume are discarded. Clipping in 3-D is achieved by extending the ideas of two-
dimensional clipping.

Instead of clipping against 2-D window, clipping of object is done against the boundary
planes of the view volumes. Lines which are totally outside the volume boundary are
discarded. Lines which are completely inside the selected volume boundary, are
selected. Lines which are partially inside are intersected with the volume boundary
planes and the part which is inside the volume boundary is displayed.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Normalized view volumes for clipping & viewport clipping –
The rectangular parallelopiped in world coordinate system is mapped into the unit cube,
which is normalized view volume.

The normalized view volume is a region defined by the planes x = 0, x = 1, y = 0, z = 0, z


= 1.

The objects in the view volume in world coordinates are transformed to unit cube (volume
viewport).
The factors Dx, Dy and Dz are the ratios of the viewport and regular window view volume.

xv max  x v min y  y v min


Dx  D y  v max
x w max  x w min y w max  y w min
z v max  z v min
Dz 
z w max  z w min
where( xv min , y v min , z v min )  (0,0,0)
( xv max , y v max , z v max )  (1,1,1)
xv = xvmin + (xw_xwmin) Dx
yv = yvmin + (yw-ywmin) Dy
zv = zvmin + (zw-zwmin) Dz
(extension of 2D window to viewport clipping).

Lines and polygons in a scene are clipped against viewport boundaries with procedures
similar to two dimensions. The objects are now processed against planes instead of lines.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
The two dimensional concept of region codes can be extended to three dimensions.
Instead of 4 bit code, code of 6 bits will be developed. One bit for front of the unit volume
and one bit for the back of the unit volume. For each endpoint of the line the 6 bit code
will be developed.

The bits are as follows,


bit0 = 1 if x < xvmin (left)
bit1 = 1 if x > xvmax (right)
bit2 = 1 if y < yvmin (below)
bit3 = 1 if y > yvmax (above)
bit4 = 1 if z < zvmin (back)
bit5 = 1 if z > zvmax (front)

 If the endpoint is inside the clipping volume, then the code will be 000000.
 If both the endpoints has the codes as 000000, then the line is selected for display.
 If there is 1 at the same position in the two codes then the line is completely outside
the view volume and hence rejected.
 If the above conditions are not satisfied then the line is intersected with necessary
planes out of the 6 planes of the view volume.
 After intersection, the part of the line outside the view volume is discarded.

To find intersection of a line we will; use parametric equations. In Liang-Barshy algorithm,


any point (x, y, z) is specified in parametric equation form as follows.
x = x1 + (x2 – x1)u
y = y1 + (y2 – y1)u 0u1
z = z1 + (z2 – z1)u

Let us consider a case in which line is to be intersected with a plane say z = zvmin.

Then the value u is found as


z v min  z1
u
z 2  z1
If the value of u is not in the range of 0  u  1 then it means line is not intersecting with
the plane z = zvmin.

If value of u is between 0 and 1 then there exists intersection and intersecting point will
be given as follows.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
z  z1 
x  x1  ( x 2  x1 ) v min 
 z 2  z1 
z  z1 
y  y1  ( y 2  y1 ) v min 
 z 2  z1 
z  z v min .

 Similarly, intersections with remaining 5 planes can also be determined.




pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
8
VISIBILITY Z BUFFER ALGORITHM
While generating realistic graphics display, it is important to identify visible and invisible
parts of the scene. The algorithms used to identify this are called as visible surface
detection methods or hidden-surface elimination methods.

Visible surface detection algorithms are broadly classified according to the way of
working. The two different approaches are object-space methods or image-space
methods.

An object-space method compares the objects and parts of the object with each other
within the scene definition, to determine visible surfaces.

In an image-space method, visibility is decided pixel by pixel at each position on the


projection plane. Most of the algorithms are of image-space methods.

Plane equations –
In 3D applications, such as surface rendering, transformation, visible surface detection, it
is necessary to know plane equations.

The equation of the plane surface is given by,


Ax + By + Cz + D = 0
Where, (x, y, z) is any point on the plane. To know the above equation of the plane, we
must know A, B, C and D.

Let us take three points, (x1, y1, z1), (x2, y2, z2) and (x3, y3, z3) on the plane. These three
points will form simultaneous equations as,
Ax1 + By1 + Cz1 + D = 0
Ax2 + By2 + Cz2 + D = 0
Ax3 + By3 + Cz3 + D = 0

In the above equations, A, B, C and D are unknown. Let us rearrange the equations as,

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 A B c
   x1    y1    z1  1
D D D
 A B C 
  x 2    y 2    z 2  1
D D D
 A B C
  x 3    y 3    z 3  1
D D D
 1y1 z1 x1  1z1 x1 y1  1
 1y 2 z 2 x 2  1z 2 x2 y 2  1
A  1y 3 z 3 B x3  1z 3 C x3 y 3  1
   
D x1 y1 z1 D x1 y1 z1 D x1 y1 z1
x2 y 2 z 2 x2 y2 z 2 x2 y 2 z 2
x3 y 3 z 3 x3 y 3 z 3 x3 y 3 z 3
1 y1 z1 x 11z1 x1 y11 x1 y1 z1
 A  1 y 2 z 2  B  x 2 1z 2  C  x 2 y 2 1  D   x 2 y 2 z 2
1y3 z3 x3 1z 3 x3 y 3 1 x3 y 3 z 3

For any point, not on the plane with parameters A, B, C,


D, we have Ax + By + Cz + D  0
We can identify the point as either inside the plane or
outside the plane, accordint to sign.
If Ax + By + Cz + C < 0, the point (x, y, z) is inside the
surface
If Ax + By + Cz + D > 0, the point (x, y, z) is outside the
surface

These inequality tests are valid in right-handed cartesian system, provided the plane
parameters A, B, C and D are calculated using vertices selected in anticlockwise order,
when viewing the surface in an outside-to-inside direction.

BACK-FACE Detection –
This is a fast and simple object space method which is used for identifying the back faces
of the object. This method is based on the equation of the plane.
1 1
In right-handed coordinate system, of (x , y1, z ) is “inside” the given plane then,
1 1 1
Ax + By + Cz + D < 0

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
The equation of the plane is determined by taking three points on the plane in
anticlockwise direction when looking from “outside” to “inside”.

Consider the following diagram,

In right handed system, if viewing direction is along ‘-‘ve Zv axis, then C is the component
of normal to the surface which will be parallel to Z axis. if c < 0 then the Normal Vector
points away from view position, and hence it will be decided as back surface / back face.

In the above diagram, component C1 of N1 will be negative whereas component C2 of N2


will be positive and hence surface with normal N1 is a back-face and hence it is to be
removed while displaying. The surface with normal N2 is considered to be front-face and
hence it is to be displayed.

Depth-Buffer (z-buffer) method –


The depth buffer method is commonly used image-space method, used to detect the
visible surfaces. In this method, surface depths are compared at each pixel position on
the projection plane. This method is called as z-buffer method. This is because, usually,
he depth is measured from view plane along z-axis. Each surface of a scene is
processed separately, one point at a time across the surface.

Each point (x, y, z) on the surface


is converted to projection
coordinates (x, y) as shown in the
diagram. For every pixel (x, y) on
the view plane, object depths can
be compared by comparing z
values. The point with lowest
depth will be selected for display.

For this algorithm, two buffer


areas are required. One is used to
store depth values for each (x, y)

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
position and refresh buffer is used to store intensity values/color values for color systems
for each (x, y) position.

All the positions of the depth buffer are initialized with 1 and all the positions of the
refresh buffer are initialized with background intensity.

The steps of depth-buffer can be written as follows.

1. Initialize the depth buffer and refresh buffer so that for all the positions (x, y) on the
view plane,
depth (x, y) = 1 and refresh (x, y) = Ibackground
2. For each position on each surface, compare depth values to previously stored values
in the depth buffer to determine visibility.
 Calculate the z value for each (x, y) position on the surface.
 If z < depth (x, y) Then set depth (x, y)  z and
Set refresh (x, y)  Isurf (x, y)

Where, Ibackground is background intensity.

Isurf (x, y) is intensity of a point (x, y) on the surface. After all the surfaces have been
processed, the depth buffer contains the corresponding depth values for visible surfaces
and refresh buffer contains the corresponding intensity values for these surfaces.

Depth values for a position (x, y) are calculated from plane equation for each surface.

 Ax  By  D
Z
C

1
If the depth of position (x, y) has been determined to be z, then the depth z of the next
position along the same scan line i.e. (x+1, y) is obtained as,

 A( x  1)  By  D  Ax  By  D A
z1   
C C C
A
 z1  z 
C
Similarly, depth values for succeeding scan lines can be obtained as follows,

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 Ax  B( y  1)  D
z 11 
C
 Ax  By  D B
 z 11  
C C
B
 z 11  z 
C
Thus, successive values of depth on a particular surface can be calculated faster.



pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
9
COMPUTER ANIMATION
Computer Animations, design of animation sequence, Raster animations, morphing
motion specification, kinematics & dynamics.

The term computer animation generally refers to any time sequence of visual changes in
a scene.

In addition to changing object position with translations or rotations, a computer-


generated animation could display time variations in object size, colour, texture etc.

Computer animations can also be generated by changing camera parameters such as


position, orientation and focal length.

Segmentation:-
In practice, the image on the display screen is often composed of several pictures or
items of information.

E.g. We may wish to display an internal plan of the lining room. The plan may contain
various objects such as sofa set, T.V., show-case etc. each object has a set of attributes
such as size, colour & its position in the room.

We know that all the information about the image is stored in the display file. The display
file is divided into segments. Each segment corresponds to a component or object of the
overall display & it is associated with a set of attributes. Along with the attributes, the
segment is also associated with image transformation parameters such as scaling,
rotation, shear transformation etc.

The most common screen attributes of an object are shape, size, colour, position,
visibility etc. by setting the visible attribute of the segment, we can decide whether to
display or not.

When the visible attribute is set to 1, it is included in the active segment list & display file
interpreter processes it. Such a segment is called posted segment.

When the visible attribute of segment is D it is not included in the active segment list &
display file interpreter ships this segment. Such a segment is called unposted segment.

Design of an Animation Sequence

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
In general, an animation sequence is designed with the help of the following steps –
 Storyboard layout
 Object definition
 Key-frame specification
 Generation of in-between frames

Definition of frame :-
For frame-by-frame animation, each frame of the scene is separately generated and
stored later, the frames can be recorded on a film or they can be consecutively displayed
in “real-time playback” mode.

 The storyboard is an outline of the action. It defines the motion sequence as a set of
basic events that are to take place. Depending on the type of animation to be produced,
the storyboard would consist of a set of rough sketches or it could be a list of the basic
ideas for the motion.

 An object definition is given to each participant in the action. Objects can be defined in
terms of basic shapes such as polygons, circles, arc, spheres etc. In addition, the
associated movements of each object are specified along with the shape.

 A key frame is a detailed drawing of a scene at a certain time in the animation


sequence. Within each key frame, each object is positioned according to time for that
frame. More key frames are specified for complex motion than simple, slowly varying
motion.

 In-between frames are file intermediate frames between the key frames. The number
of in-between frames needed is determined by the media to be used to display the
animation. Film requires 24-frames per second and graphic sequences are refreshed at
the rate of 30 to 60 frames per second. Typically, time intervals for motion are set up so
that there are from 3 to 5 in between frames for each pair of key frames.

Raster Animations :-
On raster systems, we can generate real-time animations in limited applications using
raster operations. Raster systems store picture information as pixel patterns in the frame
buffer. Therefore, some simple transformations can be carried out rapidly by simply
moving rectangular arrays of stored pixel values from one location to another within the
frame buffer.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Translating an object from screen position (a) to position (b) by moving a rectangular
block of pixel values. Coordinate positions Pmin & Pmax specify the limits of the rectangular
block to be moved & P0 is the destination reference position.

Figure above illustrates translation performer as a block transfer of a raster area. The bit
setting in a rectangular area are copied as a block into another part of the raster. We
accomplish this translation by false reading pixel intensities from a specified rectangular
area of a raster into an array, then we copy the array back into the raster at the new
location. The original object could be erased by filling its rectangular area with
background intensities.

Morphing :-
Transformations of object shapes from one form to another is called morphing which is a
shortened form of metamorphosis. Morphing methods could be applied to any motion or
transition involving change of shape.

Given the key frames for an object transformation, we first adjust the object specification
in one of the frames so that the no. of polygon edges (or the no. of vertices) is same for
both frames.

An edge with vertex positions 1 & 2 in key frame K evolves into two connected edges in
key frame K+1.

for manufacturing a line segment in key frame k into two connected line segment
in key frame k+1.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Linear interpolation for transforming a triangle into a quadrilateral.

A straight line segment in key frame k is transformed into two line segments in key frame
k+1. Since key frame k+1 has an extra vertex, we add a vertex between vertices 1 & 2 in
key frame k to balance the no. of vertices (& edges) in the two key frames.

We can state general processing rules for equalizing key frames in terms of either the no.
of edges or the no. of vertices to be added to a key frame.

Rules for edges


Let Lk & Lk+1 denote line segments in consecutive frames.
1) Lmax = max (Lk, Lk+1)
Lmin = min (Lk, Lk+1)
2) Ne = Lmax mod Lmin
3) Ne = int (Lmax/Lmin)
Where Ne denotes the no. of edges to be divided.
Ns denotes the no. of sections.
4) The preprocessing is accomplished by dividing Ne (no. of edges) to Ns+1 sections.

Rules for vertices :-


Let Vk & Vk+1 denote the no. of vertices in the two consecutive frames.
1) Vmax = max (Vk, Vk+1)
Vmin = min (Vk, Vk+1)
2) Nes = (Vmax – 1) mod (Vmin – 1)
Nes  no. of line sections
3) Np = int (Vmax-1/Vmin-1)
Np  no. of points to be added.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
4) Preprocessing using vertex count is performed by adding the no. of points to the no.
of line sections.

Motion specifications:-
There are several ways in which the motions of objects can be specified in an animation
system.

1) Motion specifications can be given in terms of translation & rotation parameters i.e.
we specify the rotation angles & translation vectors. Then the geometric
transformation matrices are applied to transform coordinate positions.
2) We can use an approximating equation to specify certain kinds of motions.

Eg. We can approximate the path of a bouncing ball with damped rectified line curve.

y(x) = A | sin (wx+0) | e


where A  initial complitude
w  angular frequency
0  phase angle
k  damping constant
These methods can be used for simple user programmed animation sequences.

3) We can also construct animation sequences using kinematic or dynamic descriptions.


With a kinematic description, we specify the animation by giving motion parameters
(position, velocity & acceleration) without reference to the forces that cause the
motion.

Dynamic descriptions on the other hand require the specification of the forces that
produce the velocities & accelerations. Examples of forces affecting object motion include
electromagnetic, gravitational, friction & other mechanical forces.

Visibility:-
In a given set of 3D objects & viewing specifications, we wish to determine which lines or
surfaces of the object are visible, so that we can display only the visible lines or surfaces.
This process is known as hidden surface or hidden line elimination or visible surface
determination.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
Various algorithms are used to find the hidden lines or surface & visible lines or surfaces
to an observer located at a specified point in space. Eg. Back-face removal algorithm, Z-
buffer algorithm, warnockls algorithm etc.

Depth Buffer algorithm:-


 One of the simplest & commonly used image space approach to eliminate hidden
surface is the Z-buffer or depth buffer algorithm.
 This algorithm compares the surface depths at each pixel position on the projection
plane.
 The surface depths is measured from the new plane along the Z axis of a viewing
system.

 When the object description is converted to projection coordinates (x, y, z), each pixel
position on the view plane is specified by x & y coordinate & z value gives the depth
information.
 Thus object depths can be compared by comparing the z-values & hence the name z-
buffer algorithm.
 The implementation requires another buffer memory called z-buffer along with the
frame buffer memory required for raster display devices.
 The z-buffer is used to store depth values for each (x, y) position as surfaces are
processed & frame buffer stores the intensity values for each position.
 Initially, all positions in the depth-buffer are set to D (minimum depth) & the refresh
buffer (frame buffer) is initialized to the background intensity.
 Each surface listed in the polygon tables is then processed, one scan line at a time,
calculating the depth (z value) at each (x, y) pixel position.
 The calculated depth is compared to the value previously stored in the depth buffer at
that position. if the calculated depth is greater than the value stored in the depth buffer,
the new depth value is stored, & the surface intensity at that position is determined &
placed in the same xy location in frame buffer.


pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
10
GRAPHICS COMMANDS
Note:- The output screen is initially set with background colour while & the drawing color
(set color) is set to black.

1. putpixel ( );
 Putpixel plots a pixel in the specified color at a specified point.
 Syntax :-
putpixel (int x, int y, int color);
 eg:-
putpixel (300, 400m, 4);

2. line ( );
 line draws a line between two specified points.
 Syntax:
line (int x1, int y1, int x2, int y2);
 Eg :-
line (100, 100, 100, 200);

3. set line style ( );


 Set line style sets the current line style and width or pattern.
 Syntax :
setlinestyle (int linestyle, unsigned pattern, int thickness);
 eg :-
setlinestyle (3, 1, 1)
line (100, 100, 100, 200);

4. bar ( );
 bar draws a filled in rectangular, two dimensional bar.
 Syntax :
bar (int left, int top, int right, int bottom);
Parameters Meanings
left, top Rectangle’s upper left corner
right, bottom Rectangle’s lower right corner
 Eg :-
Bar (200, 200, 300, 300);

5. rectangle ( );
 Draw a rectangle in current line style, thickness & drawing color.
 Syntax :

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
rectangle (int left, int top, int right, int bottom);
 eg :-
rectangle (100, 100, 200, 300)

6. circle ( );
 Draw a circle in current drawing color.
 Syntax:-
circle (int x, int y, int radius);
Parameters Meanings
x, y centre coordinates
 eg :-
circle (400, 400, 20);

7. ellipse ( );
 ellipse draws an elliptical arc.
 Syntax:-
ellipse (int x, int y, int stangle, int endangle,
int x radius, int y radius);

Parameter Meaning
x, y center of ellipse
x radius Horizontal axis
y radius Vertical axis
stangle Starting angle
endangle Ending angle
 Eg:-
Ellipse (500, 200, 0, 300, 50, 20);

8. fillellipse ( );
 Draw an ellipse, then fills the ellipse with the current fill pattern.
 fillellipse (int x, int y, int x radius, int y radious);
 eg:
fillellipse (500, 200, 0, 360, 50, 20);

9. arc ( );
 Draws a circular arc in the current drawing color
 Syntax :
arc (int x, int y, int stangle, int endangle, int radius);
 eg:-
arc (100, 100, 300, 270, 40);

10. pieslice ( );
 Draws a pieslice in the current drawing color, then fills it using the current fill pattern
& fill colour.

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
 Syhntax :
pieslice (int x, int y, int stangle, int endangle, int radius);
 eg :-
pieslice (400, 200, 270, 360, 50);

11. floodfill ( );
 The area bounded by the color border is flooded with the current file pattern & fill
color.
 Syntax:
floodfill (int x, unt y, int border);
 eg :-
circle (400, 400, 20);
floodfill (400, 400, 14);

12. set fillstyle ( );


 Sets the current fill pattern & fill color
 Syntax:
setfillstyle (int pattern, int color);
 eg:-
setfillstyle (1, 4)
circle (400, 400, 20);

13. set color ( );


 setcolor sets the current drawing color.
 Syntax :
setcolor (int color);
 eg:
setcolor (4);
circle (400, 400, 20);

14. setbkcolor ( );
 Set the background color to the specified color.
 Syntax:
setbkcolor (int color);
 eg:-
setbkcolor (4);

15. Outtext xy ( );
 Display a text string in the viewport at the position (x, y)
 Syntax:
outtext xy (int x, int y, char text string);
 eg:- outtext xy (200, 300, “CONGRAGULATIONS”);

pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!
16. settextstyle ( );
 Sets the text font, direction in which text is displayed and
the size of the character
 Syntax :
settextstyle (int font, int direction, int char size);
 eg settextstyle (1, 1, 3);
outtextxy (200, 300, “CONGRATS”);



pdfMachine
A pdf writer that produces quality PDF files with ease!
Produce quality PDF files in seconds and preserve the integrity of your original documents. Compatible across
nearly all Windows platforms, simply open the document you want to convert, click “print”, select the
“Broadgun pdfMachine printer” and that’s it! Get yours now!

Você também pode gostar