Unit 2 1
Unit 2 1
Point
Point plotting is done by converting a single coordinate position
furnished by an application program into appropriate operations for the
output device in use.
Example: Plot point 𝑃 (3, 2) 7
6
Line 𝑥 = 3
5
Line 𝑦 = 2 4
Point 𝑃 (3, 2) 3
2
To draw the point on the screen we use function
1
𝑠𝑒𝑡𝑝𝑖𝑥𝑒𝑙 (𝑥, 𝑦)
0
To draw the pixel in C language we use function
0 1 2 3 4 5 6 7
𝑝𝑢𝑡𝑝𝑖𝑥𝑒𝑙 (𝑥, 𝑦, 𝑐𝑜𝑙𝑜𝑟)
Similarly for retrieving color of pixel we have function
𝑔𝑒𝑡𝑝𝑖𝑥𝑒𝑙 (𝑥, 𝑦)
Line
Line drawing is done by calculating intermediate positions along
the line path between two specified endpoint positions.
The output device is then directed to fill in those positions
between the end points with some color.
5
For some device such 5 as a pen plotter or random scan display, a
4
4
straight line can be33 drawn smoothly from one end point to other.
Digital devices display
2
2 a straight line segment by plotting discrete
1
points between the0 two endpoints.
1
0
0 2 4 6
Discrete coordinate positions
1 2
along
3
the
4
line path are calculated
from the equation of the line.
1
8/22/2023
Contd.
Screen locations are referenced with integer values.
So plotted positions may only approximate actual line positions
between two specified endpoints. For example line position of
(12.36, 23.87) would be converted to pixel position (12, 24).
This rounding of coordinate values to integers causes lines to be
displayed with a stair step appearance (“the Jaggies”).
2
8/22/2023
3
8/22/2023
Contd.
We sample at unit 𝑦 interval (∆𝑦 = 1) and calculate each successive 𝑥
value as follow:
𝑥 = (𝑦 − 𝑏)/𝑚
𝑥 = ((𝑦 + 1) − 𝑏)/𝑚 [For first intermediate point]
𝑥 = ((𝑦 + k) − 𝑏)/𝑚 [For 𝑘𝑡ℎ intermediate point]
𝑥 = ((𝑦 + k + 1) − 𝑏)/𝑚 [For 𝑘 + 1 intermediate point]
Subtract 𝑥 from 𝑥
𝑥 − 𝑥 = {((𝑦 + k + 1) − 𝑏)/𝑚} − {((𝑦 + k) − 𝑏)/𝑚}
𝑥 = 𝑥 + 1/𝑚
Similarly
for ∆x = -1: we obtain 𝑦 =𝑦 −𝑚
for ∆y = -1: we obtain 𝑥 = 𝑥 − 1/𝑚
10
4
8/22/2023
11
𝑚= = = 4
3
𝑚 is “+ve” and less than 1 so Δ𝑥 = 1. 2
𝑥 = 2, 𝑦 = 2 1
[Plot the initial point as given] 0
𝑥 = 3, 𝑦 = 𝑦 + 𝑚 = 2 + 0.5 = 2.5 0 1 2 3 4 5 6 7 8
[Plot the first intermediate point by rounding it to (3, 3)]
𝑥 = 4, 𝑦 = 𝑦 + 𝑚 = 2.5 + 0.5 = 3
[Plot the second intermediate point by rounding it to (4, 3)]
𝑥 = 5, 𝑦 = 𝑦 + 𝑚 = 3 + 0.5 = 3.5
[Plot the third intermediate point by rounding it to (5, 4)]
𝑥 = 6, 𝑦 = 4
[Plot End point given]
12
5
8/22/2023
13
14
6
8/22/2023
15
Contd.
Calculate 𝑑 − 𝑑
𝑑 −𝑑 = 𝑚 𝑥 +1 +𝑏−𝑦 − (𝑦 +1 − 𝑚 𝑥 + 1 − 𝑏}
𝑑 − 𝑑 = 𝑚𝑥 + 𝑚 + 𝑏 − 𝑦 − {𝑦 + 1 − 𝑚𝑥 − 𝑚 − 𝑏}
𝑑 − 𝑑 = 2𝑚 𝑥 + 1 − 2𝑦 + 2𝑏 − 1
𝑑 − 𝑑 = 2(∆𝑦/∆𝑥) 𝑥 + 1 − 2𝑦 + 2𝑏 − 1 [Put 𝑚 = Δ𝑦/Δ𝑥]
Decision parameter
𝑝 = ∆𝑥(𝑑 − 𝑑 )
𝑝 = ∆𝑥 {2(∆𝑦/∆𝑥) 𝑥 + 1 − 2𝑦 + 2𝑏 − 1 }
𝑝 = 2∆𝑦𝑥 − 2∆𝑥𝑦 + 2∆𝑦 + 2∆𝑥𝑏 − ∆x
𝑝 = 2∆𝑦𝑥 − 2∆𝑥𝑦 + C [Replacing single constant C for simplicity]
Similarly
𝑝 = 2∆𝑦𝑥 − 2∆𝑥𝑦 +C
16
7
8/22/2023
Contd.
Subtract 𝑝𝑘 from 𝑝
𝑝 − 𝑝 = 2∆𝑦𝑥 − 2∆𝑥𝑦 + C − 2∆𝑦𝑥 + 2∆𝑥𝑦 − C
𝑝 − 𝑝 = 2∆𝑦(𝑥 −𝑥 ) − 2∆𝑥(𝑦 −𝑦 )
[where (𝑥 −𝑥 ) = 1]
𝑝 = 𝑝 + 2∆𝑦 − 2∆𝑥(𝑦 −𝑦 )
[where (𝑦 −𝑦 ) = 0 or 1 depending on selection of previous pixel]
17
18
8
8/22/2023
19
20
9
8/22/2023
21
22
10
8/22/2023
23
Contd.
Numbering the partitions and the processors, as 0, 1, 2, up to
𝑛𝑝 – 1, we calculate the starting 𝑥 coordinate for the 𝑘𝑡ℎ partition
as:
𝑥𝑘 = 𝑥0 + 𝑘∆𝑥𝑝
The change ∆𝑦𝑝 in the 𝑦 direction over each partition is calculated
from the line slope 𝑚 and partition width ∆𝑥𝑝:
∆𝑦𝑝 = 𝑚∆𝑥𝑝
At the 𝑘𝑡ℎ partition, the starting y coordinate is then
𝑦𝑘 = 𝑦0 + 𝑟𝑜𝑢𝑛𝑑(𝑘∆𝑦𝑝)
24
11
8/22/2023
25
26
12
8/22/2023
Contd.
Perpendicular distance d from line to a particular pixel is
calculated by:
𝑑 = 𝐴𝑥 + 𝐵𝑦 + 𝐶
Where
𝐴 = −∆𝑦/𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ
𝐵 = −∆𝑥/𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ
𝐶 = (𝑥 ∆𝑦 − 𝑦 ∆𝑥)/𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ
With
𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ = ∆𝑥 + ∆𝑦
𝐴, 𝐵, and 𝐶 are constant we need to compute only once.
27
Contd.
For the line each processors need to perform two multiplications
and two additions to compute the pixel distance 𝑑.
A pixel is plotted if 𝑑 is less than a specified line thickness
parameter.
Instead of partitioning the screen into single pixels, we can assign
to each processor either a scan line or a column.
Each processor calculates line intersection with horizontal row or
vertical column of pixels assigned to that processor.
28
13
8/22/2023
Contd.
If vertical column is assign to processor then 𝑥 is fix and it will
calculate 𝑦.
Similarly if horizontal row is assign to processor then 𝑦 is fix and 𝑥
will be calculated.
Such direct methods are slow in sequential machine but we can
perform very efficiently using multiple processors.
29
Circle
A circle is defined as the set of points that are all at a given
distance 𝑟 from a center position say (𝑥 , 𝑦 ).
Center
(𝑥 , 𝑦 )
r
Radius
30
14
8/22/2023
31
Contd.
But this is not best method as it requires more number of
calculations which take more time to execute.
And also spacing between the plotted pixel positions is not
uniform.
32
15
8/22/2023
33
(-3, 4) (3, 4)
(-Y, X) (Y, X)
(-4, 3) (4, 3)
(-X, Y) (X, Y)
45𝑂
(-4, -3)
(4, -3)
(-X, -Y)
(X, -Y)
34
16
8/22/2023
Circle Algorithm
Taking advantage of this symmetry property of circle we can
generate all pixel position on boundary of circle by calculating only
one sector from 𝑥 = 0 to 𝑥 = 𝑦.
Determining pixel position along circumference of circle using any
of two equations shown above still required large computation.
More efficient circle algorithm are based on incremental
calculation of decision parameters, as in the Bresenham line
algorithm.
Bresenham’s line algorithm can be adapted to circle generation by
setting decision parameter for finding closest pixel to the
circumference at each sampling step.
35
Contd.
A method for direct distance comparison to test the midpoint
between two pixels to determine if this midpoint is inside or
outside the circle boundary.
This method is easily applied to other conics also.
Midpoint approach generates same pixel position as generated by
bresenham’s circle algorithm.
The error involve in locating pixel positions along any conic section
using midpoint test is limited to one-half the pixel separation.
36
17
8/22/2023
37
38
18
8/22/2023
yk Midpoint
Candidate
yk+1 Pixel
xk xk+1 xk+2
39
𝑝 =𝑓 𝑥 + 1, 𝑦 −
𝑝 = 𝑥 +1 + 𝑦 − −𝑟
If 𝑝 < 0, midpoint is inside the circle and the pixel on the scan
line 𝑦 is closer to circle boundary.
Otherwise midpoint is outside or on the boundary and we select
the scan line 𝑦 − 1.
40
19
8/22/2023
Contd.
Successive decision parameters are obtain using incremental calculations as follows:
𝑝 =𝑓 𝑥 + 1, 𝑦 −
𝑝 = 𝑥 +1 +1 + 𝑦 − −𝑟
Now we can obtain recursive calculation using equation of 𝑝 and 𝑝 as follow
𝑝 −𝑝 = 𝑥 +1 +1 + 𝑦 − −𝑟 − 𝑥 +1 + 𝑦 − −
𝑝 −𝑝 = 𝑥 +1 +2 𝑥 +1 +1+𝑦 −𝑦 + −𝑟 − 𝑥 +1 −
𝑦 +𝑦 − +𝑟
41
Contd.
𝑝 −𝑝 = 𝑥 +1 +2 𝑥 +1 +1+𝑦 −𝑦 + −
𝑟 − 𝑥 +1 −𝑦 +𝑦 − +𝑟
𝑝 −𝑝 =2 𝑥 +1 +1+𝑦 −𝑦 −𝑦 +𝑦
𝑝 − 𝑝 = 2 𝑥 + 1 + (𝑦 − 𝑦 ) − (𝑦 −𝑦 ) + 1
𝑝 = 𝑝 + 2 𝑥 + 1 + (𝑦 − 𝑦 ) − (𝑦 −𝑦 ) + 1
Now we can put 2𝑥 = 2(𝑥 + 1)
𝑝 = 𝑝 + 2𝑥 + (𝑦 − 𝑦 ) − (𝑦 −𝑦 ) + 1
42
20
8/22/2023
Contd.
𝑝 = 𝑝 + 2𝑥 + (𝑦 − 𝑦 ) − (𝑦 −𝑦 ) + 1
In above equation 𝑦 is either 𝑦 or 𝑦 − 1 depending on the
sign of the 𝑝 .
If we select 𝑦 = 𝑦𝑘 .
𝑝 = 𝑝 + 2𝑥 +1
If we select 𝑦 = 𝑦𝑘 – 1.
𝑝 = 𝑝 + 2𝑥 + (𝑦 − 𝑦 ) − (𝑦 −𝑦 ) + 1
𝑝 = 𝑝 + 2𝑥 + (𝑦 +𝑦 )(𝑦 −𝑦 ) − (𝑦 −𝑦 ) + 1
𝑝 = 𝑝 + 2𝑥 + (𝑦𝑘 – 1 + 𝑦 )(𝑦𝑘 – 1 − 𝑦 ) − (𝑦𝑘 – 1 −
𝑦 )+1
𝑝 = 𝑝 + 2𝑥 + (2𝑦𝑘 – 1)(– 1) − (– 1) + 1
43
Contd.
𝑝 = 𝑝 + 2𝑥 − 2𝑦𝑘 + 1 + 1 + 1
𝑝 = 𝑝 + 2𝑥 − (2𝑦𝑘 − 2) + 1
Now put 2𝑦 = 2𝑦 − 2.
𝑝 = 𝑝 + 2𝑥 − 2𝑦 +1
44
21
8/22/2023
𝑝 =𝑓 0 + 1, 𝑟 −
𝑝 =1 + 𝑟− −𝑟
𝑝 =1+𝑟 −𝑟+ −𝑟
𝑝 = −𝑟
𝑝 ≈1−𝑟
45
46
22
8/22/2023
47
Contd.
𝑝 = 𝑝 + 2𝑥 + 1 𝒌 𝒑𝒌 (𝒙𝒌 𝟏 , 𝒚𝒌 𝟏 )
0 -9 (1, 10)
𝑝 = −6 + 4 + 1 = −1
1 -6 (2, 10)
Now 𝑝 < 0 we select (3, 10) 2 -1 (3, 10)
𝑝 = 𝑝 + 2𝑥 + 1 3 6 (4, 9)
𝑝 = −1 + 6 + 1 = 6 4 -3 (5, 9)
5 8 (6, 8)
Now 𝑝 ≮ 0 we select (4, 9)
6 5 (7, 7)
𝑝 = 𝑝 + 2𝑥 + 1 − 2𝑦
𝑝 = 6 + 8 + 1 − 18 = −3
Now 𝑝 < 0 we select (5, 9)
48
23
8/22/2023
Contd.
𝑝 = 𝑝 + 2𝑥 + 1 𝒌 𝒑𝒌 (𝒙𝒌 𝟏 , 𝒚𝒌 𝟏 )
0 -9 (1, 10)
𝑝 = −3 + 10 + 1 = 8
1 -6 (2, 10)
Now 𝑝 ≮ 0 we select (6, 8) 2 -1 (3, 10)
𝑝 = 𝑝 + 2𝑥 + 1 − 2𝑦 3 6 (4, 9)
𝑝 = 8 + 12 + 1 − 16 = 5 4 -3 (5, 9)
5 8 (6, 8)
Now 𝑝 ≮ 0 we select (7, 7)
6 5 (7, 7)
Now Loop exit as 𝑥 ≥ 𝑦, as
in our case 7 ≥ 7
49
Contd.
Than we calculate pixel position for given center 1, 1 using
equations:
Center (0, 0) Center (1, 1)
𝑥 = 𝑥+𝑥 =𝑥+1
(1, 10) (2, 11)
𝑦 =𝑦+𝑦 = 𝑦+1
(2, 10) (3, 11)
(3, 10) (4, 11)
(4, 9) (5, 10)
(5, 9) (6, 10)
(6, 8) (7, 9)
(7, 7) (8, 8)
50
24
8/22/2023
Contd.
Plot the pixel.
12
First plot initial point. 11
(1, 11) 10
9
Center (1, 1)
8
(2, 11) 7
6
(3, 11)
5
(4, 11) 4
(5, 10) 3
(6, 10) 2
Center
1
(7, 9) (1, 1)
0
(8, 8)
0 1 2 3 4 5 6 7 8 9 10 11
51
Ellipse
AN ellipse is defined as the set of points such that the sum of the
distances from two fixed positions (foci) is same for all points.
𝑝(𝑥, 𝑦)
𝑑1
𝑑2
𝑓1 𝑓2
52
25
8/22/2023
Contd.
If we labeled distance from two foci to any point on ellipse
boundary as 𝑑 and 𝑑 then the general equation of an ellipse can
be written as:
𝑑 + 𝑑 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
Expressing distance in terms of focal coordinates 𝑓 = 𝑥 , 𝑦 and
𝑓 = 𝑥 , 𝑦 we have
𝑥−𝑥 + 𝑦−𝑦 + 𝑥−𝑥 + 𝑦−𝑦 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
[Using Distance formula]
53
Properties of Ellipse-Specifying
Equations
An interactive method for specifying an ellipse in an arbitrary
orientation is to input
two foci and
a point on the ellipse boundary.
With this three coordinates we can evaluate constant in equation:
𝑥−𝑥 + 𝑦−𝑦 + 𝑥−𝑥 + 𝑦−𝑦 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
We can also write this equation in the form
𝐴𝑥 + 𝐵𝑦 + 𝐶𝑥𝑦 + 𝐷𝑥 + 𝐸𝑦 + 𝐹 = 0
Where the coefficients 𝐴, 𝐵, 𝐶, 𝐷, 𝐸, and 𝐹 are evaluated in terms
of the focal coordinates and the dimensions of the major and
minor axes of the ellipse.
54
26
8/22/2023
Contd.
Then coefficient in 𝐴𝑥 + 𝐵𝑦 + 𝐶𝑥𝑦 + 𝐷𝑥 + 𝐸𝑦 + 𝐹 = 0 can be
evaluated and used to generate pixels along the elliptical path.
We can say ellipse is in standard position if their major and minor
axes are parallel to x-axis and y-axis.
Ellipse equation are greatly simplified if we align major and minor
axis with coordinate axes i.e. x-axis and y-axis.
X-axis
Y-axis
55
Contd.
Equation of ellipse can be written in terms of the ellipse center
coordinates (𝑥 , 𝑦 ) and parameters 𝑟 and 𝑟 as.
𝑥−𝑥 𝑦−𝑦
+ =1
𝑟 𝑟
Using the polar coordinates r and θ, we can also describe the
ellipse in standard position with the parametric equations:
𝑥 = 𝑥 + 𝑟 cos θ
𝑦 = 𝑦 + 𝑟 sin θ
𝑟 𝑟
(𝑥 , 𝑦 )
56
27
8/22/2023
Properties of Ellipse-Symmetry
Symmetry property further reduced computations.
An ellipse in standard position is symmetric between quadrant.
(−2, 4) (2, 4)
(−𝑥, 𝑦) (𝑥, 𝑦)
𝑟
𝑟
(𝑥 , 𝑦 )
57
58
28
8/22/2023
59
60
29
8/22/2023
61
62
30
8/22/2023
=−
At boundary between region 1 and 2 slope= -1 and equation
become.
2𝑟 𝑥 = 2𝑟 𝑦
Therefore we move out of region 1 whenever following equation
is false:
2𝑟 𝑥 ≤ 2𝑟 𝑦
63
ry2x2+rx2y2-rx2ry2=0
yk Midpoint
yk-1 Candidate
Pixel
xk xk+1 xk+2
𝑝1 = 𝑓 𝑥 + 1, 𝑦 −
64
31
8/22/2023
𝑝1 = 𝑟 (𝑥 + 1) +𝑟 𝑦 − −𝑟 𝑟
If 𝑝1 < 0, the midpoint is inside the ellipse and the pixel on scan
line 𝑦 is closer to ellipse boundary
Otherwise the midpoint is outside or on the ellipse boundary and
we select the pixel 𝑦 − 1.
65
Contd.
At the next sampling position decision parameter for region 1 is
evaluated as.
𝑝1 =𝑓 𝑥 + 1, 𝑦 −
𝑝1 =𝑟 𝑥 +1 +1 +𝑟 𝑦 − −𝑟 𝑟
Now subtract 𝑝1 from 𝑝1
𝑝1 − 𝑝1 = 𝑟 𝑥 +1 +1 +𝑟 𝑦 − −𝑟 𝑟 −
𝑟 (𝑥 + 1) −𝑟 𝑦 − +𝑟 𝑟
66
32
8/22/2023
Contd.
𝑝1 − 𝑝1 = 𝑟 𝑥 +1 +1 +𝑟 𝑦 − −
𝑟 (𝑥 + 1) −𝑟 𝑦 −
𝑝1 − 𝑝1 = 𝑟 𝑥 +1 + 2𝑟 𝑥 +1 +𝑟 +𝑟 𝑦 −
− 𝑟 (𝑥 + 1) −𝑟 𝑦 −
𝑝1 − 𝑝1 = 2𝑟 𝑥 +1 +𝑟 +𝑟 𝑦 − − 𝑦 −
Now making 𝑝1 as subject.
𝑝1 = 𝑝1 + 2𝑟 𝑥 +1 +𝑟 +𝑟 𝑦 − − 𝑦 −
67
Contd.
𝑝1 = 𝑝1 + 2𝑟 𝑥 +1 +𝑟 +𝑟 𝑦 − −
𝑦 −
𝑦 is either 𝑦 or 𝑦 − 1, depends on the sign of 𝑝1
68
33
8/22/2023
𝑝1 = 𝑓 0 + 1, 𝑟 −
𝑝1 = 𝑟 (1) +𝑟 𝑟 − −𝑟 𝑟
𝑝1 = 𝑟 +𝑟 𝑟 − −𝑟 𝑟
𝑝1 = 𝑟 −𝑟 𝑟 + 𝑟
69
yk Midpoint
yk-1 Candidate
Pixel
xk xk+1 xk+2
For this region, the decision parameter is evaluated as follows.
𝑝2 = 𝑓 𝑥 + ,𝑦 −1
70
34
8/22/2023
𝑝2 = 𝑟 𝑥 + +𝑟 𝑦 −1 −𝑟 𝑟
If 𝑝2 > 0 the midpoint is outside the ellipse boundary, and we
select the pixel at 𝑥 .
If 𝑝2 ≤ 0 the midpoint is inside or on the ellipse boundary and
we select 𝑥 + 1.
71
Contd.
At the next sampling position decision parameter for region 2 is
evaluated as.
𝑝2 =𝑓 𝑥 + ,𝑦 −1
𝑝2 =𝑟 𝑥 + +𝑟 𝑦 −1 −1 −𝑟 𝑟
Now subtract 𝑝2 from 𝑝2
𝑝2 − 𝑝2 = 𝑟 𝑥 + +𝑟 𝑦 −1 −1 −𝑟 𝑟 −
𝑟 𝑥 + −𝑟 𝑦 −1 +𝑟 𝑟
72
35
8/22/2023
Contd.
𝑝2 − 𝑝2 = 𝑟 𝑥 + +𝑟 𝑦 −1 −1 −𝑟 𝑟 −
𝑟 𝑥 + −𝑟 𝑦 −1 +𝑟 𝑟
𝑝2 − 𝑝2 = 𝑟 𝑥 + +𝑟 𝑦 −1 − 2𝑟 𝑦 −1 +
𝑟 −𝑟 𝑥 + −𝑟 𝑦 −1
𝑝2 − 𝑝2 = 𝑟 𝑥 + − 2𝑟 𝑦 −1 +𝑟 −𝑟 𝑥 +
𝑝2 − 𝑝2 = −2𝑟 𝑦 −1 +𝑟 +𝑟 𝑥 + − 𝑥 +
73
Contd.
𝑝2 − 𝑝2 = −2𝑟 𝑦 −1 +𝑟 +𝑟 𝑥 + −
𝑥 +
Now making 𝑝2 as subject.
𝑝2 = 𝑝2 − 2𝑟 𝑦 −1 +𝑟 +𝑟 𝑥 + −
𝑥 +
Here 𝑥 is either 𝑥 or 𝑥 + 1, depends on the sign of 𝑝2 .
74
36
8/22/2023
𝑝2 = 𝑓 𝑥 + ,𝑦 − 1
𝑝2 = 𝑟 𝑥 + +𝑟 𝑦 −1 −𝑟 𝑟
For simplify calculation of 𝑝2 we could also select pixel position
in counterclockwise order starting at (𝑟 , 0).
75
76
37
8/22/2023
Contd.
4. Calculate the initial value of the decision parameter in region 2 using the last
point 𝑥 , 𝑦 calculated in region 1 as
𝑝2 = 𝑟 𝑥 + +𝑟 𝑦 −1 −𝑟 𝑟
7. Move each calculated pixel position (𝑥, 𝑦) onto the elliptical path centered on
(𝑥 , 𝑦 ) and plot the coordinate values:
𝑥 =𝑥+𝑥 ,𝑦 =𝑦+𝑦
77
𝑝1 = 𝑟 −𝑟 𝑟 + 𝑟
𝑝1 = 6 − 8 ∗ 6 + 8
𝑝1 = −332
78
38
8/22/2023
Contd.
𝑝1 = −332 K p1k (xk+1, yk+1)
0 -332 (1, 6)
𝑝1 = 𝑝1 + 2𝑟 𝑥 +1 +𝑟 + 1 -224 (2, 6)
𝑟 𝑦 − − 𝑦 − 2 -44 (3, 6)
3 208 (4, 5)
𝑝1 = −332 + 2 ∗ 6 0 + 1 + 6 +
4 -108 (5, 5)
5 288 (6, 4)
8 6− − 6− = −224
6 244 (7, 3)
79
Contd.
𝑝1 = 𝑝1 + 2𝑟 𝑥 +1 +𝑟 + K p1k (xk+1, yk+1)
𝑟 𝑦 − − 𝑦 −
0 -332 (1, 6)
1 -224 (2, 6)
2 -44 (3, 6)
𝑝1 = −224 + 2 ∗ 6 1 + 1 + 6 +
3 208 (4, 5)
8 6− − 6− = −44
4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)
80
39
8/22/2023
Contd.
𝑝1 = 𝑝1 + 2𝑟 𝑥 +1 +𝑟 + K p1k (xk+1, yk+1)
𝑟 𝑦 − − 𝑦 −
0 -332 (1, 6)
1 -224 (2, 6)
2 -44 (3, 6)
𝑝1 = −44 + 2 ∗ 6 2 + 1 + 6 +
3 208 (4, 5)
8 6− − 6− = 208
4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)
81
Contd.
𝑝1 = 𝑝1 + 2𝑟 𝑥 +1 +𝑟 + K p1k (xk+1, yk+1)
𝑟 𝑦 − − 𝑦 −
0 -332 (1, 6)
1 -224 (2, 6)
2 -44 (3, 6)
𝑝1 = 208 + 2 ∗ 6 3 + 1 + 6 +
3 208 (4, 5)
8 5− − 6− = −108
4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)
82
40
8/22/2023
Contd.
𝑝1 = 𝑝1 + 2𝑟 𝑥 +1 +𝑟 + K p1k (xk+1, yk+1)
𝑟 𝑦 − − 𝑦 −
0 -332 (1, 6)
1 -224 (2, 6)
2 -44 (3, 6)
𝑝1 = −108 + 2 ∗ 6 4 + 1 + 6 +
3 208 (4, 5)
8 5− − 5− = 288
4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)
83
Contd.
𝑝1 = 𝑝1 + 2𝑟 𝑥 +1 +𝑟 + K p1k (xk+1, yk+1)
𝑟 𝑦 − − 𝑦 −
0 -332 (1, 6)
1 -224 (2, 6)
2 -44 (3, 6)
𝑝1 = 288 + 2 ∗ 6 5 + 1 + 6 +
3 208 (4, 5)
8 4− − 5− = 244
4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)
84
41
8/22/2023
Contd.
K p2k (xk+1, yk+1)
𝑝2 = 𝑟 𝑥 + +𝑟 𝑦 −1 −
0 -23 (8, 2)
𝑟 𝑟
1 361 (8, 1)
2 297 (8, 0)
𝑝2 = 6 7+ +8 3−1 −
8 6 = −23
85
Contd.
𝑝2 = 𝑝2 − 2𝑟 𝑦 −1 +𝑟 + K p2k (xk+1, yk+1)
𝑟 𝑥 + − 𝑥 + 0 -23 (8, 2)
1 361 (8, 1)
𝑝2 = −23 − 2 ∗ 8 3−1 +8 +
2 297 (8, 0)
6 8+ − 7+ = 361
86
42
8/22/2023
Contd.
𝑝2 = 𝑝2 − 2𝑟 𝑦 −1 +𝑟 + K p2k (xk+1, yk+1)
𝑟 𝑥 + − 𝑥 + 0 -23 (8, 2)
1 361 (8, 1)
𝑝2 = 361 − 2 ∗ 8 2−1 +8 +
2 297 (8, 0)
6 8+ − 8+ = 297
87
Contd.
Plot the pixel.
12
Plot initial point(0, 6) 11
Center (0, 0) Center (0, 0) 10
9
(1, 6) (8, 2) 8
(2, 6) (8, 1) 7
(3, 6) 6
(8, 0)
5
(4, 5) 4
(5, 5) 3
(6, 4) 2
(7, 3) 1
Center 0
(0, 0) 0 1 2 3 4 5 6 7 8 9 10 11
88
43
8/22/2023
Filled-Area Primitives
In practical we often use polygon which are filled with some
colour or pattern inside it.
There are two basic approaches to area filling on raster systems.
• One way to fill an area is to determine the overlap intervals for scan line
that cross the area.
• Another method is to start from a given interior position and paint outward
from this point until we encounter boundary.
89
Scan line
90
44
8/22/2023
Contd.
Scan line intersects at vertex are required special handling.
For vertex we must look at the other endpoints of the two line
segments which meet at this vertex.
• If these points lie on the same (up or down) side of the scan line, then that
point is counts as two intersection points.
• If they lie on opposite sides of the scan line, then the point is counted as
single intersection.
Scan line
Scan line
Scan line
91
𝑚=
Since change in 𝑦 coordinates between the two scan lines is
simply
𝑦 −𝑦 =1
92
45
8/22/2023
Contd.
So slope equation can be modified as follows
𝑚=
𝑚=
𝑥 −𝑥 =
𝑥 =𝑥 +
Each successive 𝑥 intercept can thus be calculated by adding the
inverse of the slope and rounding to the nearest integer.
93
𝑥 =𝑥 +
∆
Now if we put 𝑚 = in incremental calculation equation 𝑥 =
∆
𝑥 + then we obtain equation as.
∆
𝑥 =𝑥 +
∆
Using this equation we can perform integer evaluation of 𝑥
intercept.
94
46
8/22/2023
Counter=3
Counter=2
Counter=4
Counter=6
Counter=1
Counter=5
Counter=0
𝑦
𝑥
95
96
47
8/22/2023
Contd.
Scan Line
Number
𝑦 𝑦 𝑥 1/𝑚
B .
.
.
𝑦 𝑦 𝑥 1/𝑚
Scan Line 𝑦 .
C . 𝑦 𝑥 1/𝑚
.
C E 𝑦
Scan Line 𝑦 𝑦 𝑥 1/𝑚
Scan Line 𝑦 D .
.
A . 𝑦 𝑥 1/𝑚
1
0
97
Inside-Outside Tests
In area filling and other graphics operation often required to find
particular point is inside or outside the polygon.
For finding which region is inside or which region is outside most
graphics package use either
1. Odd even rule OR
2. Nonzero winding number rule
98
48
8/22/2023
1 2
𝑝
𝑟
1
𝑞
99
Winding number=0
100
49
8/22/2023
Contd.
The line we choose must not pass through vertices.
Then we move along that line we find number of intersecting
edges.
1. If edge cross our line from right to left We add 1 to winding number
2. Otherwise subtract 1 from winding number
IF the final value of winding number is nonzero then the point is
interior otherwise point is exterior. Boundary of Screen
-1 -1
Winding number=+1-1=0
number=0
number=-1
𝑝
𝑟
+1
𝑞
101
102
50
8/22/2023
103
104
51
8/22/2023
Contd.
In some cases, an 8-connected algorithm is more accurate than
the 4-connected algorithm.
Some times 4-connected algorithm produces the partial fill.
Seed
105
106
52
8/22/2023
107
Contd.
Then we locate and stack starting positions for spans on the
adjacent scan lines.
Spans are defined as the contiguous horizontal string of positions
bounded by pixels displayed in the area border colour.
At each subsequent step, we unstack the next start position and
repeat the process.
For e.g.
108
53
8/22/2023
Contd.
3
2
(a) (b)
1 2 1 3
1 1
5 6 5
6
(c) 4 5 (d) 4 5
1 4 1 4
1 1
109
Introduction to Flood-Fill
Algorithm
Sometimes it is required to fill in an area that is not defined within
a single colour boundary.
In such cases we can fill areas by replacing a specified interior
colour instead of searching for a boundary colour.
This approach is called a flood-fill algorithm. Like boundary fill
algorithm, here we start with some seed and examine the
neighbouring pixels.
However, here pixels are checked for a specified interior colour
instead of boundary colour and they are replaced by new colour.
Using either a 4-connected or 8-connected approach, we can step
through pixel positions until all interior point have been filled.
110
54
8/22/2023
Flood-Fill Algorithm
Procedure :
flood-fill4(x, y, new-colour, old-colour)
{
if(getpixel (x,y) = = old-colour)
{
putpixel (x, y, new-colour)
flood-fill4 (x + 1, y, new-colour, old -colour);
flood-fill4 (x, y + 1, new -colour, old -colour);
flood-fill4 (x - 1, y, new -colour, old -colour);
flood-fill4 (x, y - l, new -colour, old-colour);
}
}
111
55