0% found this document useful (0 votes)
12 views137 pages

CG 1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 137

Computer Graphics

Evaluation Pattern

In-Sem Exam : 50 Marks


End-Sem Exam : 50 Marks
Practical ( PR) : 50 Marks
Term Work (TW) : 25 Marks

Total Marks: 175 Grades: 4


Syllabus

UNIT 1: Graphics Primitives and Scan Conversion


UNIT 2: Polygons and Clipping Algorithms
UNIT 3: 2-D, 3-D Transformations and Projections
UNIT 4: Segment and Animation
UNIT 5: Shading, and Hidden Surfaces
UNIT 6: Curves and Fractals
Books

Text Books:
• S. Harrington, ―Computer Graphics‖, 2nd Edition, McGraw-Hill
Publications, 1987, ISBN 0 – 07 – 100472 – 6.
• D. Rogers, ―Procedural Elements for Computer Graphics‖, 2nd Edition,
Tata McGraw-Hill Publication, 2001, ISBN 0 – 07 – 047371 – 4.
• Donald D. Hearn, ―Computer Graphics with Open GL‖, 4th Edition, ISBN-
13: 9780136053583.

Reference Books:
• J. Foley, V. Dam, S. Feiner, J. Hughes, ―Computer Graphics Principles and
Practice‖, 2nd Edition, Pearson Education, 2003, ISBN 81 – 7808 – 038 – 9.
• D. Rogers, J. Adams, ―Mathematical Elements for Computer Graphics‖,
2nd Edition, Tata McGrawHill Publication, 2002, ISBN 0 – 07 – 048677 – 8.
• Mario Zechner, Robert Green, ―Beginning Android 4 Games
Development‖, Apress, ISBN: 978-81- 322-0575-3.
Unit -I

• Concepts, applications of computer graphics, pixel, frame


buffer, resolution, aspect ratio.
• Plotting Primitives: Scan conversions, lines, line segments,
vectors, pixels and frame buffers, vector generation.
• Scan Conversion: Line and line segments, qualities of good
line drawing algorithms, line drawing algorithms: Digital
Differential Analyzer (DDA), Bresenhams and parallel line
algorithms, Line styles: thick, dotted and dashed. Circle
drawing algorithm: DDA, Bresenhams. Character generating
methods: stroke and bitmap method.
• Display Files: display file structure, algorithms and display file
interpreter. Primitive operations on display file.
Concept of Computer Graphics

• The term of Graphics comes from Greek “graphikos” which


means 'something written' e.g. autograph. So, Graphics
are visual images or designs on some surface, such as a
wall, canvas, screen, paper, or stone to inform, illustrate, or
entertain.
• The term computer graphics includes almost everything on
computers that is not text or sound.
• Computer graphics can be a series of images which most
often called video or a single image.
• The definition of computer graphics is the technology that
deals with designs and pictures on computers.
• So, computer graphics are visual representations
of data displayed on a monitor made on a computer.
Concept of Computer Graphics

• Computer graphics is an art of drawing pictures, lines,


charts, etc using computers with the help of
programming.
• Computer graphics is made up of number of pixels.
• Pixel is the smallest graphical picture or unit represented
on the computer screen.
• Computer graphics is concerned with all aspects of
producing images using a computer.
• It concerns with the pictorial synthesis of real or
imaginary objects from their computer-based models.
Types of Computer Graphics

Computer Graphics can be broadly divided into two


a) Non Interactive Computer Graphics
b) Interactive Computer Graphics
Non Interactive Computer Graphics

• In non interactive computer graphics otherwise


known as passive computer graphics. it is the
computer graphics in which user does not have any
kind of control over the image. Image is merely the
product of static stored program and will work
according to the instructions given in the program
linearly. The image is totally under the control of
program instructions not under the user.
• Example: screen savers.
Interactive Computer Graphics

• Interactive Computer Graphics involves a two way communication


between computer and user.
• Here the observer is given some control over the image by providing him
with an input device.
• for example the video game controller of the ping pong game. This helps
him to signal his request to the computer. The computer on receiving
signals from the input device can modify the displayed picture
appropriately. To the user it appears that the picture is changing
instantaneously in response to his commands. He can give a series of
commands, each one generating a graphical response from the computer.
In this way he maintains a conversation, or dialogue, with the computer.
• Interactive computer graphics affects our lives in a number of indirect
ways. For example, it helps to train the pilots of our airplanes. We can
create a flight simulator which may help the pilots to get trained not in a
real aircraft but on the grounds at the control of the flight simulator.
Applications of Computer Graphics

• Computer graphics are very useful. Today almost every computer


can do some graphics, and people have even come to expect to
control their computer through icons and pictures rather than just
by typing.
• Computer-generated imagery is used for movie making, video
game and computer program development, scientific modeling, and
design for catalogs and other commercial art. Some people even
make computer graphics as art. We can classify applications of
computer graphics into four main areas:
• Display of information
• Design
• User interfaces
• Simulation
Continued…
Continued…

• Computational Biology: Computational biology is an interdisciplinary field


that applies the techniques of computer science, applied mathematics and
statistics to address biological problems. The main focus lies on developing
mathematical modeling and computational simulation techniques.
• Computational Physics: Computational physics is the study and
implementation of numerical algorithm to solve problems in physics for
which a quantitative theory already exists. It is often regarded as a sub
discipline of theoretical physics but some consider it an intermediate
branch between theoretical and experimental physics.
• Information of Graphics: Information graphics or information graphics are
visual representations of information, data or knowledge. These graphics
are used where complex information needs to be explained quickly and
clearly, such as in signs, maps, journalism, technical writing, and
education. They are also used extensively as tools by computer scientists,
mathematicians, and statisticians to ease the process of developing and
communicating conceptual information.
Continued…

• Scientific Visualization: Scientific visualization is a branch of science, concerned


with the visualization of three dimensional phenomena, such as architectural,
meteorological, medical, biological systems. Scientific visualization focuses on the
use of computer graphics to create visual images which aid in understanding of
complex, often massive numerical representation of scientific concepts or results.
• Graphic Design: The term graphic design can refer to a number of artistic and
professional disciplines which focus on visual communication and presentation.
Various methods are used to create and combine symbols, images and/or words to
create a visual representation of ideas and messages. Graphic design often refers
to both the process (designing) by which the communication is created and the
products (designs) which are generated.
• Computer-aided Design: Computer-aided design (CAD) is the use of computer
technology for the design of objects, real or virtual. The design of geometric
models for object shapes, in particular, is often called computer-aided geometric
design (CAGD). CAD may be used to design curves and figures in two-dimensional
("2D") space; or curves, surfaces, or solids in three-dimensional ("3D") objects.
CAD is also widely used to produce computer animation for special effects in
movies, advertising, technical manuals.
Continued…

• Web Design: Web design is the skill of designing presentations of content usually
hypertext or hypermedia that is delivered to an end-user through the World Wide
Web, by way of a Web browser. The process of designing Web pages, Web sites,
Web applications or multimedia for the Web may utilize multiple disciplines, such
as animation, authoring, communication design, corporate identity, graphic design,
human-computer interaction, information architecture, interaction design,
marketing, photography, search engine optimization and typography.
• Digital Art: Digital art most commonly refers to art created on a computer in digital
form. On other hand, is a term applied to contemporary art that uses the methods
of mass production or digital media. The impact of digital technology has
transformed traditional activities such as painting, drawing and sculpture, while
new forms, such as net art, digital installation art, and virtual reality, have been
recognized artistic practices.
• Video Games: A video game is an electronic game that involves interaction with a
user interface to generate visual feedback on a raster display device. The electronic
systems used to play video games are known as platforms. This platform creates
through graphics.
Continued…
• Virtual Reality: Virtual reality (VR) is a technology which allows a user to interact with a computer-
simulated environment. The simulated environment can be similar to the real world, for example,
simulations for pilot or combat training, or it can differ significantly from reality, as in VR games. It
is currently very difficult to create a high-fidelity virtual reality experience, due largely to technical
limitations on processing power, image resolution and communication bandwidth. Virtual Reality is
often used to describe a wide variety of applications, commonly associated with its immersive,
highly visual, 3D environments.
• Computer Simulation: A computer simulation, a computer model or a computational model is a
computer program, or network of computers, that attempts to simulate an abstract model of a
particular system.
• Education: A computer simulation, a computer model or a computational model is a computer
program, or network of computers, that attempts to simulate an abstract model of a particular
system. Computer simulations have become a useful part of mathematical modeling of many
natural systems in physics (computational physics), chemistry and biology, human systems in
economics, psychology, and social science and in the process of engineering new technology, to
gain insight into the operation of those systems, or to observe their behavior.
• Information Visualization: Information visualization is the study of the visual representation of
large-scale collections of non-numerical information, such as files and lines of code in software
systems, and the use of graphical techniques to help people understand and analyze data.
Typical Components of a Graphics
System :

1. A host computer system with support of fast processor


2. Large memory
3. Frame buffer
4. Display Device: color monitor
5. Input devices : mouse, keyboard, joystick,
touch screen, track ball
6. Output devices : LCD panels, laser printers,
color printers, plotters etc.
Basic Graphics System

Output
device
Input
devices
Image formed in FB
Computer Aided Design
Scientific Visualisation
Films
Games
Virtual/Augmented Reality
Pixel

• A pixel is the smallest unit of a digital image or


graphic that can be displayed and represented on a
digital display device.
• A pixel is the basic logical unit in digital graphics.
Pixels are combined to form a complete image,
video, text or any visible thing on a computer display.
• A pixel is also known as a picture element.
Pixel Per Inch

• The meaning of “pixels per inch”. We’ve considered a hypothetical display that
measures 1-inch in each direction. Pixels are shown as a grey square. Starting from
the leftmost example, we have a display with just one pixel. The one pixel takes up
the entire display. In this example, there’s one pixel for one inch of display. We say
the display has a pixel density of 1ppi.
• Moving rightwards to the next image, the number of pixels has been doubled in
both directions. The pixel density has also doubled to 2ppi. The pattern continues
as we move to 4ppi and 8ppi.
Continued…

• As pixel density is increased, the display is able to show more details in an image.
The following diagram shows the effect of increasing pixel density. We’ve shown a
heart on our one-inch square display. As pixel density is increased to higher ppis,
finer details can be seen. The image becomes progressively clear.
How to Calculate Pixel Density

• To calculate the pixel density of your smartphone, start by taking its resolution. You can look at the
resolution in either the horizontal or vertical directions. Once you have the resolution, measure the length
of the display. This should be recorded in inches (2.54cm = 1 inch). By dividing the two numbers, you’ll end
up with the “pixels per inch” (ppi).
• Here’s an example where we’ve calculated the pixel density for the Galaxy S4:
Frame Buffer

• Its an array of internal representation of the image.

• It collects and stores pixel values for use by the display


device
• It holds an intensity coded form of the image to be
displayed
• Operations : clearing and transfer of the information from
frame buffer to the display medium.
The Frame Buffer

0 8
0 0
x
0

pixel at address spot at


(x,y) (x,y)
6
0 y
Frame buffer 0 Display
at surface
(800,600)

29
The Bit-map
1-bit-deep frame-buffer

1 1 1 1 1 1 0 0
0 1 1 0 0 1 1 0
0 1 1 0 0 1 1 0
0 1 1 1 1 1 0 0
0 1 1 0 0 1 1 0
0 1 1 0 0 1 1 0
1 1 1 1 1 1 0 0
0 0 0 0 0 0 0 0

Frame Pixel
buffer s

30
Gray Level images
• n-bits per pixel produce 2n gray levels.
• Many images use 8-bits per pixel, i.e. 256
gray levels since it gives acceptable quality.
00 01 10 11

2-bit per
pixel
4 gray level

Color image 8-bit per 1-bit per


pixel pixel
256 gray 2 gray levels 31
3-bit plane frame buffer
Red Green Blue

Black 0 0 0

Red 1 0 0

Green 0 1 0

Blue 0 0 1

Yellow 1 1 0

Cyan 0 1 1

Magenta 1 0 1

White 1 1 1
Look up Table

• An increase in number of available intensities level can be


achieved through the LUT.
• The LUT must contains 2N entries
• Each entry in the look up table is W bits wide, W may be
greater than N.
• So total 2W intensities are available but only 2N at a time

• To get the additional intensities the LUT must be changed/


Reloaded.
Resolution

• Maximum number of points that can be displayed without


overlap on a CRT.
• The greater the number of points, the higher the
resolution.
• Good resolution : 1000x1000 or 1 million pixels.
• The maximum number of distinguishable points which a
line may have.
• Common Resolution :
640 x 480
800 x 600
1024 x 768
1280 x 1024
• In this example, although the monitor on your desk is
larger, you won't actually be able to fit anything extra
onto it. The total number of pixels is the same - just
everything looks a bit bigger:
Video Display Devices

Four Major Categories:

o Random-scan displays
o Raster-scan displays
o CRT Display
o Flat-panel displays
Random-Scan (Vector) displays
• Vector stands for line.
• Developed in the mid-sixties and in common use until the
mid-eighties.
• The electron beam is directed only to parts of the screen
where the picture is to be drawn.

MoveTo (300,800)
LineTo (700,800)
LineTo (500,300)
LineTo (300,800)

37
Random-Scan Display

A CRT has the electron beam


directed only to the parts of the
screen where the picture is to be
drawn.
A Straight Line can be drawn from any
addressable points to any other
addressable point.
Random-scan (vector, stroke-writing,
calligraphic) displays

o Draw a picture one line at a time


o Stores only the co-ordinates of the lines to be drawn
o To draw a line all it needs to the co-ordinates of the endpoints
o Refresh buffer( Display File)
o It stores the input commands to draw the lines
o The lines are drawn by using vector generation algorithms
o In order to present steady image the display must be drawn
repeatedly
o So the drawing must be fast enough before noticing any flicker(30-60)
o Picture definition
o A set of line-drawing commands
o Refresh display file
o Designed for line drawing applications
o Can not display realistic shaded scenes
Advantages Vs Disadvantages

Sr. No. Advantages Disadvantages

1. Suitable for Line drawing Not suited for the shaded images

2. Require to store only the end Images are composed of line segments
point co-ordinates to draw a line not the surface so complex images may
flicker.
Raster Graphics Display

• The raster graphics is a point plotting device.

• A raster graphics device can be considered as matrix


of discrete cells, each of which can be made bright.

• Not possible to draw a straight line ( Except in some


special cases) .
• The line can be only approximated by a series of dots
close to the path of the line.
Raster-Scan Display

The electron beam is swept across


the screen, one row at a time from
top to bottom
RASTER SCAN AND ADVANTAGES

Scan line

Horizontal retrace Vertical retrace

Raster Scan
Advantages :
1.Lower cost
2. ability to display solid colors and patterns
Disadvantages:
1. Discrete nature of pixel representation (jagged edges)
2.Need scan conversion
3. Need to store not only the end ponts but also all the pixel in
between, as well as all the pixel not on the line
Raster Scan Vs Random Scan

Ideal line drawing Raster Random scan


scan

45
Interlaced raster display

• Each frame is divided in two field and each


containing half of the images.
• The two fields are interlaced and they are presented
alternatively every other 1/60 secs.
• One field contains odd numbered scan line(1,3,5….)
and the other field contains even
numbered( 2,4,6……).
Interlaced Raster Scan Displays
• Odd/even scan lines covered in successive refresh
cycles.
• Hence 30 frames/sec refresh rate appears like 60
frames/sec.

0
1
2
3
4
5
6

47
Cathode-Ray Tubes ( CRT)

– Invented by Karl Ferdinand Braun (1897)


– Most classical display device
– Beam of electrons directed from cathode (-)to
phosphor-coated (fluorescent) screen (anode (+))
– Phosphor emits photon of light, when hit by an
electron, of varied colors
– Phosphors are organic compounds characterized by
their persistence and their color (blue, red, green).
– Horizontal deflection and vertical deflection direct the
* electron beam to any point on the screen 48
Cathode-ray tubes (CRT)

Focusing
System
Y deflect
Bas
e

Phosphor

Connector x deflect
Pins
Electron
Gun Con
trol
grid 49
volt
age
Refresh Cathode-Ray Tube

o Focusing system
– Focusing forces the electron beam to converge to a point on the monitor
screen
– Can be electrostatic (lens) or magnetic (field)
o Deflection of electron beam
– Deflection directs the electron beam horizontally and/or vertically to any
point on the screen
– Can be controlled by electric (deflection plates,) or magnetic fields
(deflection coils,)
– Magnetic coils: two pairs (top/bottom, left/right) of tube neck
– Electric plates: two pairs (horizontal, vertical)

o Persistence
o How long phosphors continue to emit light
o Low persistence is useful for animation
o Resolution
o Number of points per centimeter can be plotted horizontally and
vertically
Refresh Cathode-Ray Tube

o Intensity distribution of a phosphor spot


o Intensity is proportional to the number of electrons
repelled in beam per second (brightness)

o Resolution of a CRT depends


o Type of phosphor
o Intensity to be displayed
o Focusing and deflection system
o Aspect ratio
o The ratio of vertical points to horizontal points
necessary to produce equal-length lines
Flat Panel Display
• Reduced volume, weight and power requirements
compared to a CRT.
• All flat panel displays are raster refresh displays.
Classified into two categories:
• Emissive displays (or Active display) are
devices that convert electrical energy into light
e.g: Plasma panels, thin-film electoluminescent
displays, Light-Emitting Diodes (LEDs).

• Non-emissive (or Passive Display) flat-


panel displays use optical effects to convert
sunlight or light from some other source into
graphics patterns.
e.g: Liquid-crystal device(LCD).
1. Flat CRT

• Initially projecting the electron beam parallel to


the screen and then reflecting it through 90º.
• It has all the performance advantages of the
conventional CRT.
• Available only in small sizes.

53
2. Plasma or Gas Discharge Display

• Plasma panels/gas‐discharge displays :


Constructed by filling the region between two glass plates with
a mixture of gases that usually includes neon .
• Picture definition is stored in a refresh buffer.
• Consists of a matrix of cells (the raster) in a class envelope. Each
cell is filled with a gas (usually neon, or a neon/argon mixture)
at low pressure (below atmospheric).
• The firing voltages are applied to refresh the pixel positions 60
times per second.
• When a sufficiently high voltage is applied the gas
dissociates, i.e. electrons are stripped from the atoms. The
dissociated gas is called a plasma, hence the name plasma
display.
• When the electrons recombine, energy is released in the
form of photons; and the gas glows.
• Plasma displays have large size and are high resolution
displays (100 pixels/inch).
55
Plasma Display Panel

Basic design of a plasma display Panel device


3. Liquid-Crystal Display (LCD)

• It is a flat panel display.


• It is a thin, lightweight display device.
• It has no moving parts.
• It consists of an electrically-controlled light-polarising liquid
trapped in cells between two transparent polarising sheets.
• An electric current passed through the liquid causes the
crystals to align or not so that light can/cannot pass
through them. Each crystal, therefore, is like a shutter,
either allowing light to pass through or blocking the light.
57
Liquid-Crystal Display (LCD)
• Made up of six layers:
1. Vertical filter film to polarize the light as it enters.
2. Glass with electrodes which lines up with the vertical filter. The shapes of
these electrodes will determine the shapes on the LCD.
3. Twisted liquid crystals.
4. Glass with common electrode film which lines up with the horizontal filter.
5. Horizontal filter film to block/allow through light.
6. Reflective surface to send light back to viewer.

58
CRT vs LCD
• Physical Size, Weight – An LCD has one third the size of a CRT, and it is much
lighter.
• Display Size – LCDs are sized by their actual viewable diagonal measurement,
but CRTs are not. E.g. the viewable area on a 17" LCD monitor will measure
17" diagonally, but the viewable area on a CRT monitor will only measure 16"
diagonally.
• Colours – Most CRT monitors are capable of displaying unlimited colours.
Some LCD monitors are only capable of hundreds or thousands of colours, but
many of the newer LCD's are capable of unlimited colours.
• Resolution – CRT monitors are usually capable of displaying multiple video
resolutions, each with the same quality. LCD monitors, however, usually have
what is called a Native resolution, or the resolution that it displays best. The
native resolution is generally the highest resolution that the LCD can display.

59
CRT vs LCD

• Viewing Angle –A CRT screen can be looked at from a very wide angle,
practically from the side, but an LCD monitor typically has a smaller viewing
angle. From the side, the image on an LCD screen can seem to disappear, or
invert colours. Newer displays that are coming out have wider viewing
angles.
• Brightness is not a concern with CRT monitors. LCD monitors have different
levels of brightness. The brightness rating for an LCD monitor is commonly
referred to as 'nits', and commonly range from 70 to 300 nits. The higher the
nits, the brighter the display.
• Power Consumption and Radiation Emission – LCD monitors consume much
less energy than CRT monitors. Secondly, CRT monitors are known to emit
harmful radiation, whereas LCD monitors do not.
• Price – CRT monitors are more affordable than LCD monitors. However the
LCD’s cost have come down quite a lot in the last 1-2 years. An LCD monitor
will cost more but will conserve energy in the long run. The energy savings
may not be much for an individual user, but with a corporation the energy
savings might be more of an issue.
60
Line styles: thick, dotted and
dashed
• Many times different styles of line are required to
differentiate each of the lines from one another.

• Solid line
• Dashed line
• Dotted line A chart with different line style

• Thick line

61
Line styles: thick, dotted and dashed

• Dashed line and dotted lines are generated by just a


minor modification in general line drawing
algorithm.

• A dotted line can be generated by displaying the


pixels alternatively.

• A dashed line can be generated by displaying


alternate group of pixels(Inter dash).

62
Thick Lines

• A line segment generated by DDA algorithm is of a


single pixel width.
• How to draw a line segment with thickness of three
pixel???
• A line with any width w, can be generated by putting
a vertical span of (w/2) pixels on both sides of the
central line

63
Line styles: thick, dotted and
dashed

• The value of wy is

64
Line styles: thick, dotted and
dashed
• For a line with steep slope i.e. a slope greater than 1
the role of x and y will be interchanged .

• Then the value of w x will be

65
Antialiasing

Antialiasing is a technique used to reduce the uneven edges of


an image or a line, so that the line appears to be smoother; by
changing the pixels around the edges to intermediate colors or
gray scales.
Eg. Antialiasing disabled:

Eg. Antialiasing enabled:

66
Unit II
Scan Conversions (6 Hrs)

• Line and line segments,


• Line and circle drawing algorithms: DDA and Bresenham
• Line styles: thick, dotted and dashed.
• Antialising and antialising techniques.
• Character generating methods: stroke and bitmap method
• Multiligual character standards.
• Concurrent line drawing using midpoint sub-division
algorithm.

67
Line Drawing Algorithm

▪ The Process of determine which pixels provide the best


approximation to the desired line is properly known as
“Rasterization”.

▪ The primary design criteria are that straight lines appear as straight
lines, and that they start and end accurately.

▪ In addition , displayed lines should have constant brightness along


their, independent of the line length and orientation.

68
Digital differential analyzer (DDA)

• This algorithm is for rasterzing a line.


• Suppose, the line have two end points like (x1,y1) and (x2,y2)

• if abs(x2-x1) ≥ abs(y2-y1) then


Length = abs(x2-x1)
else
Length = abs(y2-y1)

69
if abs(x2-x1) ≥ abs(y2-y1) then
Length = abs(x2-x1)
else
Length = abs(y2-y1)
Select the larger of Δx or Δy to be one raster unit.
Δx = (x2-x1)/Length
Δy = (y2-y1)/Length
x=x1+0.5 ( or round(x) )
y=y1+0.5 ( or round(y) )
i=1
while (i≤ Length)
setpixel ( Integer (x), Integer (y))
x=x+Δx
y=y+Δy
i=i+1
end while
Finish
70
#define round(a) ( (int) (a+0.5) )
void lineDDA (int x0, int y0, int xEnd, int yEnd)
{
int dx = xEnd - x0, dy = yEnd - y0, steps, k;
float xIncrement, yIncrement, x = x0, y = y0;
if (abs (dx) > abs (dy))

DDA Algorithm
steps = abs (dx);
else
steps = abs (dy);
xIncrement = dx / float (steps);
yIncrement = dy / float (steps);
setPixel (round (x), round (y));
for (k = 0; k < steps; k++)
{
x += xIncrement;
y += yIncrement;
setPixel (round (x), round (y));
}}
71
DDA Example

• Suppose we want to draw a line starting at pixel (2,3) and


ending at pixel (12,8).
Length = 12 – 2 = 10
Δx = 10/10 = 1.0
Δy = 5/10 = 0.5
0 i setpixel x y
1 2.5 3.5
2
3 1 (2,3) 2.5+1 3.5+0.5
4
5
6
7
8
0 1 2 3 4 5 6 7 8 9 10 11 12

72
DDA Example
• Suppose we want to draw a line starting at pixel (2,3) and
ending at pixel (12,8).
Length = 12 – 2 = 10
Δx = 10/10 = 1.0
Δy = 5/10 = 0.5
0 i setpixel x y
1 2.5 3.5
2
3 1 (2,3) 2.5+1 3.5+0.5
4 2 (3,4) 3.5+1 4+0.5
5
6
7
8
0 1 2 3 4 5 6 7 8 9 10 11 12

73
DDA Example
• Suppose we want to draw a line starting at pixel (2,3) and
ending at pixel (12,8).
Length = 12 – 2 = 10
Δx = 10/10 = 1.0
Δy = 5/10 = 0.5
0 i setpixel x y
1 2.5 3.5
2
3 1 (2,3) 2.5+1=3.5 3.5+0.5=4
4 2 (3,4) 3.5+1=4.5 4+0.5=4.5
5 3 (4,4) 4.5+1=5.5 4.5+0.5=5
6
7
8
0 1 2 3 4 5 6 7 8 9 10 11 12

74
DDA Example

• Suppose we want to draw a line starting at pixel (2,3) and


ending at pixel (12,8).
Length = 12 – 2 = 10
Δx = 10/10 = 1.0
Δy = 5/10 = 0.5
0 i setpixel x y
1 2.5 3.5
2
1 (2,3) 2.5+1=3.5 3.5+0.5=4
3
4 2 (3,4) 3.5+1=4.5 4+0.5=4.5
5 3 (4,4) 4.5+1=5.5 4.5+0.5=5
6 4 (5,5) 5.5+1=6.5 5+0.5=5.5
7
8
0 1 2 3 4 5 6 7 8 9 10 11 12

75
DDA Example
• Suppose we want to draw a line starting at pixel (2,3) and
ending at pixel (12,8).
Length = 12 – 2 = 10
Δx = 10/10 = 1.0
Δy = 5/10 = 0.5
0 i setpixel x y
1 2.5 3.5
2
3 1 (2,3) 2.5+1=3.5 3.5+0.5=4
4 2 (3,4) 3.5+1=4.5 4+0.5=4.5
5 3 (4,4) 4.5+1=5.5 4.5+0.5=5
6 4 (5,5) 5.5+1=6.5 5+0.5=5.5
7
5 (6,5) 6.5+1=7.5 5.5+0.5=6
8
0 1 2 3 4 5 6 7 8 9 10 11 12

76
DDA Example
• Suppose we want to draw a line starting at pixel (2,3) and
ending at pixel (12,8).
Length = 12 – 2 = 10
Δx = 10/10 = 1.0
Δy = 5/10 = 0.5
0 i setpixel x y
1 2.5 3.5
2
3 1 (2,3) 2.5+1=3.5 3.5+0.5=4
4 2 (3,4) 3.5+1=4.5 4+0.5=4.5
5 3 (4,4) 4.5+1=5.5 4.5+0.5=5
6 4 (5,5) 5.5+1=6.5 5+0.5=5.5
7
5 (6,5) 6.5+1=7.5 5.5+0.5=6
8
0 1 2 3 4 5 6 7 8 9 10 11 12 6 (7,6) 7.5+1=8.5 6+0.5=6.5

77
DDA Example
• Suppose we want to draw a line starting at pixel (2,3) and
ending at pixel (12,8).
Length = 12 – 2 = 10
Δx = 10/10 = 1.0
Δy = 5/10 = 0.5
0 i setpixel x y
1 2.5 3.5
2
3 1 (2,3) 2.5+1=3.5 3.5+0.5=4
4 2 (3,4) 3.5+1=4.5 4+0.5=4.5
5 3 (4,4) 4.5+1=5.5 4.5+0.5=5
6 4 (5,5) 5.5+1=6.5 5+0.5=5.5
7
5 (6,5) 6.5+1=7.5 5.5+0.5=6
8
0 1 2 3 4 5 6 7 8 9 10 11 12 6 (7,6) 7.5+1=8.5 6+0.5=6.5
7 (8,6) 8.5+1=9.5 6.5+0.5=7
78
DDA Example
• Suppose we want to draw a line starting at pixel (2,3) and
ending at pixel (12,8).
Length = 12 – 2 = 10
Δx = 10/10 = 1.0
Δy = 5/10 = 0.5
0 setpixel x y
1 2.5 3.5
2
3 1 (2,3) 2.5+1=3.5 3.5+0.5=4
4 2 (3,4) 3.5+1=4.5 4+0.5=4.5
5 3 (4,4) 4.5+1=5.5 4.5+0.5=5
6 4 (5,5) 5.5+1=6.5 5+0.5=5.5
7
5 (6,5) 6.5+1=7.5 5.5+0.5=6
8
0 1 2 3 4 5 6 7 8 9 10 11 12 6 (7,6) 7.5+1=8.5 6+0.5=6.5
7 (8,6) 8.5+1=9.5 6.5+0.5=7
8 (9,7) 9.5+1=10.5 7+0.5=7.5 79
DDA Example
• Suppose we want to draw a line starting at pixel (2,3) and
ending at pixel (12,8).
Length = 12 – 2 = 10
Δx = 10/10 = 1.0
Δy = 5/10 = 0.5
0 i setpixel x y
1 2.5 3.5
2
3 1 (2,3) 2.5+1=3.5 3.5+0.5=4
4 2 (3,4) 3.5+1=4.5 4+0.5=4.5
5 3 (4,4) 4.5+1=5.5 4.5+0.5=5
6 4 (5,5) 5.5+1=6.5 5+0.5=5.5
7
5 (6,5) 6.5+1=7.5 5.5+0.5=6
8
0 1 2 3 4 5 6 7 8 9 10 11 12 6 (7,6) 7.5+1=8.5 6+0.5=6.5
7 (8,6) 8.5+1=9.5 6.5+0.5=7
8 (9,7) 9.5+1=10.5 7+0.5=7.5
9 (10,7) 10.5+1=11.5 7.5+0.5=8

80
DDA Example
Length = 12 – 2 = 10
Δx = 10/10 = 1.0
Δy = 5/10 = 0.5
0 i setpixel x y
1 2.5 3.5
2
3 1 (2,3) 2.5+1=3.5 3.5+0.5=4
4 2 (3,4) 3.5+1=4.5 4+0.5=4.5
5 3 (4,4) 4.5+1=5.5 4.5+0.5=5
6 4 (5,5) 5.5+1=6.5 5+0.5=5.5
7
5 (6,5) 6.5+1=7.5 5.5+0.5=6
8
0 1 2 3 4 5 6 7 8 9 10 11 12 6 (7,6) 7.5+1=8.5 6+0.5=6.5
7 (8,6) 8.5+1=9.5 6.5+0.5=7
8 (9,7) 9.5+1=10.5 7+0.5=7.5
9 (10,7) 10.5+1=11.5 7.5+0.5=8
10 (11,8) 11.5+1=12.5 8+0.5=8.5 81
81
DDA Example
Length = 12 – 2 = 10
Δx = 10/10 = 1.0
Δy = 5/10 = 0.5
0 i setpixel x y
1 2.5 3.5
2
3 1 (2,3) 2.5+1=3.5 3.5+0.5=4
4 2 (3,4) 3.5+1=4.5 4+0.5=4.5
5 3 (4,4) 4.5+1=5.5 4.5+0.5=5
6 4 (5,5) 5.5+1=6.5 5+0.5=5.5
7
5 (6,5) 6.5+1=7.5 5.5+0.5=6
8
0 1 2 3 4 5 6 7 8 9 10 11 12 6 (7,6) 7.5+1=8.5 6+0.5=6.5
7 (8,6) 8.5+1=9.5 6.5+0.5=7
8 (9,7) 9.5+1=10.5 7+0.5=7.5
9 (10,7) 10.5+1=11.5 7.5+0.5=8
10 (11,8) 11.5+1=12.5 8+0.5=8.5 82
Digital differential analyzer (DDA)

• Advantages:
– Simplest algorithm
– Faster
• Disadvantages:
– Time consuming floating point arithmetic.
– End point accuracy is poor.

83
Breseham’s algorithm

84
The Bresenham Line Algorithm
• The Bresenham algorithm is another
incremental scan conversion
algorithm
• The big advantage of this algorithm
is that it uses only integer
calculations

Jack Bresenham worked


for 27 years at IBM
before entering
academia. Bresenham
developed his famous
algorithms at IBM in the
early 1960s 85
The Bresenham Line Algorithm
• Move across the x axis in unit intervals and at each
step choose between two different y coordinates

For example, from


5
(xk+1, yk+1)
position (2, 3) we have
4
to choose between
(xk, yk) (3, 3) and (3, 4)
3
We would like the
(xk+1, yk)
2
point that is closer to
the original line
2 3 4 5 86
Bresenham’s Algorithm

• This algorithm always increments by one unit in x , increment in y


depend on the slope of the line.
• The increment in y , either zero or one , is determined by examining
the distance between the actual line and nearest grid locations. This
distance is called the error.

87
The Bresenham Line Algorithm

(x1,y1) and (x2,y2) are the end points.


Integer is the integer function
x, y, Δx, Δy are assumed integer, e is real
Initialize variables
x= x1
y=y1

Δx=x2-x1
Δy=y2-y1

e = m – 1/2

88
The Bresenham Line Algorithm

Begin the main loop


For i=1 to Δx
setpixel (x,y)
while(e>0)
y=y+1
e=e-1;
end while
x=x +1
e=e + m
next i
finish

89
Breseham algorithm Example
• Suppose we want to draw a line starting at pixel (0,0) and
ending at pixel (5,5). Δx = 5-0 = 5
Begin the main loop Δy = 5 - 0 = 5
m=1
For i=1 to Δx
e = m – 1/2 = 1/2
0 setpixel(x,y) i setpixel e x y
1 while(e>0) ½ 0 0
2
3 y=y+1 1 (0,0)
4 e=e-1;
5
6
end while
7 x=x+1
8 e=e+m
0 1 2 3 4 5 6 7 8 9 10 11 12
next I
finish 90
Breseham algorithm Example
• Suppose we want to draw a line starting at pixel (0,0) and
ending at pixel (5,5). Δx = 5-0 = 5
Begin the main loop Δy = 5 - 0 = 5
For i=1 to Δx m=1
e = m – 1/2 = 1/2
0
setpixel(x,y) i setpixel e x y
1 while(e>0) ½ 0 0
2
3
y=y+1 1 (0,0) -½ 0 1
4 e=e-1; ½ 1 1
5 end while 2 (1,1)
6
7 x=x+1
8 e=e+m
0 1 2 3 4 5 6 7 8 9 10 11 12
next I
finish 91
Breseham algorithm Example
• Suppose we want to draw a line starting at pixel (0,0) and
ending at pixel (5,5). Δx = 5-0 = 5
Begin the main loop Δy = 5 - 0 = 5
For i=1 to Δx m=1
e = m – 1/2 = 1/2
0
setpixel(x,y) i setpixel e x y
1 while(e>0) ½ 0 0
2
3
y=y+1 1 (0,0) -½ 0 1
4 e=e-1; ½ 1 1
5 end while 2 (1,1) -½ 1 2
6 ½ 2 2
7 x=x+1
3 (2,2)
8 e=e+m
0 1 2 3 4 5 6 7 8 9 10 11 12
next I
finish 92
Breseham algorithm Example
• Suppose we want to draw a line starting at pixel (0,0) and
ending at pixel (5,5). Δx = 5-0 = 5
Begin the main loop Δy = 5 - 0 = 5
For i=1 to Δx m=1
e = m – 1/2 = 1/2
0 setpixel(x,y) i setpixel e x y
1 while(e>0) ½ 0 0
2
3 y=y+1 1 (0,0) -½ 0 1
4 e=e-1; ½ 1 1
5 2 (1,1) -½ 1 2
end while
6 ½ 2 2
7 x=x+1
3 (2,2) -½ 2 3
8 e=e+m
0 1 2 3 4 5 6 7 8 9 10 11 12 ½ 3 3
next I 4 (3,3)
finish 93
Breseham algorithm Example
Δx = 5-0 = 5
Δy = 5 - 0 = 5
Begin the main loop m=1
For i=1 to Δx e = m – 1/2 = 1/2
0 i setpixel e x y
1
setpixel(x,y)
½ 0 0
2 while(e>0)
3 1 (0,0) -½ 0 1
4
y=y+1 ½ 1 1
5 e=e-1; 2 (1,1) -½ 1 2
6
end while ½ 2 2
7
8 x=x+1 3 (2,2) -½ 2 3
0 1 2 3 4 5 6 7 8 9 10 11 12 ½ 3 3
e=e+m
4 (3,3) -½ 3 4
next I
½ 4 4
finish 5 (4,4) -½ 4 5
94
½ 5 5
The Bresenham Line Algorithm
(for all quadrant)
Initialize variables
x = x1
y =y1
Δx = abs(x2-x1)
Δy = abs(y2-y1)
s1 = sign(x2-x1)
s2 = sign(y2-y1)
if Δy > Δx then sign function returns -1, 0, 1 if its
Temp = Δx argument is <0, =0, >0
Δx=Δy
Δy= temp
Interchange=1
Else
interchange=0
end if

95
The Bresenham Line Algorithm
(for all quadrant)

e = 2 * Δy – Δx if interchange = 1
main loop then
For i=1 to Δx y=y + s2
setpixel(x,y) Else
while(e > 0) x = x + s1
If interchange = 1
end if
then
x = x + s1 e = e + 2 * Δy
else next i
y = y + s2 finish
end if
e = e – 2 * Δx
end while
96
Difference
Digital Differential Analyzer
Parameter Bresenhams Line Drawing Algorithm
Line Drawing Algorithm
Arithmetic uses floating points i.e. Real
fixed points i.e. Integer Arithmetic.
Arithmetic.
Operations uses multiplication and division in its uses only subtraction and addition in its
operations. operations.
slowly than Bresenhams algorithm in faster than DDA algorithm in line
Speed
line drawing because it uses floating- drawing because it uses only integer
point operations . arithmetic .
Accuracy
not as accurate and efficient as more efficient and much accurate than
&
Bresenham algorithm. DDA algorithm.
Efficiency
can draw circles and curves but that are
can draw circles and curves with much
Drawing not as accurate as Bresenhams
more accuracy than DDA algorithm.
algorithm.
It round off the coordinates to integer does not round off but takes the
Round Off
that is nearest to the line. incremental value in its operation.
uses an many number of floating-point less expensive than DDA algorithm97as it
Expensive
multiplications so it is expensive. uses only addition and subtraction.
Unit II
Scan Conversions (6 Hrs)

• Line and line segments,


• Line and circle drawing algorithms: DDA and Bresenham
• Line styles: thick, dotted and dashed.
• Antialising and antialising techniques.
• Character generating methods: stroke and bitmap method
• Multiligual character standards.
• Concurrent line drawing using midpoint sub-division
algorithm.

99
Representing pictures

• Picture is end product of computer graphics.


• Basic building blocks of picture is points.
Ex. Consider unit square with following four corner points
P1(0,0)
P2(0,1)
P1(0,0) E4 P4(1,0)
P3(1,1)
P4(1,0)
E1 E3
S1

P2(0,1) E2 P3(1,1)
100
Rasterization

A Raster display is considered as a matrix of discrete finite


cells , each of which can be made bright. It is not possible to
directly draw a straight line from one point to another .
The process of determining which pixels provide the best
approximation to the desired line is known as rastreization.

When combined with the process of generating the


picture in scan line order , it is known as scan conversion

101
Line
• Point can specify with a co-ordinate(X,Y)
Where X –horizontal distance from the origin
Y –vertical distance from the origin

• Two points are require to specify a Line

• If Two points used to specify a line are(x1,y1) and (x2,y2) then an


equation for the line is

• Slope between any point on the line and (X1,Y1) is same as slope
between(X2,Y2) and (X1,Y1)
102
Equation of Line

Where

Y is called slope intercept form of the line

The Slope m is change in height/change in width for two points on the line

b is called intercept ,it is the height at which the line crosses the y Axis.
103
can we determine where two lines are crossing?

Line1: Y = m1 X + b1
Line2: Y = m2 X + b2
If there is some common points (Xi,Yi)
(Xi,Yi) shared by both the lines

Yi = m1 Xi + b1
Yi = m2 Xi + b2 will both be true
Equating over Yi gives
m1 Xi + b1=m2 Xi + b2

104
After solving we get xi,
• Xi = b2-b1 / m1-m2
If put this value in eq. for line1 or line2 then we get
• Yi= b2 m1 - b1 m2 / m1-m2
So the point is
• (b2-b1/m1-m2, b2m1-b1m2/m1-m2)🡺 (Xi , Yi)
Is the intersection point

105
LINE SEGMENTS

• A Line segment can be specified by its two endpoints


• It is a piece of Line
• Using endpoint we can determine the equation of the line

• Consider if endpoints are P1 =(X1,Y1) and P2=(X2,Y2) and


these endpoints satisfied the equation
• Y= m X + b

then the another point P3=(X3,Y3) lies on segment if P2


• 1.Y3=m X3 + b
• 2.Min(X1,X2) <= X3 <=max(X1,X2)
• 3.min(Y1,Y2) <= Y3 <=max(Y1,Y2)
P1

106
What is a mid point of a line segment?

The point halfway between the endpoints of a segment will have an


x coordinate halfway between the coordinates of the endpoints ,
and a y coordinates halfway between the y coordinates of the
endpoints.
The mid point is,

p2
m
ym
p1
xm
107
Slopes
• The slope of a line (m) is defined by its start and end
coordinates
• The diagram below shows some examples of lines
and their slopes

m=∞
m = -4 m=4
m = -2 m=2

m = -1 m=1

m = -1 / 2 m = 1/2
m = -1 / 3 m = 1/3

108
m=0 m=0
Vectors
What is a vector?
•A vector has a single direction and a length.
•A vector may be denoted [Dx,Dy]
Where, Dx indicates how far to move along the x-axis direction
Dy indicates how far to move along y-axis direction

Fig. Vector

109
Vectors

Addition of vectors:
If the two vectors are V1[Dx1, Dy1] and V2[Dx2,Dy2] then the
addition is given by
V1+V2=[Dx1, Dy1] + [Dx2,Dy2]

Multiplication of vectors:
A vector can be multiplied by a number.
Let V[Dx, Dy] be a vector which is to be multiplied by a number n
then, nV = n[Dx, Dy] = [nDx, nDy]

If multiplication of a vector and the reciprocal of its length is equal


to 1 then such vector is called as unit vector.
110
DDA and Bresenham’s
Circle drawing algorithm

112
• A Circle Is A Symmetrical Figure .
• It Has Eight Way Symmetry.
• Any circle drawing algorithm can take advantage of the circle symmentry
to plot eight points by calculating the coordinates of any one point.
• Example- if point A in the figure is calculated with a circle algorithm,
seven more points could be found just by reflections.

113
• There are two standard methods of mathematically
representing a circle centered at the origin.
1. Polynomial Method
2. Trigonometric Method

114
Polynomial Method

The equation for a circle is:

where r is the radius of the circle


So, we can write a simple circle drawing algorithm by
solving the equation for y at unit x intervals using:

115
116
A Simple Circle Drawing Algorithm (cont…)

• This is not a good solution!

• Firstly, the resulting circle has large gaps where the


slope approaches the vertical

• Secondly, the calculations are not very efficient


– The square (multiply) operations
– The square root operation – try really hard to avoid
these!

• We need a more efficient, more accurate solution


117
Trigonometric Method

Where, r- radius of the circle


ᶿ - current angle
X- x coordinate
Y – y coordinate

118
Circle Drawing Algorithms

• Vector Generation / DDA algorithm


• Bresenhams Algorithm
• Midpoint Algorithm

119
DDA circle drawing algorithm

• We know that , the equation of circle , with origin as the center


of the circle is given as ,
x² + y² = r²
• The DDA algorithm can be used to draw the circle by defining
circle as a differential equation.
• It is as given below
2x dx + 2y dy = 0 where r is constant
x dx + y dy = 0
y dy = -x dx

120
DDA circle drawing algorithm
• We can construct the circle by using
• incremental x value, ∆x = ε y and
• incremental y value , ∆y = -ε x,
• where ‘ε’ is calculated from the radius of the circle as
given below,
2ⁿ⁻¹ <= r < 2ⁿ r: radius of the circle
ε = 2⁻ⁿ
• For example, if r=50 then n=6
so that 32≤ 50 < 64
ε = 2-6

121
DDA circle drawing algorithm

• Applying these incremental steps we have,


xn+1 = xn + ε yn
yn+1 = yn - ε xn
• The point plotted using above equations give the spiral
instead of circle.
• To get circle we have to replace xn by xn+1 in the
equation of yn+1
xn+1 = xn + ε yn
yn+1 = yn - ε xn+1
122
DDA Algorithm

1. Read the radius of the circle and calculate value of ε.


2. Start_x = 0
Start_y = r
3. x1 = start_x
y1 = start_y
4. do
{ x2 = x1 + ε y1
y2 = y1 - ε x2 [x2 represents xn+1 and x1 represents xn]
Plot( int(x2) ,int (y2) )
x1 = x2;
y1 = y2 [ Reinitalize the current point]
}while ( y1 - start_y) < ε or ( start_x - x1) > ε
[check if the current point is the starting point or not. If the current point is
not starting point repeat step 4; other wise stop]
5. stop 123
Example

• Calculate the pixel position along the circle with


radius=6 centered on the origin using DDA from point
( 0 , 6 ) to point x=y.
• Calculate the pixel position along the circle with
radius=8 centered on the origin using DDA from point
( 0 , 8 ) to point x=y.

124
Eight-Way Symmetry
The first thing we can notice to make our circle drawing
algorithm more efficient is that circles centred at (0, 0)
have eight-way symmetry

(-x, y) (x, y)

(y, -x) (y, x)

(-y, -x) (-y, x)

(-x, - (x, -y)


125
y)
Bresenham’s Circle drawing
algorithm
• Assume, clockwise generation of a circle then for any
given point on the circle, there are only three possible
selections for the next pixel which best represent the
circle.
1) Horizontally to the right
2) Diagonally downward to the right
3) Vertically downward
All these selections are shown in fig.

126
Pixel selection

• These are labeled as mH, mD, mV

Xi,Yi mH
Xi+1,Yi

mD

mV

Xi+1,Yi-1
Xi,Yi-1

127
Bresenham’s Circle drawing
algorithm
• The algorithm chooses the pixel which minimizes the
square of the distance between one of the pixel and
the true circle.
• Following are the equations to calculate the values of
mH, mD, mV
• mH=|(Xi+1)²+(Yi)²-R²|
• mD =|(Xi+1)²+(Yi-1)²-R²|
• mV =|(Xi)²+(Yi-1)²-R²|

128
Bresenham’s Circle drawing
algorithm
• The difference between the square of the distance
from the center of the circle to the diagonal pixel at
Xi+1,Yi-1 and the distance to a point on the circle R²
is

• Δi= =(Xi+1)²+(Yi-1)²-R²

129
Bresenham’s Circle drawing
algorithm
By evaluating the value of Δi, we get these 3 conditions,

130
Bresenham’s Circle drawing
algorithm
• The diagonal pixel (Xi+1,Yi-1) is always outside the
circle.
• The vertical pixel (Xi,Yi-1) is always inside the
circle.
• Thus, δ can be evaluated as
d =|(Xi+1)²+(Yi)²-R²| + |(Xi+1)²+(Yi-1)²-R²|
• After calculating δ , there are two cases
1) Check d<= 0 then choose mH at (Xi+1,Yi)
2) Check d > 0 then choose mD at (Xi+1,Yi-1)

131
Bresenham’s Circle drawing
algorithm
• The equation for di at starting point x=0 and y=R can be
simplified as follows:

di = |(Xi+1)²+(Yi)²-R²| + |(Xi+1)²+(Yi-1)²-R²|
= |(0+1)²+(R)²-R²| + |(0+1)²+(R-1)²-R²|
= 1²+R²-R² + 1²+R²-2R+1-R²
= 1+R²-R² + 1+R²-2R+1-R²
= 3-2R

132
Bresenham’s Circle drawing
algorithm
• Similarly, the equation for di+1 is
di =(Xi+1)²+(Yi)²-R² + (Xi+1)²+(Yi-1)²-R²
di+1 = 2(xi+1+1)2 +yi+12+(yi+1-1)2 -2R2
di+1 -di=2(xi+1+1)2+yi+12+(yi+1-1)2-2R2- (2(Xi+1)²-(Yi)²-(Yi-1)²+2R²)
Since xi+1=xi+1 we have,
di+1 =di+2(xi+1+1)2+yi+12+(yi+1-1)2- (2(Xi+1)²-(Yi)²-(Yi-1)²)
=di+2(xi+2)2+yi+12+(yi+1-1)2- (2(Xi+1)²-(Yi)²-(Yi-1)²)
=di+2(xi2+4xi+4)2+yi+12+(yi+12-2yi+1+1)2- (2(xi2+2xi+4)²-(Yi)²-(yi2-2yi+1)²)
=di+4xi+2(yi+12-Yi²)-2(yi+1-yi)+6 = di+4xi+6
If d≥0 then yi+1=yi
• di+1=di+4(xi-yi) + 10
133
Bresenham’s Circle drawing
algorithm
• Similarly, the equation for di+1 for both the cases are given as
For di < 0, di+1 = di+4xi + 6 and
For di ≥ 0, di+1 = di+4(xi-yi) + 10
• To plot complete circle:
plot(x, y)
plot(y, x)
plot(y, -x)
plot(x, -y)
plot(-x, -y)
plot(-y, -x)
plot(-y, x)
plot(-x, y)

134
Algorithm to plot 1/8 of the circle
1. Read the radius R of the circle
2. d = 3-2R [initialize the decision variable]
3. x = 0, y = R [initialize starting point]
4. do
{
Plot (x,y)
If(d <0) then
{
d=d+4x+6
else
d=d+4(x-y)+10
y=y-1
}
x=x+1
} While (x<y)
5. Stop
135
Example

• Calculate the pixel position along the circle with


radius=10 centered on the origin using Bresenhams
from point ( 0 , 10 ) to point x=y.
• Calculate the pixel position along the circle with
radius=14 centered on the origin using Bresenhams
from point ( 0 , 14 ) to point x=y.

136
X Y d Plot
0 10 -17 (0,10)
1 10 -11 (1,10)
2 10 -1 (2,10)
3 10 13 (3,10)
4 9 -5 (4,9)
5 9 17 (5,9)
6 8 11 (6,8)
7 7 13 (7,7)

137

You might also like