0% found this document useful (0 votes)
10 views167 pages

CG Chapter 4

Chapter 4 discusses various aspects of geometry and line generation in computer graphics, including point representation, line drawing algorithms (DDA and Bresenham's), and techniques for plotting curves and polygons. It covers the mathematical foundations for drawing lines and circles, as well as algorithms for filling shapes and generating text. The chapter emphasizes the importance of efficient algorithms for rendering graphics accurately on digital devices.

Uploaded by

Shafi Esa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views167 pages

CG Chapter 4

Chapter 4 discusses various aspects of geometry and line generation in computer graphics, including point representation, line drawing algorithms (DDA and Bresenham's), and techniques for plotting curves and polygons. It covers the mathematical foundations for drawing lines and circles, as well as algorithms for filling shapes and generating text. The chapter emphasizes the importance of efficient algorithms for rendering graphics accurately on digital devices.

Uploaded by

Shafi Esa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 167

Chapter 4

Geometry and Line Generation


4.1. Point and Lines, Bresenham’s Algorithm Generating Circles
4.2. Plotting General Curves
4.3. Line Thickness
4.4. Line Style
4.5. Polygons
4.6. Filling
4.7. Text and Characters
Outline
▪ Points
▪ Line drawing algorithms.
▪ Circle drawing algorithm.
▪ Ellipse drawing algorithm.
▪ Scan-Line polygon filling algorithm.
▪ Inside-Outside test.
▪ Boundary fill algorithm.
▪ Flood fill algorithm.
▪ Character generation.
▪ Line attributes.
▪ Color and grayscale levels
▪ Area fill attributes.
▪ Character attributes.
Point
▪ A point in computer graphics is a single location in a two-
dimensional space, represented by its x and y coordinates.
▪ The simplest geometric entity, represented by coordinates (x, y) in
2D space.
▪ Point plotting is done by converting a single coordinate position
furnished by an application program into appropriate operations for
the output device in use. 6

▪ Example: Plot point 𝑃 (3, 2) 4

➢ Line 𝑥 = 3 2

➢ Line 𝑦 = 2 0

➢ Point 𝑃 (3, 2) 0 2 4 6

▪ To draw the point on the screen we use function


✓ 𝒔𝒆𝒕𝒑𝒊𝒙𝒆𝒍 (𝒙, 𝒚)
▪ To draw the pixel in C /C++ language we use function
✓ 𝒑𝒖𝒕𝒑𝒊𝒙𝒆𝒍 (𝒙, 𝒚, 𝒄𝒐𝒍𝒐𝒓)
▪ 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.
▪ For some device such as a pen plotter or random scan display, a
5
straight line can be4 drawn smoothly from one end point to other.
▪ Digital devices display
3 a straight line segment by plotting discrete
points between the2two endpoints.
1

▪ Discrete coordinate
0 positions along the line path are calculated
1 2 3 4
from the equation of the line. 6

0
0 5
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”).
Line Drawing Algorithms
▪ The Cartesian slop-intercept equation for a straight line is
• 𝒚 = 𝒎𝒙 + 𝒃
• with ‘𝒎’ representing slop and ‘𝒃’ as the intercept.
▪ It is also known as Direct use of Line Equation
▪ It is possible to draw line using this equation but for
efficiency purpose we use different line drawing
algorithm.
• DDA Algorithm
• Bresenham’s Line Algorithm
▪ We can also use this algorithm in parallel if we have
more number of processors.
▪ The slope-intercept equation of a straight line is:
▪ Y=mx+b …………….(i) Where m = slope of line and, b = y-intercept.

Fig: Line path between two end points (x1, y1), and (x2, y2)

▪ Suppose (x1, y1), and (x2, y2) are the two end points of a line
segment as shown in fig above.
y 2 − y1
▪ Then slope (m) = x2 − x1
▪ From above equation (i) becomes,
▪ Therefore b= y- y 2 − y1 x …………………….(ii)
x2 − x1
▪ For any point (xk,yk), equation (i) becomes,
▪ Yk =mxk +b……………. (iii)
▪ For any point (xk+1,yk+1), equation (i) becomes,
▪ yk+1 = mxk+1 +b ……………(iv)
▪ Subtracting equation (iii) from (iv) we get,
▪ yk+1 – yk = (mxk+1 +b) – (mxk +b) ………….(v)
▪ = m(xk+1 -xk )
▪ So, Δy= m.Δx, where Δx and Δy are x and y-increment
respectively.
▪ m = Δy/Δx …………………..(vi)
Introduction to DDA Algorithm
▪ Full form of DDA is Digital Differential Analyzer
▪ DDA is scan conversion line drawing algorithm based on
calculating either ∆𝑦 or ∆𝑥 using line equation.
▪ We sample the line at unit intervals in one coordinate and
find corresponding integer values nearest the line path for
the other coordinate.
▪ Selecting unit interval in either 𝑥 or 𝑦 direction based on
way we process line.
Unit Step Direction in DDA
Algorithm
▪ Processing from left to right.
✓ Slope is “+ve”, & Magnitude is Less than 1
Δ𝑋 = 1
✓ Slope is “-ve”, & Magnitude is Less than 1
✓ Slope is “+ve”, & Magnitude is greater than 1 Δ𝑌 = 1
✓ Slope is “-ve”, & Magnitude is greater than 1 Δ𝑌 = −1

▪ Processing from right to left.


✓ Slope is “+ve”, & Magnitude is Less than 1
Δ𝑋 = −1
✓ Slope is “-ve”, & Magnitude is Less than 1
✓ Slope is “+ve”, & Magnitude is greater than 1 Δ𝑌 = −1
✓ Slope is “-ve”, & Magnitude is greater than 1 Δ𝑌 = 1
Derivation of DDA Algorithm
▪ We sample at unit 𝑥 interval (∆𝑥 = 1) and calculate each successive 𝑦
value as follow:
▪ 𝑦 = 𝑚𝑥 + 𝑏
▪ 𝑦1 = 𝑚 𝑥 + 1 + 𝑏 [For first intermediate point]
▪ 𝑦𝑘 = 𝑚 𝑥 + 𝑘 + 𝑏 [For 𝑘𝑡ℎ intermediate point]
▪ 𝑦𝑘+1 = 𝑚 𝑥 + 𝑘 + 1 + 𝑏 [For 𝑘 + 1𝑡ℎ intermediate point]
▪ Subtract 𝑦𝑘 from 𝑦𝑘+1
▪ 𝑦𝑘+1 − 𝑦𝑘 = 𝑚 𝑥 + 𝑘 + 1 + 𝑏 − 𝑚 𝑥 + 𝑘 − 𝑏
▪ 𝑦𝑘+1 = 𝑦𝑘 + 𝑚
▪ Using this equation computation becomes faster than normal line
equation.
▪ As 𝒎 is any real value calculated 𝒚 value must be rounded to nearest
integer.
Contd.
▪ We sample at unit 𝑦 interval (∆𝑦 = 1) and calculate each
successive 𝑥 value as follow:
▪ 𝑥 = (𝑦 − 𝑏)/𝑚
▪ 𝑥1 =((𝑦+1)−𝑏)/𝑚 [For first intermediate point]
▪ 𝑥𝑘 =((𝑦+k)−𝑏)/𝑚 [For 𝑘𝑡ℎ intermediate point]
▪ 𝑥𝑘+1 =((𝑦+k+1)−𝑏)/𝑚 [For 𝑘 + 1𝑡ℎ intermediate point]
Subtract 𝑥𝑘 from 𝑥𝑘+1
▪ 𝑥𝑘+1 − 𝑥𝑘 ={((𝑦+k+1)−𝑏)/𝑚} − {((𝑦+k)−𝑏)/𝑚}
▪ 𝑥𝑘+1 = 𝑥𝑘 + 1/𝑚
Similarly
▪ for ∆x = -1: we obtain 𝒚𝒌+𝟏 = 𝒚𝒌 − 𝒎
▪ for ∆y = -1: we obtain 𝒙𝒌+𝟏 = 𝒙𝒌 − 𝟏/𝒎
▪ Algorithm
▪ Step 1: Start
▪ Step 2: Input the line endpoints and store the left endpoint in (x1, y1) and right end point
in (x2, y2).
▪ Step 3: Calculate the values of dx and dy,
• dx = x2 – x1
• dy = y2 – y1.
▪ Step 4: if( abs(dx) > abs(dy)) then
• steplength = abs(dx)
• else
• steplength = abs(dy)
▪ Step 5: Calculate the values of x-increment and y-increment as,
• xIncrement = dx/ steplength
• yIncrment = dy/ steplength
• Step 6: set x=x1 and y=y1;
▪ Step 7: draw the pixel (round(x), round(y));
▪ Step 8: for k=0 to steplength do
• x = x + xIncrement
• y = y + yIncrement
▪ Draw the pixel (round(x), round(y));
▪ Step 9: End
Procedure for DDA line algorithm.
Void lineDDA (int xa, int ya, int xb, int yb)
{
int dx = xb – xa, dy = yb – ya, steps, k;
float xincrement, yincrement, x = xa, y = ya;
if (abs(dx)>abs(dy))
{
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));
}
}
Example DDA Algorithm
▪ Example: Draw line 𝐴𝐵 with coordinates 𝐴(2,2), 𝐵(6,4).
4−2 2 1
▪ 𝑚= = = 4
6−2 4 2
3
▪ 𝑚 is “+ve” and less than 1 so Δ𝑥 = 1. 2
▪ 𝑥0 = 2, 𝑦0 = 2 1
[Plot the initial point as given] 0

▪ 𝑥1 = 3, 𝑦1 = 𝑦0 + 𝑚 = 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)]
▪ 𝑥2 = 4, 𝑦2 = 𝑦1 + 𝑚 = 2.5 + 0.5 = 3
[Plot the second intermediate point by rounding it to (4, 3)]
▪ 𝑥3 = 5, 𝑦3 = 𝑦2 + 𝑚 = 3 + 0.5 = 3.5
[Plot the third intermediate point by rounding it to (5, 4)]
▪ 𝑥4 = 6, 𝑦4 = 4
[Plot End point given]
Example 1: Digitize the line with endpoints (1, 5) and (7, 2) using DDA
algorithm
▪ Here, dx = 7-1=6 and dy = 2-5 = -3
▪ So, steplength = 6 (since abs(dx)>abs(dy))
▪ Therefore, xIncrement = dx/steplength = 6/6 = 1
▪ yIncrement = dy/steplength = -3/6 = -1/2 = -0.5
▪ Based on these values the intermediate pixel calculation is shown in the table below
k xk+1 yk+1 (xk+1, Plot in screen (xk+1, yk+1)
yk+1)
1 2 4.5 (2, 4.5) (2, 5)
2 3 4 (3, 4) (3, 4)
3 4 3.5 (4, 3.5) (4,4)
4 5 3 (5,3) (5,3)
5 6 2.5 (6,2.5) (6,3)
6 7 2 (7,2) (7,2)

▪ Example 2: Digitize the line with endpoints (1, -6) and (4, 4) using DDA algorithm.
▪ Example 3: Digitize the line with endpoints (1, 6), (6, 10) using DDA algorithm.
▪ Example 4: Trace DDA algorithm for line with endpoints (1, 2), (5, 6).
▪ Example 5: Trace DDA algorithm for endpoints (1, 7), (6, 3).
Introduction to Bresenham’s Line
Algorithm
▪ An accurate and efficient raster line-generating algorithm,
developed by Bresenham.
▪ It scan converts line using only incremental integer calculations.
▪ That can be modified to display circles and other curves.
▪ Based on slop we take unit step in one direction and decide pixel
of other direction from two candidate pixel.
▪ If |Δ𝑥| > |Δ𝑦| we sample at unit 𝒙 interval and vice versa.
Line Path & Candidate pixel
▪ Example |ΔX| > |ΔY|, and ΔY is “+ve”. 4
3
➢ Initial point (Xk, Yk) 2
➢ Line path 1
0
➢ Candidate pixels {(Xk+1, Yk), (Xk+1, Yk+1)}
0 1 2 3 4

▪ Now we need to decide which candidate pixel is more closer to


actual line.
▪ For that we use decision parameter (Pk) equation.
▪ Decision parameter can be derived by calculating distance of
actual line from two candidate pixel.
Derivation Bresenham’s Line
Algorithm
▪ 𝑦 = 𝑚𝑥 + 𝑏 [Line Equation] 4
3
▪ 𝑦 = 𝑚(𝑥𝑘 ) + 𝑏 [Actual Y value at Xk position] 2
▪ 𝑦 = 𝑚(𝑥𝑘 + 1) + 𝑏 [Actual Y value at Xk +1position] 1
0
Distance between actual line position and lower candidate
0 1 2 3 4
pixel
▪ 𝑑1 = 𝑦 − 𝑦𝑘
▪ 𝑑1 = 𝑚(𝑥𝑘 + 1) + 𝑏 − 𝑦𝑘
Distance between actual line position and upper
candidate pixel
▪ 𝑑2 = (𝑦𝑘 +1) − 𝑦
▪ 𝑑2 = (𝑦𝑘 +1) − 𝑚 𝑥𝑘 + 1 − 𝑏
Contd.
Calculate 𝑑1 − 𝑑2
▪ 𝑑1 − 𝑑2 = 𝑚 𝑥𝑘 + 1 + 𝑏 − 𝑦𝑘 − (𝑦𝑘 +1 − 𝑚 𝑥𝑘 + 1 − 𝑏}
▪ 𝑑1 − 𝑑2 = 𝑚𝑥𝑘 + 𝑚 + 𝑏 − 𝑦𝑘 − {𝑦𝑘 + 1 − 𝑚𝑥𝑘 − 𝑚 − 𝑏}
▪ 𝑑1 − 𝑑2 = 2𝑚 𝑥𝑘 + 1 − 2𝑦𝑘 + 2𝑏 − 1
▪ 𝑑1 − 𝑑2 = 2(∆𝑦/∆𝑥) 𝑥𝑘 + 1 − 2𝑦𝑘 + 2𝑏 − 1 [Put 𝑚 = Δ𝑦/Δ𝑥]
Decision parameter
▪ 𝑝𝑘 = ∆𝑥(𝑑1 − 𝑑2 )
▪ 𝑝𝑘 = ∆𝑥 {2(∆𝑦/∆𝑥) 𝑥𝑘 + 1 − 2𝑦𝑘 + 2𝑏 − 1 }
▪ 𝑝𝑘 = 2∆𝑦𝑥𝑘 − 2∆𝑥𝑦𝑘 + 2∆𝑦 + 2∆𝑥𝑏 − ∆x
▪ 𝑝𝑘 = 2∆𝑦𝑥𝑘 − 2∆𝑥𝑦𝑘 + C [Replacing single constant C for simplicity]
Similarly
▪ 𝑝𝑘+1 = 2∆𝑦𝑥𝑘+1 − 2∆𝑥𝑦𝑘+1 + C
Contd.
Subtract 𝑝𝑘 from 𝑝𝑘+1
▪ 𝑝𝑘+1 − 𝑝𝑘 = 2∆𝑦𝑥𝑘+1 − 2∆𝑥𝑦𝑘+1 + C − 2∆𝑦𝑥𝑘 + 2∆𝑥𝑦𝑘 − C
▪ 𝑝𝑘+1 − 𝑝𝑘 = 2∆𝑦(𝑥𝑘+1 −𝑥𝑘 ) − 2∆𝑥(𝑦𝑘+1 −𝑦𝑘 )
[where (𝑥𝑘+1 −𝑥𝑘 ) = 1]
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦 − 2∆𝑥(𝑦𝑘+1 −𝑦𝑘 )
[where (𝑦𝑘+1 −𝑦𝑘 ) = 0 or 1 depending on selection of previous pixel]
Initial Decision parameter
▪ The first decision parameter 𝑝0 is calculated using equation of 𝑝𝑘.
▪ 𝑝𝑘 = 2∆𝑦𝑥𝑘 − 2∆𝑥𝑦𝑘 + 2∆𝑦 + 2∆𝑥𝑏 − ∆x
▪ 𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥𝑏 − ∆x [Put 𝑘 = 0]
▪ 𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥 𝑦0 − 𝑚𝑥0 − ∆x
[Substitute 𝑏 = 𝑦0 – 𝑚𝑥0]
▪ 𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥(𝑦0 − (∆𝑦/∆𝑥)𝑥0 ) − ∆x
[Substitute 𝑚 = ∆𝑦/Δ𝑥]
▪ 𝑝0 = 2∆𝑦𝑥0 − 2∆𝑥𝑦0 + 2∆𝑦 + 2∆𝑥𝑦0 − 2∆𝑦𝑥0 − ∆x
▪ 𝑝0 = 2∆𝑦 − ∆x
[Initial decision parameter with all terms are constant]
Bresenham’s Line Algorithm
1. Input the two line endpoints and store the left endpoint in (𝑥0 , 𝑦0 ).
2. Load (𝑥0 , 𝑦0 ) into the frame buffer; that is, plot the first point.
3. Calculate constants ∆𝑥, ∆𝑦, 2∆𝑦, and 2∆𝑦 − 2∆𝑥, and obtain the
starting value for the decision parameter as
𝑝0 = 2∆𝑦 − ∆𝑥
4. At each 𝑥𝑘 along the line, starting at 𝑘 = 0, perform the following test:
If 𝑝𝑘 < 0, the next point to plot is (𝑥𝑘 + 1, 𝑦𝑘 ) and
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦
Otherwise, the next point to plot is (𝑥𝑘 + 1, 𝑦𝑘 + 1) and
𝑝𝑘+1 = 𝑝𝑘 + 2∆𝑦 − 2∆𝑥
5. Repeat step-4 ∆𝑥 times.
▪ Algorithm
▪ Step 1: Start
▪ Step 2: Input the two line endpoint and store the left endpoint at and right endpoint at
▪ Step 3: calculate ∆x=abs(x1-x0), ∆y=abs(y1-y0);
▪ Step 4: calculate initial decision parameter as,
▪ Step 4: if x1>x0 then
▪ Set x=x0
▪ Set y=y0
▪ Set xend=x1;
▪ Otherwise
▪ Set x=x1
▪ Set y=y1
▪ Set xend=x0;
▪ Step 5: draw pixel at(x, y)
▪ Step 6: while(x<xend)
▪ x ++;
▪ if p<0 then
▪ p=p+2∆y
▪ otherwise
▪ y++
▪ p=p+2∆y-2∆x
▪ draw pixel at(x, y)
▪ Step 7: Stop
Description of Bresenham’s Line Algorithm
▪ Bresenham’s algorithm is generalized to lines with arbitrary slope.
▪ For lines with positive slope greater than 1 we interchange the
roles of the 𝑥 and 𝑦 directions.
▪ Also we can revise algorithm to draw line from right endpoint to
left endpoint, both 𝑥 and 𝑦 decrease as we step from right to left.
▪ When 𝑝𝑘 = 0 we can choose either lower or upper pixel but same
for whole line.
▪ For the negative slope the procedure are similar except that now
one coordinate decreases as the other increases.
▪ The special case handle separately by loading directly into the
frame buffer without processing.
✓ Horizontal line (∆𝑦 = 0),
✓ Vertical line (∆𝑥 = 0)
✓ Diagonal line with |∆𝑥| = |∆𝑦|
▪ Example: Digitize a line with end points (10, 15) and (15, 18) using BSA.
▪ Here, △y = |18-15| = 3
▪ △x = |15-10| = 5
▪ Since, |m|= △y/△x ≤ 1, so we sample at x direction i.e., at each step we simply
increment x-coordinate by 1 and find appropriate y-coordinate.
▪ First pixel to plot is (10, 15), which is the starting endpoint.
▪ Now, initial decision parameter, p0 = 2△y – △x = 2 * 3- 5 = 1
▪ We know that, If pk < 0, then we need to set pk+1 = pk+2△y and
plot pixel (xk+1, yk)
▪ And if pk ≥ 0, then we need to set pk+1 = pk + 2 △y – 2 △x then
plot pixel (xk+1, yk+1)
▪ Here p0 = 1, we have i.e., pk ≥0
▪ So, p1 = p0 + 2 △y – 2 △x = 1 + 2 * 3 – 2 x 5 = -3
▪ p2 = p1+ 2 △y = -3+2 * 3 = 3.
▪ p3 = p2 + 2 △y – 2 △x = 3+6-10 = -1.
▪ p4 = p3 + 2 △y = -1+ 6 = 5
▪ Successive pixel positions and decision parameter calculation is shown in
the table below.
k x y pk (xk+1, yk+1)
0 10 15 1(>=0) (11, 16)
1 11 16 -3(<0) (12, 16)
2 12 16 3 (13, 17)
3 13 17 -1 (14, 17)

Exercises 4 14 17 5 (15, 18)

1. Digitize the line with endpoints (1, -6) and (4, 4) using BSA/BLA
algorithm.
2. Digitize the line with endpoints (1, 6), (6, 10) using BSA algorithm.
3. Trace BSA for line with endpoints (15, 15), (10, 11).
4. Trace BSA for line with endpoints (20, 10), (30, 18).
5. Trace BSA for endpoints (5, 10), (10, 7).
6. Trace BSA for endpoints (20, 30), (30, 22)
▪ Example: Draw line 𝑨𝑩 with coordinates 𝑨(𝟐, 𝟐), 𝑩(𝟔, 𝟒).
▪ Plot left end point 𝐴(2, 2).
▪ Calculate:
• ∆𝑥 = 4,
• ∆𝑦 = 2, 4
3
• 2∆𝑦 = 4, 2
• 2∆𝑦 − 2∆𝑥 = −4, 1
▪ 𝑝0 = 2∆𝑦 − ∆𝑥 = 0 0

▪ Now 𝑝0 ≮ 0 so we select upper pixel (3, 3). 0 1 2 3 4 5 6 7 8


▪ 𝑝1 = 𝑝0 + 2∆𝑦 − 2∆𝑥 = 0 + −4 = −4
▪ Now 𝑝1 < 0 so we select lower pixel (4, 3).
▪ 𝑝2 = 𝑝1 + 2∆𝑦 = −4 + 4 = 0
▪ Now 𝑝2 ≮ 0 so we select upper pixel (5, 4).
▪ 𝑝3 = 𝑝2 + 2∆𝑦 − 2∆𝑥 = 0 + −4 = −4
▪ Now 𝑝3 < 0 so we select lower pixel (6, 4).
Parallel Execution of Line
Algorithms
▪ The line-generating algorithms we have discussed so far
determine pixel positions sequentially.
▪ With multiple processors we can calculate pixel position
along a line path simultaneously.
▪ One way to use multiple processors is partitioning
existing sequential algorithm into small parts and
compute separately.
▪ Alternatively we can setup the processing so that pixel
positions can be calculated efficiently in parallel.
▪ Balance the load among the available processors is also
important in parallel processing.
Parallel Bresenham Line
Algorithms
▪ For 𝑛𝑝 number of processors we can set up parallel
Bresenham line algorithm by subdividing the line path
into 𝑛𝑝 partitions and simultaneously generating line
segment in each of the subintervals.
▪ For a line with slope 0 < 𝑚 < 1 and left endpoint
coordinate position (𝑥0 , 𝑦0 ), we partition the line along
the positive 𝑥 direction.
▪ The distance between beginning 𝑥 positions of adjacent
partitions can be calculated as:
∆𝑥𝑝 = (∆𝑥 + 𝑛𝑝 − 1)/𝑛𝑝
▪ Where ∆𝑥 is the width of the line and value for partition
with ∆𝑥𝑝 is computed using integer division.
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 + 𝑟𝑜𝑢𝑛𝑑(𝑘∆𝑦𝑝)
IDP for Parallel Bresenham Line
Algorithms
▪ The initial decision parameter(IDP) for Bresenham's
algorithm at the start of the 𝐾 𝑡ℎ subinterval is obtained
as follow:
▪ 𝑝𝑘 = 2∆𝑦𝑥𝑘 − 2∆𝑥𝑦𝑘 + 2∆𝑦 + 2𝑏∆𝑥 − ∆𝑥
▪ 𝑝𝑘 = 2∆𝑦(𝑥0 + 𝑘∆𝑥𝑝 ) − 2∆𝑥 𝑦0 + 𝑟𝑜𝑢𝑛𝑑 𝑘∆𝑦𝑝 + 2∆𝑦 +
∆𝑦
2∆𝑥(𝑦0 − 𝑥0 ) − ∆𝑥
∆𝑥
▪ 𝑝𝑘 = 2∆𝑦𝑥0 + 2∆𝑦𝑘∆𝑥𝑝 − 2∆𝑥𝑦0 − 2∆𝑥𝑟𝑜𝑢𝑛𝑑 𝑘∆𝑦𝑝 + 2∆𝑦 +
2∆𝑥𝑦0 − 2∆𝑦𝑥0 − ∆𝑥
▪ 𝑝𝑘 = 2∆𝑦𝑘∆𝑥𝑝 − 2∆𝑥𝑟𝑜𝑢𝑛𝑑 𝑘∆𝑦𝑝 + 2∆𝑦 − ∆𝑥
▪ Each processor then calculates pixel positions over its
assigned subinterval.
Other Ways for Parallel Execution of Line
Algorithms
▪ For line with slope greater than 1 we partitioning the
line in the 𝑦 direction and calculating beginning 𝑥
values for the positions.
▪ For negative slopes, we increment coordinate values in
one direction and decrement in the other.
▪ Another way to set up parallel algorithms on raster
system is to assign each processor to a particular group
of screen pixels.
▪ With sufficient number of processor we can assign each
processor to one pixel within some screen region.
▪ This can be done by assigning one processor to each of
the pixels within the limit of the bounding rectangle.
Contd.
▪ Perpendicular distance d from line to a particular pixel is
calculated by:
▪ 𝑑 = 𝐴𝑥 + 𝐵𝑦 + 𝐶
Where
▪ 𝐴 = −∆𝑦/𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ
▪ 𝐵 = −∆𝑥/𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ
▪ 𝐶 = (𝑥0 ∆𝑦 − 𝑦0 ∆𝑥)/𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ
With
▪ 𝑙𝑖𝑛𝑒𝑙𝑒𝑛𝑔𝑡ℎ = ∆𝑥 2 + ∆𝑦 2
▪ 𝐴, 𝐵, and 𝐶 are constant we need to compute only once.
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.
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.
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
Properties of Circle- Cartesion
Coordinate
▪ Cartesian coordinates equation :
▪ (𝑥 − 𝑥𝑐 )2 +(𝑦 − 𝑦𝑐 )2 = 𝑟 2
▪ We could use this equation to calculate circular boundary points.
▪ We increment 1 in 𝑥 direction in every steps from 𝑥𝑐 − 𝑟 to 𝑥𝑐 +
𝑟 and calculate corresponding 𝑦 values at each position as:
▪ (𝑥 − 𝑥𝑐 )2 +(𝑦 − 𝑦𝑐 )2 = 𝑟 2
▪ (𝑦 − 𝑦𝑐 )2 = 𝑟 2 − (𝑥 − 𝑥𝑐 )2
▪ 𝑦 − 𝑦𝑐 = ± 𝑟 2 − (𝑥𝑐 − 𝑥)2
▪ y = 𝑦𝑐 ± 𝑟 2 − (𝑥𝑐 − 𝑥)2
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.

▪ We can adjust spacing by stepping through y values and


calculating x values whenever the absolute value of the slop of the
circle is greater than 1.
▪ But it will increases computation time.
Properties of Circle- Polar
Coordinate
▪ Another way to eliminate the non-uniform spacing is to draw circle
using polar coordinates ‘r’ and ‘’.
▪ Calculating circle boundary using polar equation is given by pair of
equations which is as follows.
𝑥 = 𝑥𝑐 + 𝑟 cos 
𝑦 = 𝑦𝑐 + 𝑟 sin 
▪ When display is produce using these equations using fixed angular
step size circle is plotted with uniform spacing.
▪ The step size ‘’ is chosen according to application and display
device.
▪ For a more continuous boundary on a raster display we can set the
1
step size at .
𝑟
Properties of Circle- Symmetry
▪ Computation can be reduced by considering symmetry city
property of circles.
▪ The shape of circle is similar in each octant.

(-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)

(-Y, -X) (Y, -X)


(-3, -4) (3, -4)
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.
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.
Introduction to Midpoint Circle
Algorithm
▪ In this we sample at unit interval and determine the closest pixel
position to the specified circle path at each step.
▪ Given radius 𝑟 and center (𝑥𝑐 , 𝑦𝑐 )
▪ We first setup our algorithm to calculate circular path coordinates
for center (0, 0).
▪ And then we will transfer calculated pixel position to center
(𝑥𝑐 , 𝑦𝑐 ) by adding 𝑥𝑐 to 𝑥 and 𝑦𝑐 to 𝑦.
▪ Along the circle section from 𝑥 = 0 to 𝑥 = 𝑦 in the first quadrant,
the slope of the curve varies from 0 to −1.
▪ So we can step unit step in positive 𝑥 direction over this octant
and use a decision parameter to determine which of the two
possible 𝑦 position is closer to the circular path.
Decision Parameter Midpoint Circle
Algorithm
▪ Position in the other seven octants are then obtain by symmetry.
▪ For the decision parameter we use the circle function which is:
𝑓𝑐𝑖𝑟𝑐𝑙𝑒 𝑥, 𝑦 = 𝑥 2 + 𝑦 2 − 𝑟 2

< 0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦


𝑓𝑐𝑖𝑟𝑐𝑙𝑒 𝑥, 𝑦 ൞ = 0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑜𝑛 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
> 0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑜𝑢𝑡𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
▪ Above equation we calculate for the mid positions between pixels
near the circular path at each sampling step.
▪ And we setup incremental calculation for this function as we did in
the line algorithm.
Midpoint between Candidate
pixel
▪ Figure shows the midpoint between the two candidate pixels at
sampling position 𝑥𝑘 + 1.
𝒙𝟐 + 𝒚𝟐 − 𝒓𝟐 = 𝟎

yk Midpoint
Candidate
yk+1 Pixel

xk xk+1 xk+2

▪ Assuming we have just plotted the pixel at 𝑥𝑘 , 𝑦𝑘 .


▪ Next we determine whether the pixel at position 𝑥𝑘 + 1, 𝑦𝑘 or
the one at position 𝑥𝑘 + 1, 𝑦𝑘 − 1 is closer to circle boundary.
Derivation Midpoint Circle
Algorithm
▪ So for finding which pixel is more closer using decision parameter
evaluated at the midpoint between two candidate pixels as below:
▪ 𝑝𝑘 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 𝑥𝑘 + 1, 𝑦𝑘 − 12
2 2
▪ 𝑝𝑘 = 𝑥𝑘 + 1 + 𝑦𝑘 − 1
2
− 𝑟2
▪ 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.
Contd.
▪ Successive decision parameters are obtain using incremental
calculations as follows:
▪ 𝑝𝑘+1 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 𝑥𝑘+1 + 1, 𝑦𝑘+1 − 12
2 2
▪ 𝑝𝑘+1 = 𝑥𝑘 + 1 + 1 + 𝑦𝑘+1 − 1
2
− 𝑟2
▪ Now we can obtain recursive calculation using equation of 𝑝𝑘+1 and 𝑝𝑘
as follow

2 2
▪ 𝑝𝑘+1 − 𝑝𝑘 = 𝑥𝑘 + 1 + 1 + 𝑦𝑘+1 − 1
2
− 𝑟 2 − ൬ 𝑥𝑘 + 1 2
+
2
𝑦𝑘 − 1
2
− 𝑟2൰
2
▪ 𝑝𝑘+1 − 𝑝𝑘 = 𝑥𝑘 + 1 + 2 𝑥𝑘 + 1 + 1 + 𝑦𝑘+1 2 − 𝑦𝑘+1 + 14 − 𝑟 2 −
2
𝑥𝑘 + 1 − 𝑦𝑘 2 + 𝑦𝑘 − 14 + 𝑟 2
Contd.
2
▪ 𝑝𝑘+1 − 𝑝𝑘 = 𝑥𝑘 + 1 + 2 𝑥𝑘 + 1 + 1 + 𝑦𝑘+1 2 − 𝑦𝑘+1 + 14 −
𝑟 2 − 𝑥𝑘 + 1 2
− 𝑦𝑘 2 + 𝑦𝑘 − 14 + 𝑟 2
▪ 𝑝𝑘+1 − 𝑝𝑘 = 2 𝑥𝑘 + 1 + 1 + 𝑦𝑘+1 2 − 𝑦𝑘+1 − 𝑦𝑘 2 + 𝑦𝑘
▪ 𝑝𝑘+1 − 𝑝𝑘 = 2 𝑥𝑘 + 1 + (𝑦𝑘+1 2 − 𝑦𝑘 2 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2 𝑥𝑘 + 1 + (𝑦𝑘+1 2 − 𝑦𝑘 2 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
▪ Now we can put 2𝑥𝑘+1 = 2(𝑥𝑘 + 1)
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (𝑦𝑘+1 2 − 𝑦𝑘 2 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
Contd.
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (𝑦𝑘+1 2 − 𝑦𝑘 2 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
▪ In above equation 𝑦𝑘+1 is either 𝑦𝑘 or 𝑦𝑘 − 1 depending on the
sign of the 𝑝𝑘 .
▪ If we select 𝑦𝑘+1 = 𝑦𝑘 .
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1
▪ If we select 𝑦𝑘+1 = 𝑦𝑘 – 1.
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (𝑦𝑘+1 2 − 𝑦𝑘 2 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (𝑦𝑘+1 +𝑦𝑘 )(𝑦𝑘+1 −𝑦𝑘 ) − (𝑦𝑘+1 −𝑦𝑘 ) + 1
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (𝑦𝑘 – 1 + 𝑦𝑘 )(𝑦𝑘 – 1 − 𝑦𝑘 ) − (𝑦𝑘 – 1 −
𝑦𝑘 ) + 1
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + (2𝑦𝑘 – 1)(– 1) − (– 1) + 1
Contd.
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 − 2𝑦𝑘 + 1 + 1 + 1
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 − (2𝑦𝑘 − 2) + 1
▪ Now put 2𝑦𝑘+1 = 2𝑦𝑘 − 2.
▪ 𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 − 2𝑦𝑘+1 + 1
IDP Midpoint Circle Algorithm
▪ The initial decision parameter(IDP) is obtained by evaluating the
circle function at the start position 𝑥0 , 𝑦0 = (0, 𝑟) as follows.
▪ 𝑝0 = 𝑓𝑐𝑖𝑟𝑐𝑙𝑒 0 + 1, 𝑟 − 12
2 2
▪ 𝑝0 = 1 + 𝑟 − 1
2
− 𝑟2
▪ 𝑝0 = 1 + 𝑟 2 − 𝑟 + 14 − 𝑟 2
▪ 𝑝0 = 54 − 𝑟
▪ 𝑝0 ≈ 1 − 𝑟
Algorithm for Midpoint Circle Generation
1. Input radius r and circle center (𝑥𝑐 , 𝑦𝑐 ), and obtain the first point on the
circumference of a circle centered on the origin as
𝑥0 , 𝑦0 = (0, 𝑟)
2. calculate the initial value of the decision parameter as
𝑝0 = 54 − 𝑟
3. At each 𝑥𝑘 position, starting at 𝑘 = 0, perform the following test:
If 𝑝𝑘 < 0, the next point along the circle centered on (0, 0) is 𝑥𝑘 + 1, 𝑦𝑘 &
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1
Otherwise, the next point along the circle is 𝑥𝑘 + 1, 𝑦𝑘 − 1 &
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1 − 2𝑦𝑘+1
Where 2𝑥𝑘+1 = 2𝑥𝑘 + 2, & 2𝑦𝑘+1 = 2𝑦𝑘 − 2.
4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position (𝑥, 𝑦) onto the circular path centered on
(𝑥𝑐 , 𝑦𝑐 ) and plot the coordinate values:
𝑥 = 𝑥 + 𝑥𝑐 , 𝑦 = 𝑦 + 𝑦𝑐
6. Repeat steps 3 through 5 until 𝑥 ≥ 𝑦.
Example Midpoint Circle
Algorithm
▪ Example: Draw circle with radius 𝑟 = 10, and center of circle is
1, 1 (Only one octant 𝑥 = 0 to 𝑥 = 𝑦 )
▪ First we find pixel position for octant 𝑥 = 0 to 𝑥 = 𝑦 for center
0, 0
𝒌 𝒑𝒌 (𝒙𝒌+𝟏 , 𝒚𝒌+𝟏)
▪ 𝑝0 = 1 − 𝑟 0 -9 (1, 10)
▪ 𝑝0 = 1 − 10 = −9 1 -6 (2, 10)
2 -1 (3, 10)
▪ Now 𝑝0 < 0 we select (1, 10)
3 6 (4, 9)
▪ 𝑝1 = 𝑝0 + 2𝑥1 + 1 4 -3 (5, 9)
▪ 𝑝1 = −9 + 2 + 1 = −6 5 8 (6, 8)

▪ Now 𝑝1 < 0 we select (2, 10) 6 5 (7, 7)


Contd.
▪ 𝑝2 = 𝑝1 + 2𝑥2 + 1 𝒌 𝒑𝒌 (𝒙𝒌+𝟏 , 𝒚𝒌+𝟏)
0 -9 (1, 10)
▪ 𝑝2 = −6 + 4 + 1 = −1
1 -6 (2, 10)
▪ Now 𝑝2 < 0 we select (3, 10) 2 -1 (3, 10)
▪ 𝑝3 = 𝑝2 + 2𝑥3 + 1 3 6 (4, 9)

▪ 𝑝3 = −1 + 6 + 1 = 6 4 -3 (5, 9)
5 8 (6, 8)
▪ Now 𝑝3 ≮ 0 we select (4, 9)
6 5 (7, 7)
▪ 𝑝4 = 𝑝3 + 2𝑥4 + 1 − 2𝑦4
▪ 𝑝4 = 6 + 8 + 1 − 18 = −3
▪ Now 𝑝4 < 0 we select (5, 9)
Contd.
▪ 𝑝5 = 𝑝4 + 2𝑥5 + 1 𝒌 𝒑𝒌 (𝒙𝒌+𝟏 , 𝒚𝒌+𝟏)
0 -9 (1, 10)
▪ 𝑝5 = −3 + 10 + 1 = 8
1 -6 (2, 10)
▪ Now 𝑝5 ≮ 0 we select (6, 8) 2 -1 (3, 10)
▪ 𝑝6 = 𝑝5 + 2𝑥6 + 1 − 2𝑦6 3 6 (4, 9)

▪ 𝑝6 = 8 + 12 + 1 − 16 = 5 4 -3 (5, 9)
5 8 (6, 8)
▪ Now 𝑝6 ≮ 0 we select (7, 7)
6 5 (7, 7)
▪ Now Loop exit as 𝑥 ≥ 𝑦, as
▪ in our case 7 ≥ 7
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)
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
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
Contd.
▪ If we labeled distance from two foci to any point on ellipse
boundary as 𝑑1 and 𝑑2 then the general equation of an ellipse can
be written as:
𝑑1 + 𝑑2 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
▪ Expressing distance in terms of focal coordinates 𝑓1 = 𝑥1 , 𝑦1 and
𝑓2 = 𝑥2 , 𝑦2 we have
▪ 𝑥 − 𝑥1 2 + 𝑦 − 𝑦1 2 + 𝑥 − 𝑥2 2 + 𝑦 − 𝑦2 2 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
[Using Distance formula]
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:
𝑥 − 𝑥1 2 + 𝑦 − 𝑦1 2 + 𝑥 − 𝑥2 2 + 𝑦 − 𝑦2 2 = 𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡
▪ We can also write this equation in the form
𝐴𝑥 2 + 𝐵𝑦 2 + 𝐶𝑥𝑦 + 𝐷𝑥 + 𝐸𝑦 + 𝐹 = 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.
Contd.
▪ Then coefficient in 𝐴𝑥 2 + 𝐵𝑦 2 + 𝐶𝑥𝑦 + 𝐷𝑥 + 𝐸𝑦 + 𝐹 = 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
Contd.
▪ Equation of ellipse can be written in terms of the ellipse center
coordinates (𝑥𝑐 , 𝑦𝑐 ) and parameters 𝑟𝑥 and 𝑟𝑦 as.
2 2
𝑥 − 𝑥𝑐 𝑦 − 𝑦𝑐
+ =1
𝑟𝑥 𝑟𝑦
▪ Using the polar coordinates r and θ, we can also describe the
ellipse in standard position with the parametric equations:
𝑥 = 𝑥𝑐 + 𝑟𝑥 cos θ
𝑦 = 𝑦𝑐 + 𝑟𝑦 sin θ

𝑟𝑦
𝑟𝑥

(𝑥𝑐 , 𝑦𝑐 )
Properties of Ellipse-Symmetry
▪ Symmetry property further reduced computations.
▪ An ellipse in standard position is symmetric between quadrant.

(−2, 4) (2, 4)
(−𝑥, 𝑦) (𝑥, 𝑦)
𝑟𝑦
𝑟𝑥
(𝑥𝑐 , 𝑦𝑐 )

(−𝑥, −𝑦) (𝑥, −𝑦)


(−2, −4) (2, −4)
Introduction to Midpoint Ellipse
Algorithm
▪ Given parameters 𝑟𝑥 , 𝑟𝑦 , & (𝑥𝑐 , 𝑦𝑐 ).
▪ We determine points (𝑥, 𝑦) for an ellipse in standard position
centered on the origin.
▪ Then we shift the points so the ellipse is centered at (𝑥𝑐 , 𝑦𝑐 ).
▪ If we want to display the ellipse in nonstandard position then we
rotate the ellipse about its center to align with required direction.
▪ For the present we consider only the standard position.
▪ We draw ellipse in first quadrant and than use symmetry property
for other three quadrant.
Regions in Midpoint Ellipse
Algorithm
▪ In this method we divide first quadrant into two parts according to
the slope of an ellipse
▪ Boundary divides region at Region 1
• slope = -1. 𝑦
▪ We take unit step in X direction 𝑆𝑙𝑜𝑝𝑒 = −1
• If magnitude of ellipse slope < 1 (Region 1). 𝑟𝑦
Region 2
▪ We take unit step in Y direction
𝑟𝑥 𝑥
• If magnitude of ellipse slope > 1 (Region 2).
Ways of Processing Midpoint Ellipse
Algorithm
▪ We can start from (0, 𝑟𝑦 ) and step clockwise along the elliptical
path in the first quadrant
▪ Alternatively, we could start at (𝑟𝑥 , 0 ) and select points in a
counterclockwise order.
▪ With parallel processors, we could calculate pixel positions in the
two regions simultaneously.
▪ Here we consider sequential implementation of midpoint
algorithm.
▪ We take the start position at (0, 𝑟𝑦 ) and steps along the elliptical
path in clockwise order through the first quadrant.
Decision Parameter Midpoint Ellipse
Algorithm
▪ We define ellipse function for center of ellipse at (0, 0) as follows.
▪ 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥, 𝑦 = 𝑟𝑦 2 𝑥 2 + 𝑟𝑥 2 𝑦 2 − 𝑟𝑦 2 𝑟𝑥 2
▪ Which has the following properties:

<0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦


𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥, 𝑦 ൞ = 0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑜𝑛 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
> 0 𝑖𝑓 𝑥, 𝑦 𝑖𝑠 𝑜𝑢𝑡𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
▪ Thus the ellipse function serves as the decision parameter in the
midpoint ellipse algorithm.
▪ At each sampling position we select the next pixel from two
candidate pixel.
Processing Steps of Midpoint Ellipse
Algorithm
▪ Starting at (0, 𝑟𝑦 ) we take unit step in 𝑥 direction until we reach
the boundary between region-1 and region-2.
▪ Then we switch to unit steps in 𝑦 direction in remaining portion on
ellipse in first quadrant.
Region 1
▪ At each step we need to test the value 𝑦
of the slope of the curve for deciding 𝑆𝑙𝑜𝑝𝑒 = −1
the end point of the region-1. 𝑟𝑦
Region 2
𝑟𝑥 𝑥
Decide Boundary between Region
1 and 2
▪ The ellipse slope is calculated using following equation.
𝑑𝑦 2𝑟𝑦 2 𝑥
▪ =−
𝑑𝑥 2𝑟𝑥 2 𝑦
▪ At boundary between region 1 and 2 slope= -1 and equation
become.
▪ 2𝑟𝑦 2 𝑥 = 2𝑟𝑥 2 𝑦
▪ Therefore we move out of region 1 whenever following equation
is false:
▪ 2𝑟𝑦 2 𝑥 ≤ 2𝑟𝑥 2 𝑦
Midpoint between Candidate pixel in
Region 1
▪ Figure shows the midpoint between the two candidate pixels at
sampling position 𝑥𝑘 + 1 in the first region.

ry2x2+rx2y2-rx2ry2=0

yk Midpoint
yk-1 Candidate
Pixel
xk xk+1 xk+2

▪ Assume we are at (𝑥𝑘 , 𝑦𝑘 ) position and we determine the next position


along the ellipse path, by evaluating decision parameter at midpoint
between two candidate pixels.
1
▪ 𝑝1𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘 + 1, 𝑦𝑘 −
2
Derivation for Region 1
1
▪ 𝑝1𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘 + 1, 𝑦𝑘 −
2

2 2 2 1 2
▪ 𝑝1𝑘 = 𝑟𝑦 (𝑥𝑘 + 1) +𝑟𝑥 𝑦𝑘 − − 𝑟𝑥 2 𝑟𝑦 2
2
▪ 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.
Contd.
▪ At the next sampling position decision parameter for region 1 is
evaluated as.
1
▪ 𝑝1𝑘+1 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘+1 + 1, 𝑦𝑘+1 −
2

2 2 2 1 2
▪ 𝑝1𝑘+1 = 𝑟𝑦 𝑥𝑘 + 1 + 1 + 𝑟𝑥 𝑦𝑘+1 − − 𝑟𝑥 2 𝑟𝑦 2
2
▪ Now subtract 𝑝1𝑘 from 𝑝1𝑘+1

2 2 2 1 2
▪ 𝑝1𝑘+1 − 𝑝1𝑘 = 𝑟𝑦 𝑥𝑘 + 1 + 1 + 𝑟𝑥 𝑦𝑘+1 − − 𝑟𝑥 2 𝑟𝑦 2 −
2

2 2 2 1 2
𝑟𝑦 (𝑥𝑘 + 1) −𝑟𝑥 𝑦𝑘 − + 𝑟𝑥 2 𝑟𝑦 2
2
Contd.
2 2 2 1 2
▪ 𝑝1𝑘+1 − 𝑝1𝑘 = 𝑟𝑦 𝑥𝑘 + 1 + 1 + 𝑟𝑥 𝑦𝑘+1 − −
2

2 2 2 1 2
𝑟𝑦 (𝑥𝑘 + 1) −𝑟𝑥 𝑦𝑘 −
2

▪ 𝑝1𝑘+1 − 𝑝1𝑘 = 𝑟𝑦 2 𝑥𝑘 + 1 2
+ 2𝑟𝑦 2 𝑥𝑘 + 1 + 𝑟𝑦 2 + 𝑟𝑥 2 ቀ𝑦𝑘+1 −
1 2 2 2 2 1 2
ቁ − 𝑟𝑦 (𝑥𝑘 + 1) −𝑟𝑥 𝑦𝑘 −
2 2

2 2 2 1 2 1 2
▪ 𝑝1𝑘+1 − 𝑝1𝑘 = 2𝑟𝑦 𝑥𝑘 + 1 + 𝑟𝑦 + 𝑟𝑥 𝑦𝑘+1 − − 𝑦𝑘 −
2 2

▪ Now making 𝑝1𝑘+1 as subject.

2 2 2 1 2 1 2
▪ 𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 𝑥𝑘 + 1 + 𝑟𝑦 + 𝑟𝑥 𝑦𝑘+1 − − 𝑦𝑘 −
2 2
Contd.
2 2 2 1 2
▪ 𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 𝑥𝑘 + 1 + 𝑟𝑦 + 𝑟𝑥 ൤ 𝑦𝑘+1 − −
2
1 2
𝑦𝑘 − ൨
2

▪ 𝑦𝑘+1 is either 𝑦𝑘 or 𝑦𝑘 − 1, depends on the sign of 𝑝1𝑘


IDP for Region 1
▪ Now we calculate the initial decision parameter 𝑝10 by putting
𝑥0 , 𝑦0 = (0, 𝑟𝑦 ) as follow.
1
▪ 𝑝10 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 0 + 1, 𝑟𝑦 −
2

2 2 2 1 2
▪ 𝑝10 = 𝑟𝑦 (1) +𝑟𝑥 𝑟𝑦 − − 𝑟𝑥 2 𝑟𝑦 2
2

2 2 1 2
▪ 𝑝10 = 𝑟𝑦 + 𝑟𝑥 𝑟𝑦 − − 𝑟𝑥 2 𝑟𝑦 2
2
1
▪ 𝑝10 = 𝑟𝑦 − 𝑟𝑥 𝑟𝑦 + 𝑟𝑥 2
2 2
4
Midpoint between Candidate pixel in
Region 2
▪ Now we similarly calculate over region-2.
▪ Unit stepping in negative 𝑦 direction and the midpoint is now
taken between horizontal pixels at each step.
ry2x2+rx2y2-rx2ry2=0

yk Midpoint
yk-1 Candidate
Pixel
xk xk+1 xk+2
▪ For this region, the decision parameter is evaluated as follows.
1
▪ 𝑝2𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘 + , 𝑦𝑘 − 1
2
Derivation for Region 2
1
▪ 𝑝2𝑘 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘 + , 𝑦𝑘 − 1
2

2 1 2
▪ 𝑝2𝑘 = 𝑟𝑦 𝑥𝑘 + + 𝑟𝑥 2 𝑦𝑘 − 1 2
− 𝑟𝑥 2 𝑟𝑦 2
2
▪ 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.
Contd.
▪ At the next sampling position decision parameter for region 2 is
evaluated as.
1
▪ 𝑝2𝑘+1 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥𝑘+1 + , 𝑦𝑘+1 − 1
2

2 1 2
▪ 𝑝2𝑘+1 = 𝑟𝑦 𝑥𝑘+1 + + 𝑟𝑥 2 𝑦𝑘 − 1 − 1 2
− 𝑟𝑥 2 𝑟𝑦 2
2
▪ Now subtract 𝑝2𝑘 from 𝑝2𝑘+1

2 1 2
▪ 𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦 𝑥𝑘+1 + + 𝑟𝑥 2 𝑦𝑘 − 1 − 1 2
− 𝑟𝑥 2 𝑟𝑦 2 −
2

2 1 2
𝑟𝑦 𝑥𝑘 + − 𝑟𝑥 2 𝑦𝑘 − 1 2
+ 𝑟𝑥 2 𝑟𝑦 2
2
Contd.
2 1 2
▪ 𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦 𝑥𝑘+1 + + 𝑟𝑥 2 𝑦𝑘 − 1 − 1 2
− 𝑟𝑥 2 𝑟𝑦 2 −
2

2 1 2
𝑟𝑦 𝑥𝑘 + − 𝑟𝑥 2 𝑦𝑘 − 1 2
+ 𝑟𝑥 2 𝑟𝑦 2
2

2 1 2
▪ 𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦 𝑥𝑘+1 + + 𝑟𝑥 2 𝑦𝑘 − 1 2
− 2𝑟𝑥 2 𝑦𝑘 − 1 +
2

2 2 1 2
𝑟𝑥 − 𝑟𝑦 𝑥𝑘 + − 𝑟𝑥 2 𝑦𝑘 − 1 2
2

2 1 2 2 2 2 1 2
▪ 𝑝2𝑘+1 − 𝑝2𝑘 = 𝑟𝑦 𝑥𝑘+1 + − 2𝑟𝑥 𝑦𝑘 − 1 + 𝑟𝑥 − 𝑟𝑦 𝑥𝑘 +
2 2

2 2 2 1 2 1 2
▪ 𝑝2𝑘+1 − 𝑝2𝑘 = −2𝑟𝑥 𝑦𝑘 − 1 + 𝑟𝑥 + 𝑟𝑦 𝑥𝑘+1 + − 𝑥𝑘 +
2 2
Contd.
2 2 2 1 2
▪ 𝑝2𝑘+1 − 𝑝2𝑘 = −2𝑟𝑥 𝑦𝑘 − 1 + 𝑟𝑥 + 𝑟𝑦 ൤ 𝑥𝑘+1 + −
2
1 2
𝑥𝑘 + ൨
2

▪ Now making 𝑝2𝑘+1 as subject.

2 2 2 1 2
▪ 𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 𝑦𝑘 − 1 + 𝑟𝑥 + 𝑟𝑦 ൤ 𝑥𝑘+1 + −
2
1 2
𝑥𝑘 + ൨
2

▪ Here 𝑥𝑘+1 is either 𝑥𝑘 or 𝑥𝑘 + 1, depends on the sign of 𝑝2𝑘 .


IDP for Region 2
▪ In region-2 initial position is selected which is last position of
region one and the initial decision parameter is calculated as
follows.
1
▪ 𝑝20 = 𝑓𝑒𝑙𝑙𝑖𝑝𝑠𝑒 𝑥0 + , 𝑦0 − 1
2

1 2
▪ 𝑝20 = 𝑟𝑦 2 𝑥0 + + 𝑟𝑥 2 𝑦0 − 1 2
− 𝑟𝑥 2 𝑟𝑦 2
2
▪ For simplify calculation of 𝑝20 we could also select pixel position
in counterclockwise order starting at (𝑟𝑥 , 0).
Algorithm for Midpoint Ellipse Generation
1. Input 𝑟𝑥 , 𝑟𝑦 and ellipse center (𝑥𝑐 , 𝑦𝑐 ), and obtain the first point on an ellipse
centered on the origin as
𝑥0 , 𝑦0 = (0, 𝑟𝑦 )

2. Calculate the initial value of the decision parameter in region 1 as


1
𝑝10 = 𝑟𝑦 2 − 𝑟𝑥 2 𝑟𝑦 + 4 𝑟𝑥 2

3. At each 𝑥𝑘 position in region 1, starting at 𝑘 = 0, perform the following test:


If 𝑝1𝑘 < 0, than the next point along the ellipse is (𝑥𝑘+1 , 𝑦𝑘 ) and
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘+1 + 𝑟𝑦 2

Otherwise, the next point along the ellipse is (𝑥𝑘+1 , 𝑦𝑘 − 1) and


𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘+1 + 𝑟𝑦 2 − 2𝑟𝑥 2 𝑦𝑘+1
With
2𝑟𝑦 2 𝑥𝑘+1 = 2𝑟𝑦 2 𝑥𝑘 + 2𝑟𝑦 2 , 2𝑟𝑥 2 𝑦𝑘+1 = 2𝑟𝑥 2 𝑦𝑘 − 2𝑟𝑥 2
And continue until 2𝑟𝑦 2 𝑥 ≤ 2𝑟𝑥 2 𝑦
Contd.
4. Calculate the initial value of the decision parameter in region 2 using the last
point 𝑥0 , 𝑦0 calculated in region 1 as
2 1 2
𝑝20 = 𝑟𝑦 𝑥0 + 2 + 𝑟𝑥 2 𝑦0 − 1 2 − 𝑟𝑥 2 𝑟𝑦 2

5. At each 𝑦𝑘 position in region-2, starting at 𝑘 = 0, perform the following test:


If 𝑝2𝑘 > 0, the next point along the ellipse is (𝑥𝑘 , 𝑦𝑘 − 1) and
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 𝑦𝑘+1 + 𝑟𝑥 2

Otherwise, the next point along the ellipse is (𝑥𝑘 + 1, 𝑦𝑘 − 1) and


𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 𝑦𝑘+1 + 𝑟𝑥 2 + 2𝑟𝑦 2 𝑥𝑘+1
Using the same incremental calculations for 𝑥 and 𝑦 as in region 1.

6. Determine symmetry points in the other three quadrants.

7. Move each calculated pixel position (𝑥, 𝑦) onto the elliptical path centered on
(𝑥𝑐 , 𝑦𝑐 ) and plot the coordinate values:
𝑥 = 𝑥 + 𝑥𝑐 , 𝑦 = 𝑦 + 𝑦𝑐

8. Repeat the steps for region 2 until 𝑦𝑘 ≥ 0.


Example Midpoint Ellipse
Algorithm
▪ Example: Calculate intermediate pixel position (For first quadrant)
for ellipse with 𝑟𝑥 = 8, 𝑟𝑦 = 6 and ellipse center is at origin
▪ Initial point 0, 𝑟𝑦 = (0, 6)
1
▪ 𝑝10 = 𝑟𝑦 − 𝑟𝑥 𝑟𝑦 + 𝑟𝑥 2
2 2
4
1
▪ 𝑝10 = 62 − 82 ∗ 6 + 82
4
▪ 𝑝10 = −332
Contd.
▪ 𝑝10 = −332 K p1k (xk+1, yk+1)
0 -332 (1, 6)
▪ 𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘 + 1 + 𝑟𝑦 2 + 1 -224 (2, 6)
2 1 2 1 2 2 -44 (3, 6)
𝑟𝑥 𝑦𝑘+1 − − 𝑦𝑘 −
2 2
3 208 (4, 5)
▪ 𝑝11 = −332 + 2 ∗ 62 0 + 1 + 62 +
4 -108 (5, 5)
1 2 1 2
5 288 (6, 4)
82 6− − 6− = −224
2 2 6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.
▪ 𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘 + 1 + 𝑟𝑦 2 + K p1k (xk+1, yk+1)
2 1 2 1 2 0 -332 (1, 6)
𝑟𝑥 𝑦𝑘+1 − − 𝑦𝑘 −
2 2
1 -224 (2, 6)
2 -44 (3, 6)
▪ 𝑝12 = −224 + 2 ∗ 62 1 + 1 + 62 +
1 2 1 2
3 208 (4, 5)
2
8 6− − 6− = −44
2 2 4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.
▪ 𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘 + 1 + 𝑟𝑦 2 + K p1k (xk+1, yk+1)
2 1 2 1 2 0 -332 (1, 6)
𝑟𝑥 𝑦𝑘+1 − − 𝑦𝑘 −
2 2
1 -224 (2, 6)
2 -44 (3, 6)
▪ 𝑝13 = −44 + 2 ∗ 62 2 + 1 + 62 +
1 2 1 2
3 208 (4, 5)
2
8 6− − 6− = 208
2 2 4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.
▪ 𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘 + 1 + 𝑟𝑦 2 + K p1k (xk+1, yk+1)
2 1 2 1 2 0 -332 (1, 6)
𝑟𝑥 𝑦𝑘+1 − − 𝑦𝑘 −
2 2
1 -224 (2, 6)
2 -44 (3, 6)
▪ 𝑝14 = 208 + 2 ∗ 62 3 + 1 + 62 +
1 2 1 2
3 208 (4, 5)
2
8 5− − 6− = −108
2 2 4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.
▪ 𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘 + 1 + 𝑟𝑦 2 + K p1k (xk+1, yk+1)
2 1 2 1 2 0 -332 (1, 6)
𝑟𝑥 𝑦𝑘+1 − − 𝑦𝑘 −
2 2
1 -224 (2, 6)
2 -44 (3, 6)
▪ 𝑝15 = −108 + 2 ∗ 62 4 + 1 + 62 +
1 2 1 2
3 208 (4, 5)
2
8 5− − 5− = 288
2 2 4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.
▪ 𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘 + 1 + 𝑟𝑦 2 + K p1k (xk+1, yk+1)
2 1 2 1 2 0 -332 (1, 6)
𝑟𝑥 𝑦𝑘+1 − − 𝑦𝑘 −
2 2
1 -224 (2, 6)
2 -44 (3, 6)
▪ 𝑝16 = 288 + 2 ∗ 62 5 + 1 + 62 +
1 2 1 2
3 208 (4, 5)
2
8 4− − 5− = 244
2 2 4 -108 (5, 5)
5 288 (6, 4)
6 244 (7, 3)

Calculation stop when 𝐼𝑓 𝑝1𝑘 < 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘


2𝑟𝑦 2 𝑥 > 2𝑟𝑥 2 𝑦 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑦𝑘+1 = 𝑦𝑘 − 1
Contd.
2 1 2 K p2k (xk+1, yk+1)
▪ 𝑝20 = 𝑟𝑦 𝑥0 + + 𝑟𝑥 2 𝑦0 − 1 2

2
0 -23 (8, 2)
𝑟𝑥 2 𝑟𝑦 2
1 361 (8, 1)
2 297 (8, 0)
2 1 2
▪ 𝑝20 = 6 7+ + 82 3 − 1 2

2
82 62 = −23

Calculation stop when 𝐼𝑓 𝑝2𝑘 > 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘


𝑦𝑘 ≤ 0 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘 + 1
Contd.
▪ 𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 𝑦𝑘 − 1 + 𝑟𝑥 2 + K p2k (xk+1, yk+1)
2 1 2 1 2 0 -23 (8, 2)
𝑟𝑦 𝑥𝑘+1 + − 𝑥𝑘 +
2 2
1 361 (8, 1)
▪ 𝑝21 = −23 − 2 ∗ 82 3 − 1 + 82 +
2 297 (8, 0)

2 1 2 1 2
6 8+ − 7+ = 361
2 2

Calculation stop when 𝐼𝑓 𝑝2𝑘 > 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘


𝑦𝑘 ≤ 0 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘 + 1
Contd.
▪ 𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 𝑦𝑘 − 1 + 𝑟𝑥 2 + K p2k (xk+1, yk+1)
2 1 2 1 2 0 -23 (8, 2)
𝑟𝑦 𝑥𝑘+1 + − 𝑥𝑘 +
2 2
1 361 (8, 1)
▪ 𝑝22 = 361 − 2 ∗ 82 2 − 1 + 82 +
2 297 (8, 0)

2 1 2 1 2
6 8+ − 8+ = 297
2 2

Calculation stop when 𝐼𝑓 𝑝2𝑘 > 0 𝑠𝑜 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘


𝑦𝑘 ≤ 0 Else 𝑤𝑒 𝑠𝑒𝑙𝑒𝑐𝑡 𝑥𝑘+1 = 𝑥𝑘 + 1
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
6
(3, 6) (8, 0)
5
(4, 5) 4
(5, 5) 3
(6, 4) 2
1
(7, 3)
Center 0
(0, 0) 0 1 2 3 4 5 6 7 8 9 10 11
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.
Scan-Line Polygon Fill
Algorithm
▪ For each scan-line crossing a polygon, the algorithm locates the
intersection points are of scan line with the polygon edges.
▪ This intersection points are stored from left to right.
▪ Frame buffer positions between each pair of intersection point are
set to specified fill color.

Scan line
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
Edge Intersection Calculation with
Scan-Line
▪ Coherence methods often involve incremental calculations applied
along a single scan line or between successive scan lines.
▪ In determining edge intersections, we can set up incremental
coordinate calculations along any edge by exploiting the fact that
the slope of the edge is constant from one scan line to the next.
▪ For above figure we can write slope equation for polygon
boundary as follows.
𝑦𝑘+1 −𝑦𝑘
▪ 𝑚=
𝑥𝑘+1 −𝑥𝑘
▪ Since change in 𝑦 coordinates between the two scan lines is
simply
▪ 𝑦𝑘+1 − 𝑦𝑘 = 1
Contd.
▪ So slope equation can be modified as follows
𝑦𝑘+1 −𝑦𝑘
▪ 𝑚=
𝑥𝑘+1 −𝑥𝑘
1
▪ 𝑚=
𝑥𝑘+1 −𝑥𝑘
1
▪ 𝑥𝑘+1 − 𝑥𝑘 =
𝑚
1
▪ 𝑥𝑘+1 = 𝑥𝑘 +
𝑚
▪ Each successive 𝑥 intercept can thus be calculated by adding the
inverse of the slope and rounding to the nearest integer.
Edge Intersection Calculation with Scan-Line for parallel
execution
▪ For parallel execution of this algorithm we assign each scan line to
separate processor in that case instead of using previous 𝑥 values
for calculation we use initial 𝑥 values by using equation as.
𝑘
▪ 𝑥𝑘 = 𝑥0 +
𝑚
∆𝑦
▪ Now if we put 𝑚 = in incremental calculation equation 𝑥𝑘+1 =
∆𝑥
1
𝑥𝑘 + then we obtain equation as.
𝑚
∆𝑥
▪ 𝑥𝑘+1 = 𝑥𝑘 +
∆𝑦
▪ Using this equation we can perform integer evaluation of 𝑥
intercept.
Simplified Method for Edge Intersection Calculation with
Scan-Line
1. Suppose 𝑚 = 7/3
2. Initially, set counter to 0, and increment to 3 (which is Δ𝑥).
3. When move to next scan line, increment counter by adding ∆𝑥
4. When counter is equal to or greater than 7 (which is Δ𝑦),
increment the 𝑥 − 𝑖𝑛𝑡𝑒𝑟𝑐𝑒𝑝𝑡 (in other words, the 𝑥 − 𝑖𝑛𝑡𝑒𝑟𝑐𝑒𝑝𝑡
for this scan line is one more than the previous scan line), and
decrement counter by 7(which is ∆𝑦). ∆𝑥 = 3, ∆𝑦 = 7

Counter=3
Counter=2
Counter=4
Counter=5
Counter=6
Counter=1
Counter=0

𝑦0
𝑥0
Use of Sorted Edge table in Scan-Line Polygon Fill
Algorithm
▪ To efficiently perform a polygon fill, we can first store the polygon
boundary in a sorted edge table.
▪ It contains all the information necessary to process the scan lines
efficiently.
▪ We use bucket sort to store the edge sorted on the smallest 𝑦
value of each edge in the correct scan line positions.
▪ Only the non-horizontal edges are entered into the sorted edge
table.
Contd.
Scan Line
Number
𝑦𝐶 𝑦𝐵 𝑥𝐶 1/𝑚𝐶𝐵
B .
.
.
𝑦𝐷 𝑦𝐶 𝑥𝐷 1/𝑚𝐷𝐶
.
C Scan Line 𝑦𝐶 . 𝑦𝐸 𝑥𝐷 1/𝑚𝐷𝐸
.
C E
Scan Line 𝑦𝐷 𝑦𝐴 𝑦𝐸 𝑥𝐴 1/𝑚𝐴𝐸
D .
Scan Line 𝑦𝐴 .
. 𝑦𝐵 𝑥𝐴 1/𝑚𝐴𝐵
A
1
0
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
Odd Even/ Odd Parity/ Even
Odd Rule
▪ By conceptually drawing a line from any position 𝑝 to a distant
point outside the coordinate extents of the object.
▪ Than counting the number of edges crossing by this line.
1. If Edge count is odd, than p is an interior point.
2. Otherwise p is exterior point.
▪ To obtain accurate edge count we must sure that line selected is
does not pass from any vertices. Boundary of Screen

1 2

𝑝
𝑟
1
𝑞
Nonzero Winding Number Rule
▪ This method counts the number of times the polygon edges wind
around a particular point in the counterclockwise direction.
▪ This count is called the winding number.
▪ We apply this rule by initializing winding number with 0.
▪ Then draw a line for any point 𝑝 to distant point beyond the
coordinate extents of the object.
Boundary of Screen

Winding number=0

𝑝
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
𝑞
Comparison between Odd Even Rule and Nonzero
Winding Rule
▪ For standard polygons and simple object both rule gives same
result but for more complicated shape both rule gives different
result.

Odd Even Rule Nonzero Winding Rule


Scan-Line Fill of Curved
Boundary Areas
▪ Scan-line fill of region with curved boundary is more time
consuming as intersection calculation now involves nonlinear
boundaries.
▪ For simple curve such as circle or ellipse scan line fill process is
straight forward process.
▪ We calculate the two scan line intersection on opposite side of the
curve.
▪ This is same as generating pixel position along the curve boundary
using standard equation of curve.
▪ Then we fill the color between two boundary intersections.
▪ Symmetry property is used to reduce the calculation.
Introduction to Boundary / Edge Fill
Algorithm
▪ In this method, edges of the polygons are drawn.
▪ Then starting with some seed (any point inside the polygon) we
examine the neighbouring pixels to check whether the boundary
pixel is reached.
▪ If boundary pixels are not reached, pixels are highlighted and the
process is continued until boundary pixels are reached.
▪ Selection of neighbour pixel is either 4-cormected or 8-connected.

4-Cormected Region 8-Cormected Region


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
Boundary / Edge Fill Algorithm
Procedure:
boundary-fill4(x, y, f-colour, b-colour)
{
if(getpixel (x,y) ! = b-colour && gepixel (x, y) ! = f-colour)
{
putpixel (x, y, f-colour)
boundary-fill4(x + 1, y, f-colour, b-colour);
boundary-fill4(x, y + 1, f-colour, b-colour);
boundary-fill4(x - 1, y, f-colour, b-colour);
boundary-fill4(x, y - l, f-colour, b-colour);
}
}
Problem of Staking and Efficient
Method
▪ Same procedure can be modified according to 8 connected region
algorithm by including four additional statements to test diagonal
positions.
▪ This procedure requires considerable stacking of neighbouring
points more, efficient methods are generally employed.
▪ Efficient method fill horizontal pixel spans across scan lines,
instead of proceeding to 4 connected or 8 connected
neighbouring points.
▪ Then we need only stack a beginning position for each horizontal
pixel span, instead of stacking all unprocessed neighbouring
positions around the current position.
▪ Starting from the initial interior point with this method, we first fill
in the contiguous span of pixels on this starting scan line.
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.
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
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.
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);
}
}
Character Generation
▪ We can display letters and numbers in variety of size and style.
▪ The overall design style for the set of character is called typeface.
▪ Today large numbers of typefaces are available for computer
application for example Helvetica, Arial etc.
▪ Originally, the term font referred to a set of cast metal character
forms in a particular size and format.
▪ Example: 10-point Courier Italic or 12- point Palatino Bold.
Contd.
▪ Now, the terms font and typeface are often used interchangeably,
since printing is no longer done with cast metal forms.
▪ Methods of character generation are:
➢ Bitmap Font/ Bitmapped Font
➢ Outline Font
➢ Stroke Method
➢ Starbust Method
Bitmap Font/ Bitmapped Font
▪ A simple method for representing the 0 0 1 1 1 1 0 0
0 1 1 1 1 1 1 0
character shapes in a particular typeface is to 1 1 0 0 0 0 1 1
use rectangular grid patterns. 1 1 0 0 0 0 1 1
1 1 1 1 1 1 1 1
▪ In frame buffer, the 1 bits designate which 1 1 1 1 1 1 1 1
pixel positions are to be displayed on the 1 1 0 0 0 0 1 1
1 1 0 0 0 0 1 1
monitor.
▪ Bitmap fonts are the simplest to define and display.
▪ Bitmap fonts require more space.
▪ It is possible to generate different size and other variation from
one set but this usually does not produce good result.
Outline Font
▪ In this method character is generated using curve
section and straight line as combine assembly.
▪ To display the character we need to fill interior
region of the character.
▪ This method requires less storage since each
variation does not required a distinct font cache.
▪ We can produce boldface, italic, or different sizes
by manipulating the curve definitions for the
character outlines.
▪ But this will take more time to process the outline
fonts, because they must be scan converted into
the frame buffer.
Stroke Method
• It uses small line segments to generate
a character.
• The small series of line segments are
drawn like a stroke of a pen to form a
character.
• We can generate our own stroke method by calling line
drawing algorithm.
• Here it is necessary to decide which line segments are
needs for each character and then draw that line to
display character.
• It support scaling by changing length of line segment.
Starbust Method
▪ In this method a fix pattern of lines (24 line) segments are used to
generate characters. 03 04
13 14
02 23 05
17 18
01 06
21
12 22 07
20
24 19
11 08
16 15
10 09

▪ We highlight those lines which are necessary to draw a particular


character.
▪ Pattern for particular character is stored in the form of 24 bit code.
▪ In which each bit represents corresponding line having that number.
▪ We put bit value 1 for highlighted line and 0 for other line.
Contd.
▪ Example letter V
03 04
13 14
02 23 05
17 18
01 06
21
12 22 07
20
24 19
11 08
16 15
10 09

▪ Code for letter V = 1 1 0 0 1 1 1 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0


▪ This technique is not used now a days because:
• It requires more memory to store 24 bit code for single character.
• It requires conversion from code to character.
• It doesn’t provide curve shapes.
Line Attributes
▪ Basic attributes of a straight line segment are:
• Type
• Dimension
• color
• pen or brush option.
Line Type
▪ Possible selection for the line-type attribute includes solid lines, dashed
lines, and dotted lines etc.
1 Solid

2 Dashed
3 Dotted
4 Dotdash
▪ We modify a line –drawing algorithm to generate such lines by setting
the length and spacing of displayed solid sections along the line path.
▪ To set line type attributes in a PHIGS application program, a user invokes
the function: setLinetype(It)
▪ Where parameter lt is assigned a positive integer value of 1, 2, 3, 4… etc.
to generate lines that are, respectively solid, dashed, dotted, or dotdash
etc.
Line Width
▪ Implementation of line-width options depends on the capabilities
of the output device.
▪ A heavy line on a video monitor could be displayed as adjacent
parallel lines, while a pen plotter might require pen changes.
▪ To set line width attributes in a PHIGS application program, a user
invokes the function: setLinewidthScalFactor (lw)
▪ Line-width parameter lw is assigned a positive number to indicate
the relative width of the line to be displayed.
▪ Values greater than 1 produce lines thicker than the standard line
width and values less than the 1 produce line thinner than the
standard line width.
Contd.
▪ In raster graphics we generate thick line by plotting
• above and below pixel of line path when slope |m|<1. &
• left and right pixel of line path when slope |m|>1.
Line Width at Endpoints and
Join
▪ As we change width of the line we can also change line end and
join of two lines which are shown below

Butt caps Miter join

Projecting square caps Round join

Round caps Bevel join


Line color
▪ The name itself suggests that it is defining color of line displayed
on the screen.

▪ By default system produce line with current color but we can


change this color by following function in PHIGS package as
follows: setPolylinecolorIndex (lc)
▪ In this lc is constant specifying particular color to be set.
Pen and Brush Options
• In some graphics packages line is
displayed with pen and brush
selections.
• Options in this category include
shape, size, and pattern.
• These shapes can be stored in a
pixel mask that identifies the
array of pixel positions that are
to be set along the line path.
• Also, lines can be displayed with
selected patterns by
superimposing the pattern
values onto the pen or brush
mask.
Color and Grayscale Levels
▪ Various colors and intensity-level options can be made available to
a user, depending on the capabilities and design objectives of a
particular system.
▪ General purpose raster-scan systems, for example, usually provide
a wide range of colors, while random-scan monitors typically offer
only a few color choices, if any.
▪ In a color raster system, the number of color choices available
depends on the amount of storage provided per pixel in the frame
buffer
Contd.
▪ Also, color-information can be stored in the frame buffer in two
ways:
• We can store color codes directly in the frame buffer OR
• We can put the color codes in a separate table and use pixel values as an
index into this table
▪ With direct storage scheme we required large memory for frame
buffer when we display more color.
▪ While in case of table it is reduced and we call it color table or
color lookup table.
Color Lookup Table
▪ Color values of 24 bit is stored in lookup table and in frame buffer
we store only 8 bit index of required color.
▪ So that size of frame buffer is reduced and we can display more
color. Color
Lookup
Frame Buffer Table
0 To Red Gun
To Green Gun
To Blue Gun

2081 00000000 00001000 00100001


196 196

255
Greyscale
▪ With monitors that have no color capability, color function can be
used in an application program to set the shades of grey
(greyscale) for display primitives.
▪ Numeric values between 0-to-1 can be used to specify greyscale
levels.
▪ This numeric values is converted in binary code for store in raster
system. Example: frame buffer with 2 bits per pixel.
Intensity Code Stored Intensity Values In The Displayed Greyscale
Frame Buffer Binary Code
0.0 0 00 Black
0.33 1 01 Dark grey
0.67 2 10 Light grey
1.0 3 11 White
Area-Fill Attributes
▪ For filling any area we have choice between solid colors or pattern
to fill all these are include in area fill attributes. Which are:
• Fill Styles
• Pattern Fill
• Soft Fill
Fill Styles
▪ Area are generally displayed with three basic style.
1. hollow with color border
2. filled with solid color
3. filled with some design
▪ In PHIGS package fill style is selected by following function:
setInteriorStyle (fs)
▪ Value of fs include hollow ,solid, pattern etc.
Contd.
▪ Another values for fill style is hatch, which is patterns of line like
parallel line or crossed line.

Hollow Solid Pattern Diagonal Diagonal Cross-


Hatch Fill Hatch Fill

▪ For setting interior color in PHIGS package we use:


setInteriorColorIndex (fc)
▪ Where fc specify the fill color.
Pattern Fill
• We select the pattern with Pattern Table
setInteriorStyleIndex (pi) Index(pi) Pattern(cp)
• Where pattern index parameter pi 1 4 0
specifies position in pattern table 0 4
2 2 1 2
entry.
1 2 1
• For example: 2 1 2
– SetInteriorStyle( pattern ) ;
– setInteriorStyleIndex ( 2 ) ;
– fillArea (n, points);
Contd.
▪ We can also maintain separate table for hatch pattern.
▪ We can also generate our own table with required pattern.
▪ Other function used for setting other style as follows:
setpatternsize (dx, dy)
▪ setPaternReferencePoint (position)
▪ We can create our own pattern by setting and resetting group of
pixel and then map it into the color matrix.
Soft Fill
▪ Soft fill is filling layer of color on back ground color so that we can
obtain the combination of both color.
▪ It is used to recolor or repaint so that we can obtain layer of
multiple color and get new color combination.
▪ One use of this algorithm is soften the fill at boundary so that
blurred effect will reduce the aliasing effect.
▪ For example if we fill t amount of foreground color then pixel color
is obtain as:
▪ 𝑝 = 𝑡𝐹 + 1 − 𝑡 𝐵
▪ Where F is foreground color and B is background color
Contd.
▪ If we see this color in RGB component then:
▪ 𝑝 𝑝𝑖𝑥𝑒𝑙 = 𝑝𝑟 , 𝑝𝑔 , 𝑝𝑏
▪ 𝑓(𝑓𝑜𝑟𝑔𝑟𝑜𝑢𝑛𝑑) = (𝑓𝑟 , 𝑓𝑔 , 𝑓𝑏 )
▪ 𝑏(𝑏𝑎𝑐𝑘𝑔𝑜𝑢𝑛𝑑) = (𝑏𝑟 , 𝑏𝑔 , 𝑏𝑏 )
▪ Then we can calculate t as follows:
𝑃𝑘 −𝐵𝑘
▪ 𝑡=
𝐹𝑘 −𝐵𝑘
▪ If we use more then two color say three at that time equation
becomes as follow:
▪ 𝑝 = 𝑡0 𝐹 + 𝑡1 𝐵1 + (1 − 𝑡0 − 𝑡1 )𝐵2
▪ Where the sum of coefficient 𝑡0 , 𝑡1 , and (1 − 𝑡0 − 𝑡1 ) is 1.
Character Attributes
▪ The appearance of displayed characters is controlled by attributes
such as:
• Font
• Size
• Color
• Orientation.
▪ Attributes can be set for entire string or may be individually.
Text Attributes
▪ In text we are having so many style and design like italic fonts,
bold fonts etc.
▪ For setting the font style in PHIGS package we have function:
setTextFont (tf)
▪ Where tf is used to specify text font.
▪ For setting color of character in PHIGS we have function:
setTextColorIndex (tc)
▪ Where text color parameter tc specifies an allowable color code.
▪ For setting the size of the text we use function:
setCharacterheight (ch)
▪ Where ch is used to specify character height.
Contd.
▪ For scaling the character we use function:
setCharacterExpansionFacter (cw)
▪ Where character width parameter cw is set to a positive real
number that scale the character body width.
▪ Spacing between character is controlled by function:
▪ setCharacterSpacing (cs)
▪ Where character spacing parameter cs can be assigned any real
value.
Contd.
▪ The orientation for a displayed character string is set according to
the direction of the character up vector:
setCharacterUpVector (upvect)
▪ Parameter upvect in this function is assigned two values that
specify the x and y vector components.
▪ Text is then displayed so that the orientation of characters from
baseline to cap line is in the direction of the up vector.
▪ For setting the path of the character we use function:
setTextPath (tp)
▪ Where the text path parameter tp can be assigned the value:
right, left, up, or down.
Contd.
▪ For setting the alignment we use function:
setTextAlignment (h, v)
▪ Where parameter h and v control horizontal and vertical
alignment respectively.
▪ For specifying precision for text display is given with function:
setTextPrecision (tpr)
▪ Where text precision parameter tpr is assigned one of the values:
string, char, or stroke.
▪ The highest-quality text is produced when the parameter is set to
the value stroke.
Marker Attributes
▪ A marker symbol display single character in different color and in
different sizes.
▪ For marker attributes implementation by procedure that load the
chosen character into the raster at defined position with the
specified color and size.
▪ We select marker type using function: setMarkerType (mt)
▪ Where marker type parameter mt is set to an integer code.
Contd.
▪ Typical codes for marker type are the integers 1 through 5,
specifying, respectively:
1. a dot (.)
2. a vertical cross (+)
3. an asterisk (*)
4. a circle (o)
5. a diagonal cross (x).
▪ Displayed marker types are centred on the marker coordinates.
Contd.
▪ We set the marker size with function:
SetMarkerSizeScaleFactor (ms)
▪ Where parameter marker size ms assigned a positive number
according to need for scaling.
▪ For setting marker color we use function:
setPolymarkerColorIndex (mc)
▪ Where parameter mc specify the color of the marker symbol.
Aliasing
▪ Primitives generated in raster graphics by various algorithms have
stair step shape or jagged appearance.
▪ Jagged appearance is due to integer calculation by rounding actual
values.
▪ This distortion of actual information due to low frequency
sampling is called aliasing.
Antialiasing
▪ Minimise effect of aliasing by some way is known as antialiasing.
▪ In periodic shape distortion may be occurs due to under sampling.

▪ To avoid losing information from such periodic objects, we need to


set the sampling frequency to at least twice that of the highest
frequency occurring in the object.
▪ This is referred to as the Nyquist sampling frequency (or Nyquist
sampling rate):
𝑓𝑠 = 2𝑓𝑚𝑎𝑥
Contd.
▪ In other words sampling interval should be no larger than one-half the
cycle. Which is called nyquist sampling interval.
∆𝑥𝑐𝑦𝑐𝑙𝑒
∆𝑥𝑠 =
2
▪ One way to solve this problem is to display image on higher resolution.
▪ But it has also limit that how much large frame buffer we can maintain
along with maintaining refresh rate 30 to 60 frame per second.
▪ And also on higher resolution aliasing will remains up to some extents.
▪ With raster systems that are capable of displaying more than two
intensity levels (color or grayscale), we can apply antialiasing methods to
modify pixel intensities.
▪ By appropriately varying the intensities of pixels along the boundaries of
primitives, we can smooth the edges to lessen the aliasing effect.
Antialiasing Methods
1. Supersampling Straight Line Segments
2. Pixel-Weighting Masks
3. Area Sampling Straight Line Segments
4. Filtering Techniques
5. Pixel Phasing
6. Compensating For Line Intensity Differences
7. Antialiasing Area Boundaries
Supersampling Straight Line
Segments
▪ For the greyscale display of a straight-line segment, we can divide
each pixel into a number of sub pixels and determine the number
of sub pixel along the line path.
▪ Then we set intensity level of each pixel proportional to number of
sub pixel along the line path.
▪ E.g. in figure area of each pixel is
divided into nine sub pixel and then we
determine how many number of sub
pixel are along the line ( it can be 3 or 2
or 1 as we divide into 9 sub pixel).
▪ Based on number 3 or 2 or 1 we assign
intensity value to that pixel.
Contd.
▪ We can achieve four intensity levels by dividing pixel into 16 sub
pixels and five intensity levels by dividing into 25 sub pixels etc.
▪ Lower intensity gives blurred effect and hence performs
antialiasing.
▪ Other way is we considered pixel areas of finite size, but we
treated the line as a mathematical entity with zero width.
▪ Actually, displayed lines have a width approximately equal to that
of a pixel.
▪ If we take finite width of the line into account, we can perform
supersampling by setting each pixel intensity proportional to the
number of sub pixels inside the polygon representing the line
area.
Contd.
▪ A sub pixel can be considered to be
inside the line if its lower left corner is
inside the polygon boundaries.
▪ Advantage of this is that it having
number of intensity equals to number of
sub pixel.
▪ Another advantage of this is that it will distribute total intensity
over more pixels.
▪ E.g. in figure pixel below and left to (10, 20) is also assigned some
intensity levels so that aliasing will reduce.
▪ For color display we can modify levels of color by mixing
background color and line color.
Pixel-Weighting Masks
▪ Supersampling method are often implemented by giving more
weight to sub pixel near the center of pixel area.
▪ As we expect centre sub pixel to be more important in
determining the overall intensity of a pixel.
▪ For the 3 by 3 pixel subdivisions we have considered so far, a
weighting scheme as in fig. could be used.
▪ The center sub pixel here is weighted four times that of the corner
sub pixels and twice that of the remaining sub pixels.
▪ By averaging the weight of sub pixel which are
along the line and assign intensity proportional to
average weight will reduce aliasing effect.
Area Sampling Straight Line
Segments
▪ In this scheme we treat line as finite width rectangle, and the
section of the line area between two adjacent vertical or two
adjacent horizontal screen grid lines is then a trapezoids.
▪ Overlap areas for pixels are calculated by determining how much
of the trapezoid overlaps each pixel in that vertical column (or
horizontal row).
▪ E.g. pixel with screen grid coordinates
(10, 20) is about 90 percent covered by
the line area, so its intensity would be
set to 90 percent of the maximum
intensity.
Contd.
▪ Similarly, the pixel at (10 21) would be set to an intensity of about
15-percent of maximum.
▪ With color displays, the areas of pixel overlap with different color
regions is calculated and the final pixel color is taken as the
average color of the various overlap areas.
Filtering Techniques
▪ It is more accurate method for antialiasing.
▪ Common example of filter is rectangular, conical and Gaussian
filters.
▪ Methods for applying the filter function are similar to applying a
weighting mask, but now we integrate over the pixel surface to
obtain the weighted average intensity.
▪ For reduce computation we often use table look up.
Pixel Phasing
▪ On raster system if we pass the electron beam from the closer sub
pixel so that overall pixel is shifted by factor ¼, ½, or ¾ to pixel
diameter.
▪ Where beam strike at that part of pixel get more intensity then
other parts of the pixel and gives antialiasing effect.
▪ Some systems also allow the size of individual pixels to be
adjusted as an additional means for distributing intensities.
Compensating For Line Intensity
Differences
▪ Antialiasing a line to soften the aliasing effect also compensates
for another raster effect, illustrated fig.
▪ As both lines are display with same number of pixel and then also
length of diagonal line is greater than horizontal line by factor 2.
▪ So that diagonal line is display with less intensity then horizontal
line.
▪ For compensating this we display diagonal line with high intensity
and horizontal line with low intensity so that this effect is
minimize.
▪ In general we set intensity according to slope of
the line.
Antialiasing Area Boundaries
▪ Methods we discuss for antialiasing line can also be applied for
area boundary.
▪ If system capabilities permit the repositioning of pixels, area
boundaries can be smoothen by adjusting boundary pixel
positions.
▪ Other method is to adjust each pixel intensity at boundary
position according to percent of area inside the boundary.
Contd.
▪ In fig. pixel at (x, y) is assigned half the intensity as its ½ area is
inside the area boundary.
▪ Similar adjustments based on percent of area of pixel inside are
applied to other pixel.

You might also like