0% found this document useful (0 votes)
19 views

Unit-1.2.1 CG Scan Conversioin

The document discusses computer graphics and methods for drawing basic graphic primitives like points, lines, and circles. It describes various display devices and introduces fundamental graphic objects like points and lines. It then explains algorithms for drawing lines on a pixel-based display, including the slope-intercept line equation, and algorithms for horizontal and vertical lines that increment the x- or y-coordinate to turn on adjacent pixels along the line.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Unit-1.2.1 CG Scan Conversioin

The document discusses computer graphics and methods for drawing basic graphic primitives like points, lines, and circles. It describes various display devices and introduces fundamental graphic objects like points and lines. It then explains algorithms for drawing lines on a pixel-based display, including the slope-intercept line equation, and algorithms for horizontal and vertical lines that increment the x- or y-coordinate to turn on adjacent pixels along the line.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

UNIVERSITY INSTITUTE OF COMPUTING

Bachelor of Computer Science


Computer Graphics
20CAT-316

DISCOVER . LEARN . EMPOWER


1
Syllabus
Unit-I
Introduction: Computer Graphics, Computer Graphics Applications.
Video Display Devices: Refresh Cathode Ray Tube, Raster Scan displays, Random Scan Displays,
Architecture of Raster and Random Scan Monitors, Color CRT-monitors, Color Generating
Techniques (Shadow Mask, Beam Penetration), Direct View Storage Tube, Flat Panel Display,
Graphics monitors and Workstations.
Two dimensional Graphics Primitives: Points and Lines, Point plotting Techniques: Coordinate
system, Increment method, Line drawing algorithm: DDA, Bresenham’s line drawing,
Bresenham‘s circle drawing algorithm: Using polar coordinates, Midpoint circle drawing
algorithms Filled area algorithm: Scan line, Polygon filling algorithms, Boundary filled
algorithms. 2
Primitive Graphic Objects

Computer-generated images are produced using primitive graphic objects


such as:
 Points
 Straight lines
 Circles

3
Scan Converting A Pixel
Each pixel on graphic display does not represent a mathematical point like
P(2.6,3.33). But it can be accommodated to the nearest position by applying few
mathematical functions such as
CEIL P  (3,4)
FLOOR P  (2,3)
GREATEST INTEGER FUNCTION P  (3,3) A pixel (10, 6)
ROUND P  (3,3) X
Y
A point (-12.3,
10.3, 0)

X
Z
Y
Fig. 3.1 Coordinate axis [1] Fig. 3.2 Screen Coordinates [2]

4
Scan Converting A Line

Many computer-generated pictures are composed of straight-line segments.


A line segment is displayed by turning on a set of adjacent pixels.
In order to draw a line, it is necessary to determine which pixels lie nearest the
line and provide the best approximation to the desired line.
The line drawing routine should be accurate, fast, and easy to implement.

5
The Problem of Scan Converting A
Line
A line segment is defined by the coordinate positions of the line
endpoints.
We have a line with the endpoints (2,2) and (8,7) and we want to draw
this line on a pixel based display.

How do we choose which


pixels to turn on?

Fig. 3.3 Pixel display [3]


6
Slope-Intercept Line Equation

A line segment in a scene is defined by the coordinate positions of the line


endpoints. The starting point is (Xstart, Ystart) and the ending point is
y
(Xend, Yend).
Yend

Ystart x

Xstart Xend
Fig. 3.4 Representation of line end points

7
Slope-Intercept Line Equation
Line Equation is defined as: y = m x + b
Where m is the slope of the line, and defined as the change in y values divided
by the change in x values:

Yend – Ystart
m=
Xend – Xstart

b is the y-intercept. Recall that the y-intercept is the line’s y value when x
equals zero.
For example, the line defined by equation y=5x+3 the y-intercept is b=3.
8
Slope-Intercept Line Equation
continued..
The y-intercept can be calculated by the following equation in terms of the
coordinate of the starting points.
b = Ystart – m Xstart
The y-intercept can also be calculated by the following equation in terms of the
coordinate of the ending points.
b = Yend – m Xend

9
Slope-Intercept Line Equation
continued..
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, in all cases b=0.

Fig. 3.5 Slope representation

10
Horizontal Line Drawing Algorithm
The screen coordinates of the points on a horizontal Line are obtained by
keeping the value of y constant and repeatedly incrementing the x value by one
unit.

Horizontal line with starting point (0,4) and


ending point (8,4) on a pixel based display

Fig. 3.6 Horizontal line representation

11
Horizontal Line Drawing Algorithm
The following code can be used to draw a horizontal line from (Example)
(Xstart, Y) to (Xend, Y) Draw a Horizontal line between points (1,4) and (9,4)
where Xstart  Xend
x = Xstart
y=Y 8 Fig. 3.7 Pixel
7 by pixel
Next: Set pixel (x, y) with desired color
6
x=x+1 5 display of
If x  Xend then go to Next 4 Horizontal
3 1 2 3 4 5 6 7 8 9 line
End
2
Table 3.1 – Calculation of horizontal line pixel coordinates 1
S. No. x = x +1 y Pixel
1 1 4 (1, 4)
2 2 4 (2, 4)
3 3 4 (3, 4)
4 4 4 (4, 4)
5 5 4 (5, 4)
6 6 4 (6, 4)
7 7 4 (7, 4)
8 8 4 (8, 4)
9 9 4 (9, 4)
12
Vertical Line Drawing Algorithm
The screen coordinates of the points on a Vertical Line are obtained by keeping the
value of x constant and repeatedly incrementing the y value by one unit.

A vertical line with starting point (4,0)


and ending point (4,8) on a pixel based
display.

Fig. 3.8 Vertical line representation

13
Vertical Line Drawing Algorithm
The following code can be used to draw a vertical line from (X, Ystart) to
(Example)
(X, Yend), Draw a Horizontal line between points (3,1) and
where Ystart  Yend (3, 9)
x=X 9
8
y = Ystart 7
Next: Set pixel (x, y) with desired color 6
5
y = y+ 1 4
If y  Yend then go to Next 3
End 2
1
Table 3.2 – Calculations of vertical line pixel coordinates 1 2 3 4 5 6 7 8 9
S. No. x y=y+1 Pixel
Fig. 3.9 Pixel by pixel display of vertical line
1 3 1 (3, 1)
2 3 y = 1 + 1 =2 (2, 4)
3 3 y = 2 + 1 =3 (3, 4)
4 3 y = 3 + 1 =4 (4, 4)
5 3 y = 4 + 1 =5 (5, 4)
6 3 y = 5 + 1 =6 (6, 4)
7 3 y = 6 + 1 =7 (7, 4)
8 3 y = 7 + 1 =8 (8, 4)
9 3 y = 8 + 1 =9 (9, 4) 14
Diagonal Line Drawing Algorithm
To draw a diagonal line with a slope equals +1 (m=1), we need only repeatedly
increment by one unit both the x and y values from the starting to the ending pixels.

A diagonal line (m=1) with starting


point (2,2) and ending point (7,7) on a
pixel based display

Fig. 3.10 Diagonal line with m = 1

15
Diagonal Line Drawing Algorithm
(Example)
The following code can be used to draw a diagonal line
Draw a Horizontal line between points (2, 2) and (7, 7)
from (Xstart, Ystart) to (Xend, Yend), where Xstart 
Xend and Ystart  Yend
9
x = Xstart 8
y = Ystart 7
6
Next: Set pixel (x, y) with desired color 5
4
y = y + 1, x = x + 1 3
If x  Xend then go to Next 2
1
End 1 2 3 4 5 6 7 8 9
Fig. 3.11 Pixel by pixel display of diagonal
line with m =1
S. No. x =x+1 y=y+1 Pixel
1 2 2 (2, 2)
2 x=2+1=3 y = 2 + 1 =3 (3. 3)
Table 3.3 – Calculations of diagonal line pixel coordinates
with m = 1 3 x=3+1=4 y = 3 + 1 =4 (4, 4)
4 x=4+1=5 y = 4 + 1 =5 (5, 5)
5 x=5+1=6 y = 5 + 1 =6 (6, 6)
6 x=7 y=7 (7, 7)
16
Diagonal Line Drawing Algorithm

To draw a diagonal line with a slope equals –1 (m=-1), we need only repeatedly
increment by one unit the x and decrementing by one unit the y values from the starting
to the ending pixels.

A diagonal line (m=-1) with starting


point (3,7) and ending point (8,2) on a
pixel based display.

Fig. 3.12 Diagonal line with m = -1

17
Diagonal Line Drawing Algorithm
The following code can be used to draw a diagonal line from (Example)
(Xstart, Ystart) to (Xend, Yend), where Xstart  Xend and Ystart Draw a Horizontal line between points (2, 7) and
 Yend
x = Xstart (7, 2)
y = Ystart
9
Next: Set pixel (x, y) with desired color 8
y=y– 1 7
x=x+1 6
5
If x  Xend then go to Next 4
End 3
2
Table 3.4 – Calculations of diagonal line pixel coordinates 1
with m = -1 1 2 3 4 5 6 7 8 9
S. No. x =x+1 y=y-1 Pixel Fig. 3.13 Pixel by pixel display of diagonal
1 2 7 (2, 7) line with m = -1
2 x=2+1=3 y=7-1=6 (3. 6)
3 x=3+1=4 y=6-1=5 (4, 5)
4 x=4+1=5 y=5-1=4 (5, 4)
5 x=5+1=6 y = 4 - 1 =3 (6, 3)
6 x=7 y=2 (7, 2)

18
References

1. Computer Graphics, 2nd Ed., Hearn & Baker –PHI, New Delhi.

2. Graphics Programming with C By Yashwant Kanetkar, BPB

Publications, New Delhi.

3. Computer Graphics, Schaum’s Outline Series, MGH Publications.

19
THANK YOU

20

You might also like