Вы находитесь на странице: 1из 19

Ellipse Drawing Algorithm

Using Ellipse equation Using Mid point Ellipse Algorithm  1

Ellipse Drawing Algorithm

The equation of an ellipse can be written as [(x – α)/r x ] 2 + [(y - β)/r y ] 2 = 1 -------------------(1) 2

Using polar co –ordinates (r, θ) :

x = α +r x .cosθ ---------------- (1)

y = β + r y .sinθ ---------------- (2) 3

Symmetrical point calculations:- (- x, y)
(x, y)
r
y
r
x
(-x, -y)
(x, -y)
4

y r y
r x

Slope = -1

Region -1

Region - 2

x 5

Midpoint Ellipse Drawing algorithm

Let us define an ellipse function with (α, β) = (0,0), as f(x, y) = (x/r x ) 2 + (y/r y ) 2 – 1 = x 2 .r y 2 + y 2 .r x 2 – r x 2 .r y

2

Let (x 1 , y 1 ) be a point on the ellipse, then

f (x 1 , y 1 )

= 0

< 0

> 0   on the ellipse boundary inside the ellipse boundary outside the ellipse boundary So, we may conclude that the ellipse function may be
served as decision parameter
Contd….
6

(X k ,Y k ) (X k+1 ,Y k+1 ) or
Either
(Y
X k+1
k )
(Y k-1

Y k

Y k – 1/2

) Y k - 1  X k
X k+1
7

Starting at (0, r ), take unit steps in X-direction until reach the boundary between region 1 and region 2. Then switch to unit steps in Y-direction over the remainder of the curve in the first quadrant. At each step, test the value of slope, which is calculated as:

[(d/dx(r y 2 x 2 )] + d/dx(r x 2 y 2 )] = 0 dy/dx = - (2.x.r y 2 ) /(2.y.r x 2 ) But at the boundary between region 1 and region 2, dy/dx = -1 , so 2.x.r y 2 = 2.y.r x Move out of region 1 whenever 2.x.r y 2 ≥ 2.y.r x

y

2

2 8

The decision parameter (P1 k ) at region 1 at the mid point between the pixel Y k and Y k – 1 , which is given by P1 k = f(x k+1 , y k – ½ ) = r y 2 .(x k+1 ) 2 + r x 2 .(y k – ½ ) 2 - r x 2 .r y

2

if P1 k < 0 , then the next point is otherwise

(X k+1 , Y k )

the next point is (X k+1 , Y k –1) 9

Calculate the successive decision parameter for region – 1 using incremental calculation i.e. at next sampling position (X K+1 +1) i.e. (X k +2), the decision parameter is given by

P1 k+1 = f(X k+1 +1,Y k+1 – ½) = r y 2 (X k+1 +1) 2 + r x 2 (Y k+1 – ½) 2 - r x 2 r y

2

Hence P1 k+1 – P1 k = r y 2 [(X k+1 +1) 2 – (x k+1 ) 2 ] + r x 2 [(Y k+1 – ½) 2 -(y k – ½ ) 2 ] = 2.r y 2 .(X k +1)+r y 2 +r x 2 .[(Y k+1 2 – Y k 2 ) – (Y k+1 -Y k )] where Y k+1 is either y k or Y k – 1 depending on the sign of P1 k 10

When P1 k < 0, then next point is (X k+1 ,Y k ) since Y k+1 = Y k , So P1 k+1 = P1 k +2.r y 2 .x k+1 +r y When P1 k ≥ 0, then Y k+1 =Y k –1 and next point is (X k+1 ,Y k – 1) So P1 k+1 = P1 k +2.r y 2 .x k+1 +r y 2 +r x 2 [(Y k -1) 2 – Y k 2 ] - r x 2 [Y k -1 – Y k ] = P1 k +2.r y 2 .x k+1 +r y 2 – 2.r x 2 .Y k+1

2 11

In region – 1, the initial value of the decision parameter is Obtained as - At the start position(x 0 ,y 0 ) = (0,r y ) Then P1 0 = f(1, r y - ½)

= r y 2 +r x 2 (r y - ½) 2 – r x 2 .r y

2

r y 2 +r x 2 r y 2 – r x 2 r y + ¼.r x 2 - r x 2 r y = r y 2 – r x 2 r y + ¼.r x Hence P1 0 = r y 2 – r x 2 r y + ¼.r x

=

2

2

2 12

Over Region-2, sample at unit steps in the Negative y direction and the mid point The mid point is considered as horizontal pixels at each step. The decision parameter is given by P2 k = f(x k +½ , y k –1) = r y 2 (x k + ½ ) 2 + r x 2 (y k –1) 2 – r x 2 .r y

2 if P2 k > 0 , then the next point is
otherwise
(X k , Y k – 1)
the next point is (X k+1 , Y k –1)
13

The successive decision parameter is evaluated at next sampling step y k+1 -1, ie y k -2 P2 k+1 = f(x k+1 +½, y k+1 –1) = r y 2 (x k+1 +½ ) 2 +r x 2 (y k+1 –1) 2 –r x 2 .r y

2

Hence P2 k+1 – P2 k = r y 2 [(x k+1 +½) 2 – (x k +½) 2 ] +r x 2 [(y k+1 –1) 2 -(y k -1) 2 ] = r y 2 [(x k+1 +½) 2 –(x k +½) 2 ]+r x 2 [{(y k –1) –1} 2 -(y k -1) 2 ]

Finally

P2 k+1 = P2 k +r y 2 [2x k +2] – 2r x 2 (y k –1) + r x where x k+1 is either set to x k or x k+1 depending on the sign of P2 k

2 14

If P2 k > 0, then next point is (x k , y k –1) and P2 k+1 = P2 k – 2r x 2 (y k –1) + r y 2 (2x k +2) + r x = P2 k – 2r x 2 y k+1 + r x If P2 k ≤ 0, then next point is (x k+1 , y k –1) and P2 k+1 = P2 k +2[x k +1]r y 2 – 2r x 2 (y k –1) + r x = P2 k +2r y 2 x k+1 – 2r x 2 y k+1 + r x

2

2

2

2 15

The initial decision parameter in Region 2 is given by P2 0 = f (x 0 + ½ , y 0 – 1) = r y 2 (x 0 + ½ ) 2 + r x 2 (y 0 – 1) 2 – r x 2 r y

2 16

Ellipse Drawing algorithm

The steps are :-

1. Input (r x , r y ) and ellipse centre (α, β) and find the first point on the ellipse centered on origin as (X 0 ,Y 0 ) = (0,r y )

2. Calculate the initial value of decision parameter in region 1 as P1 0 = r y 2 – r x 2 r y + ¼ r x

3 At each x k position in region -1 at k = 0, perform the following test :

2 If P1 k < 0 , the next point is (x k+1 ,y k ) and
P1 k+1 = P1 k + 2r y 2 x k+1 + r y
otherwise , the next point (x k+1 , y k – 1) and
2
P1 k+1 = P1 k + 2r y 2 x k+1 + r y 2 – 2r x 2 y k+1
17

4 Calculate the initial decision parameter at Region 2 using the last point, calculated in region -1 as P2 0 = r y 2 (x 0 +½ ) 2 + r x 2 (y 0 – 1) 2 – r x 2 r y

5 At each y k position in Region 2, stating at k = 0, perform the following test :

2

If P2 k > 0 , the next point is (x k , y k - 1) and

P2 k+1 = P2 k -

2r x 2 y k+1 + r x

2

otherwise, the next point (x k+1 , y k – 1) and P2 k+1 = P2 k + 2r y 2 x k+1 + r x 2 – 2r x 2 y k+1
18

6 Determine the symmetry points in the other three quadrant

7 Move each calculated pixel positions (x, y) onto the elliptical path and plot the co ordinates values.

8 Repeat the steps until 2r y 2 x ≥ 2r x 2 y 19