University of Science and TechnologyFaculty of Computer Science and
Information TechnologyComputer Science –Department
4th- Year
Computer GraphicsChapter(3)
Scan Conversion Algorithms (Output primitives)Dia Eldein Mustafa Ahmed
2018
Overview
• Primitives and Attributes.
• Raster Graphics (Rasterization).
• Why Scan Conversion?
• Algorithms for Scan Conversion:
Lines
Circles
Ellipses
Filling
Polygons
2Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
2D Output Primitives and Attributes
PRIMITIVESƒPoints
Lines
Circles
Ellipses
Curves
Filled Area
Text
ATTRIBUTESƒColor , size Line Type, Width and Color
Fill Styles: Hollow, Solid and Patterned
Text Font, Color, Size and Style TextTextText
Text
3Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
• Points
• A point is shown by illuminating a pixel on the screen
2D Output Primitives and Attributes
Each point is represented as a Pixel with (x,y ,color)
4Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
• Lines
• A line segment is
completely defined in terms
of its two endpoints.
• A line segment is thus
defined as:
Line_Seg = { (x1, y1), (x2, y2) }
2D Output Primitives and Attributes
5Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
(x1, y1)
(x2, y2)
• A line is produced by means of illuminating a set of intermediary pixels between the two endpoints.
• Lines is digitized into
a set of discrete integer positions that approximate the actual line path. x2
2D Output Primitives and Attributes
x
y
y1
y2
x1
6Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
Example: A computed line position of (10.48, 20.51) is converted to pixel position (10, 21).
• The rounding of coordinate values to integer causes all but horizonatal and vertical lines to be displayed with a stair step appearance “the jaggies”.
2D Output Primitives and Attributes
7Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
Rasterization
Process of converting an image described in a Vectorgraphics format (shapes), into a Raster image (pixels or dots).
Rasterization
8Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
Rasterization Problem: Given only the two end points, how to compute the intermediate pixels, so that the set of pixels closely approximate the ideal line.
Scan Conversion
• Also known as rasterization.
• In our programs objects or primitives (points , line , circle ,curves , any 2D or 3D shape) are represented symbolically.
– 3D coordinates representing an object’s position
– Attributes representing color, motion, etc.
• But, the display device is a 2D array of pixels (unless you’re doing holographic displays).
9Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
Scan Conversion is the process of representing continuous graphics object as a collection of discrete pixels
Properties of an Ideal Line
• Must appear straight and continuous
– Only possible axis-aligned and 45 degree lines
• Must interpolate both defining end points.
• Must have uniform density and intensity
– Consistent within a line and over all lines
• Must be efficient, drawn quickly .
– Lots of them are required!!!
• Lines should terminate accurately.
• Lines should be drawn rapidly.
– Efficient algorithms. مربط الفرس10
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
The lines of this objectappear continuous
However, they aremade of pixels
11
Properties of an Ideal Line
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
• How does a machine or computer draw a line defined by a mathematical representation (e.g. using endpoints only)?
• How does the continuous line description get converted to the discrete pixel representation?
• Important part of Rasterization process is to convert the line segment into a set of pixels in the display space
Line Drawing Algorithms
12Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
(X1, Y1)
(X2, Y2)
(Xn, Yn)
Display Space
Lined Drawing Algorithms
• Slope -Intercept method (incremental method)
• Digital Differential (DDA) Algorithm
• Midpoint algorithm
• Parametric Equation
• Bresenham’s Line Algorithm
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 13
1. A line in Computer graphics is a portion of straight line that extends indefinitely in opposite direction.
2. It is defined by its two end points P1(x1,y1) and P2(x2,y2)..
3. Its density should be independent of line length.
the slope intercept equation for a line:
where, m = Slope of the line
b = the y intercept of a line
Line Drawing AlgorithmsSlope -Intercept method
)1.........(bmxy
14Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
The two endpoints of a line segment are specified at positions P1(x1,y1) and P2(x2,y2).
15Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
x1 x2
x
y
P1(x1,y1)
P2(x2,y2)
b
O
y2
y2
Line Drawing AlgorithmsSlope -Intercept method
We can determine the value for slope m & bintercept as :
)2.......(..........)
12(
)12
(
x
y
xx
yym
)3.(..........*xmybii
We can substitute in equation (3) either P1(x1,y1) or P2(x2,y2) to compute b .
16Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
)4....(..........1
*1 xmyb
Line Drawing AlgorithmsSlope -Intercept method
1- Input end points P1(x1,y1) ,P2(x2 ,y2)
2- Compute
3- Compute
4 –Compute the slope
3- Compute the intercept
4- If (x2 > x1)
dx = 1
else
dx = -1
5- while (x1 != x2)
y = m * x1 + b
PlotPixel(x1, round(y))
x1 += dx
6- EndComputer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 17
What’s the problem?If the slope m> 1, the line is not continuous, pixels are skipped
Line Drawing AlgorithmsSlope -Intercept method
xxx12
yyy12
x
ym
xmyb1
*1
P2(x2,y2)
P1(x1,y1)
P1(x1,y1)
P2(x2,y2)
Example 1: The endpoints of line are(1,3) & (6,18). Compute each value of y as x steps from 1 to 6 and plot the result.
Solution :
18Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
Line Drawing AlgorithmsSlope -Intercept method
51612
xxx
1531812
yyy
35
15
x
ym
112
dxxx01*33
1*
1 xmyb
The challenge is: to find a way to calculate the next x,y position by previous one as quickly as possible.
19Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
(x1, round(y))Y= m * x1 + bX1
(1,3)=3*1+0=31
(2,6)=3*2+0=62
(3,9)=3*3+0=93
(4,12)=3*4+0=124
(5,15)=3*5+0=155
(6,18)=3*6+0=186
xx dx 11011
Line Drawing AlgorithmsSlope -Intercept method
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 20
P1(1,3)
P2(2,6)
P3(3,9)
P4(4,12)
P5(5,15)
P6(6,18)
1
2
3
X
Y
The algorithm performs a floating-point multiplication for every step in x.This method therefore requires an enormous number of floating-pointmultiplications, and is therefore more expensive
• Exercises :
1)Draw line given by end points (12,10) and (21, 13).
2) Draw and sketch the line given by the end points
(-3,8) and (-6 ,-11).
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
21
Line Drawing AlgorithmsSlope -Intercept method
In the Slope -Intercept method algorithm, we increment x and find the y value corresponding to the new x using the line equation.
The result is a real number that is rounded to the nearest integer.
The Digital differential analyzer (DDA) algorithm is anincremental scan-conversion method.
Such an approach is characterized by performingcalculations at each step using results from thepreceding step.
22Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
Line Drawing Algorithms
DDA -Algorithm
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 23
• The differential equation of a straight line is given by:
Line Drawing Algorithms
DDA -Algorithm
)1(
1
1
12
12 .....)(
)(
)(
)(
xx
yy
xx
yy
x
y
ii
iim
yi 1
xi xi 1 xi 2xy
i
yi 2
y
y
x
)2(1 ...........
)(
xm yy ii
)3(1
............xmyyii
)4(1
............xmyyii
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 24
(Case a: m < 1) distance on x-axis is greater than on y-axis( )
and from (4)
Then the straight line equation model is given by (5) & (6):
Line Drawing Algorithms
DDA -Algorithm
)5(1 .......1 ii xxx
)6(1 ...............myy ii
yx
(Case a: m < 1) or Δy<Δx
• In this case we use equations (7) with increment in x by1 and increment y by m
(7)
• That means y is independent of x , but depend on the slope m.
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 25
Line Drawing Algorithms
DDA -Algorithm
myy
xx
ii
ii
1
1 1
26Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
Line Drawing Algorithms
DDA -Algorithm
(Case b: m > 1) or Δy>Δx
And from (4)
or
ii xxm
1
1
)8(1 .......1 ii yyy
)9(1 .).........(1 ii xxm
)10(1 .......1
mxx ii
(Case b: m > 1) or Δy>Δx
In this case we use equations (8) and (10) to construct the straight line equation model (11) , with increment in y by 1 and increment x by .
(11)
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 27
Line Drawing Algorithms
DDA -Algorithm
mxx
yy
ii
ii
1
1
1
1
m
1
• Example (1) : Draw the line with end points P1(20,10) and P2(30,18)
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 28
Line Drawing Algorithms
DDA -Algorithm
17
16
15
14
13
12
11
10
18
292726252423222120 28 30
step x y Plot(x,y)
1 20 10 (20,10)
2 21 10.8 (21,11)
3 22 11.6 (22,12)
4 23 12.4 (23,12)
5 24 13.2 (24,13)
6 25 14 (25,14)
7 26 14.8 (26,15)
8 27 15.6 (27,16)
9 28 16.4 (28,16)
10 29 17.2 (29,17)
11 30 18 (30,18)
x = 30 – 20 = 10 y = 18 – 10 = 8 Larger length = 10 = x
Yinc =m= 8 / 10 = 0.8 Xinc = 1
29
Line Drawing Algorithms
DDA -Algorithm
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 30
Line Drawing Algorithms
DDA -Algorithm
Example (2) : Draw the line with end points P1(8,12) and P2(16,28)
step x y Plot(x,y)
1 8 12 (8,12)
2 8.5 13 (9,13)
3 9 14 (9,14)
4 9.5 15 (10,15)
5 10 16 (10,16)
6 10.5 17 (11,17)
7 11 18 (11,18)
8 11.5 19 (12,19)
9 12 20 (12,20)
10 12.5 21 (13,21)
11 13 22 (13,22)
12 13.5 23 (14,23)
13 14 24 (14,24)
14 14.5 25 (15,25)
15 15 26 (15,26)
16 15.5 27 (16,27)
17 16 28 (16,28)
x = 16 – 8 = 8
y = 28 – 12 = 16
Larger length = 16 = y
Xinc =1/m= 8 / 16 =0.5
Yinc = 1
31Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 32
19
18
17
16
15
14
13
12
20
1715141312111098 16 18
2122
23
24
25
26
27
28
33Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
• Algorithm:
1. Input end points p(x0 , y0 ) and p(xend , yend ) .
2. Compute Δx=xend -x0.
3. Compute Δy =yend -y0.
4. Plot p(x0 , y0 )
5. Compute m= Δy/Δx6. If (m>1)
for y=y0 +1 to yendx= x0+ 1/m
plot p(round (x),y)else
for x=x0 +1 to xendy= y0 + m
plot p(x,round (y))
7. End
Line Drawing AlgorithmsDDA -Algorithm
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 34
Digital Differential
Analyzer
Line Drawing Algorithm
Bresenhams Line Drawing Algorithm
ArithmeticDDA algorithm uses floating
points i.e. Real Arithmetic.
Bresenhams algorithm uses fixed points
i.e. Integer Arithmetic.
Operations
DDA algorithm uses
multiplication and division
in its operations.
Bresenhams algorithm uses only
subtraction and addition in its
operations.
Speed
DDA algorithm is rather
slowly than Bresenhams
algorithm in line drawing
because it uses real arithmetic
(floating-point operations).
Bresenhams algorithm is faster than DDA
algorithm in line drawing because it
performs only addition and subtraction in
its calculation and uses only integer
arithmetic so it runs significantly faster.
Line Drawing Algorithms
Difference Between DDA Line Drawing Algorithm and
Bresenhams
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 35
Accuracy &
Efficiency
DDA algorithm is not as
accurate and efficient as
Bresenham algorithm.
Bresenhams algorithm is more
efficient and much accurate than DDA
algorithm.
Drawing
DDA algorithm can draw circles
and curves but that are not as
accurate as Bresenhams
algorithm.
Bresenhams algorithm can draw circles
and curves with much more accuracy than
DDA algorithm.
Round Off
DDA algorithm round off the
coordinates to integer that is
nearest to the line.
Bresenhams algorithm does not round off
but takes the incremental value in its
operation.
Expensive
DDA algorithm uses an enormous
number of floating-point
multiplications so it is expensive.
Bresenhams algorithm is less expensive
than DDA algorithm as it uses only
addition and subtraction.
Line Drawing Algorithms
Difference Between DDA Line Drawing Algorithm and
Bresenhams
Exercise :(1) Scan convert a line having end points (3,2) & (4,7)
using DDA.
(2) Using the above end points (4,7) as start point and (3,2) as end point , draw the line using DDA.
(3) Scan convert a line with end points (4,11) & (18,8)
Using DDA.
36Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
Line Drawing Algorithms
DDA -Algorithm
Line Drawing Algorithms
Bresenham’s Line Algorithm
The Bresenham’s algorithm is another incrementalscan conversion algorithm.
The big advantage of this algorithm is that, it uses onlyinteger calculations.
Moving across the x- axis in unit intervals and at eachstep choose between two different y coordinates.
For example, as shown in the following illustration,from position (2, 3) you need to choose between (3, 3)and (3, 4) in order to elongate it to (5,5) .
You would like the point that is closer to the originalline.
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 37
Line Drawing Algorithms
Bresenham’s Line Algorithm
• At sample position , the vertical separations from the mathematical line are labeled as and
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 38
xk 1
d upper d lower
1xk
yk
y
1yk
Line Drawing Algorithms
Bresenham’s Line Algorithm
• You can use these to make a simple decision about which pixel is closer to the mathematical line.
• This simple decision is based on the difference between the two pixel positions.
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 39
Line Drawing Algorithms
Bresenham’s Line Algorithm
• From the above illustration, the y coordinate on the mathematical line at is −
• So, and are given as follows −
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 40
bxmy k )1(
d upperd lower
bxmyyyd kkkupper
)1(11
ybxmyyd kkklower )1(
1kx
byxm
xmbyy
xmbyydd
kk
kkk
kkkupperlower
221)1(2
)1(22)1(
)1(22)(1
Line Drawing Algorithms
Bresenham’s Line Algorithm
• Let us substitute m with dy/dx where dx and dy are the differences between the end-points.
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 41
byxdx
dydd kkupperlower 221)1(2
Cdxydyx
bdxdydxydyx
byxdx
dydxdddx
kk
kk
kkupperlower
)(2)(2
)12(22)(2)(2
)221)1(2()(
Line Drawing Algorithms
Bresenham’s Line Algorithm
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 42
So, a decision parameter for the step along a line is given by −
kP thk
Cdxydyxdddxpkkupperk lower
)(2)(2)(
• The sign of the decision parameter is the same as that of .• If is negative, then choose the lower pixel, otherwise choose the upper pixel.• Remember, the coordinate changes occur along the x axis in unit steps, so you can do everything with integer calculations.
kPdd upperlower
kP
• At step , the decision parameter is given as −
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 43
Line Drawing Algorithms
Bresenham’s Line Algorithm
1k
Cdxydyxpkkk
)(2)(2111
Subtracting from this we get −
But, is the same as . So −
kP
))(2)(2())(2)(2(111
CdxydyxCdxydyxppkkkkkk
xk 1 1xk
)(2211 yydxdypp
kkkk
• Where, is either 0 or 1 depending on the sign of .
• The first decision parameter is evaluated at is given as −
• Now, keeping in mind all the above points and calculations, here is the Bresenham’s example for slope m < 1
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 44
)(1
yykk
kP
0P ),( 00 yx
Line Drawing Algorithms
Bresenham’s Line Algorithm
dxdyP 20
• If the next point to plot is and
• If the next point to plot is and
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 45
0kP ),1( yxkk
dyppkk
21
0kP
Line Drawing Algorithms
Bresenham’s Line Algorithm
)1,1( kk yx
)(21
dxdyppkk
• To illustrate the algorithm, we digitize the line with endpoints (20,10) and (30,18). This line has slope of 0.8, with
Δx = 10
Δy =8
• The initial decision parameter has the value
p0 = 2Δy − Δx = 6
• and the increments for calculating successive decision parameters are
2 Δy = 16
2 Δy - 2 Δx = -4
Line Drawing Algorithms
Bresenham’s Line Algorithm
46Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018
• We plot the initial point
(x0 , y0)=(20,10) and determine
successive pixel positions
along the line path from the
decision parameter as
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 47
k pk (xk +1, yk +1)
0 6 (21,11)
1 2 (22,12)
2 -2 (23,12)
3 14 (24,13)
4 10 (25,14)
5 6 (26,15)
6 2 (27,16)
7 -2 (28,16)
8 14 (29,17)
9 10 (30,18)
Line Drawing Algorithms
Bresenham’s Line Algorithm
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 48
Line Drawing Algorithms
Bresenham’s Line Algorithm
17
16
15
14
13
12
11
10
18
292726252423222120 28 30
• Algorithm1. Input the line end points p(x0 , y0 ) and p(xend , yend ) .2. Plot the first point p(x0 , y0 ) .3. Calculate the constants Δx, Δy, 2Δy, and 2(Δy − Δx), and
obtain the starting value for the decision parameter asp0 = 2Δy − Δx
4. At each xk along the line, starting at k = 0 , perform the following test:
If pk < 0,the next point to plot is (xk +1, yk )andpk+1=pk+2Δy
Otherwise, the next point to plot is (xk +1, yk +1) andpk+1=pk+2Δy−2Δx
5. Repeat step 4, Δx−1 times.Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 49
Line Drawing Algorithms
Bresenham’s Line Algorithm
• Exercise :
(1) Go through the steps of the Bresenham’s line drawing algorithm for a line going from (21,12) to (29,16).
(2) Using the three above methods (slope-intercept , DDA and Bresenham’s algorithm , draw the line joining the end points (3,11) and (-9,18). What are the accurate line regarding the points laying in the path of the line ?.
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 50
Line Drawing Algorithms
Bresenham’s Line Algorithm
• Circle Generation Algorithms
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 51
Circle Drawing AlgorithmsCartesian Co-ordinate Form
The equation of a circle:
We could solve for y in terms of xP(x0 , y0)
P(x,y)
x
y
r
If the center at any point (x0 , y0 )
Equation of the circle in this form is:
then from (1) we can find that
From (2) we can compute the value of with respect to the corresponding value of .
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 52
Circle Drawing AlgorithmsCartesian Co-ordinate Form
)1(..........222 ryx
)2(..........22
xry
y
x
x
y
dx
r
P(x,y)
If the center at the origin O(0 , 0)
O(0,0)
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 53
Circle Drawing AlgorithmsCartesian Co-ordinate Form
We can draw the upper part of the circle with the equation:
And the lower part with
the equation
If we implement
a decrement in x by dx ,then
Can compute the corresponding
Values of y from (3) and (4).
y
x
dx
r
P(x,y)
P(r,0)P(-r,0)
P(0,r)
P(0,-r)
xry 22
xry 22
)3.........(22
xry
)4.......(22
xry
P(-x,y)
Algorithm:( while version)1- input the radius r2- x=r 3- dx=13- while (x > - r)
PlotPixel( x, round(y))PlotPixel( x, round(-y))
x=x-dx4- End
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 54
Circle Drawing AlgorithmsCartesian Co-ordinate Form
xry 22
Algorithm: :( for version)1-input the radius r2- x=r 3- dx=13- for x=r to - r
PlotPixel( x, round(y))PlotPixel( x, round(-y))
x=x-dx4- End
xry 22
To draw a more smooth circle (dense points) we can take small value of dx (e.g. dx=0.5 or dx=0.1
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 55
Circle Drawing AlgorithmsPolar Co-ordinate Form
x
y
d
P(x,y)=P(r , )
P(r , +d)
)2)........(sin(
)1)........(cos(
ry
rx
From the previous concepts of Polar Co-ordinates :
20
rr
In this case the circle will be drawn as one unit based on the value of ()
When =0
00*)0sin(
1*)0cos(
rry
rrrx
P (0, r)
P (r, 0)
When =90
rrry
rrx
1*)90sin(
00*)90cos(
P (r, 0)
P (0, r)
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 56
Circle Drawing AlgorithmsPolar Co-ordinate Form
Algorithm:( while version)1- input the radius r2- =3.143- C= /1804- =04- while ( < 2* )
PlotPixel( round(x), round(y))
= +15- End
)*sin(
)*cos(
Cry
Crx
Algorithm:( for version)1- input the radius r2- =3.143- C= /1804- for =0 to 2*
PlotPixel( round(x), round(y))
= +15- End
kCry
hCrx
)*sin(
)*cos(
1
Center at the origin (0,0 ) Center at the origin (h,k )
• The Cartesian equation for the ellipse shown below can be written in terms of the ellipse center coordinates and parameters rx and ry as:
• If the center at the origin
the equation will be:
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 57
Ellipse Drawing Algorithms
1
22
y
c
x
c
r
yy
r
xx
),( yxcc
rx
ry
),( yxcc
xc
yc
X
Y
1
22
yx r
y
r
x
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 58
22
1
x
c
y
c
r
xx
r
yy
c
x
cy y
r
xxry
2
12
1
x
c
y
c
r
xx
r
yy
Ellipse Drawing Algorithms
22
1
xy r
x
r
y
2
1
x
yr
xry
2
1
xy r
x
r
y
)(0 origintheatcentertheyxif cc
• The Polar equation for the ellipse shown below can be written in terms of the ellipse center coordinates and parameters rx and ry as:
• If the center at the origin
the equation will be:
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 59
Ellipse Drawing Algorithms
yy
xx
cry
crx
)sin(*
)cos(*
),( yx cc
rx
ryX
Y
P(r, )
)sin(*
)cos(*
y
x
ry
rx
)0,0(
Computer Graphics - Chapter (3) Diaa Eldein Mustafa Ahmed-2018 60
Ellipse Drawing Algorithms
Algorithm:( Cartesian)
1- input the center (Xc ,Yc)
2- input the radius rx , ry
3- for x= rx to -rx
PlotPixel( round(x), round(y))
PlotPixel( round(x), round(-y))
4- End
Algorithm:( Polar)1- input the center (Xc ,Yc)
2- input the radius rx , ry
3- =180
4- C= /180
5- for =0 to 2*
x=rx *cos(C*) + Xc
Y=ry *sin(C*) + Yc
PlotPixel( x, round(y))
6- End
yr cy rxx
yx
c
2)(1
Top Related