CG 1
CG 1
CG 1
Evaluation Pattern
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
• 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 :
Output
device
Input
devices
Image formed in FB
Computer Aided Design
Scientific Visualisation
Films
Games
Virtual/Augmented Reality
Pixel
• 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
0 8
0 0
x
0
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
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
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
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
Scan line
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
45
Interlaced raster display
0
1
2
3
4
5
6
47
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
53
2. Plasma or Gas Discharge Display
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
62
Thick Lines
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 .
65
Antialiasing
66
Unit II
Scan Conversions (6 Hrs)
67
Line Drawing Algorithm
▪ The primary design criteria are that straight lines appear as straight
lines, and that they start and end accurately.
68
Digital differential analyzer (DDA)
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
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
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
87
The Bresenham Line Algorithm
Δx=x2-x1
Δy=y2-y1
e = m – 1/2
88
The Bresenham Line Algorithm
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)
99
Representing pictures
P2(0,1) E2 P3(1,1)
100
Rasterization
101
Line
• Point can specify with a co-ordinate(X,Y)
Where X –horizontal distance from the origin
Y –vertical distance from the origin
• 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
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
106
What is a mid point of a line segment?
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]
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
115
116
A Simple Circle Drawing Algorithm (cont…)
118
Circle Drawing Algorithms
119
DDA circle drawing algorithm
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
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)
126
Pixel selection
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
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