Sei sulla pagina 1di 19

Ellipse Drawing Algorithm

Using Ellipse equation


Using Mid point Ellipse Algorithm

Ellipse Drawing Algorithm

The equation of an ellipse can be written as


[(x )/rx]2 + [(y - )/ry] 2 = 1 -------------------(1)

Using polar co ordinates (r, ) :


x = +rx.cos ---------------- (1)
y = + ry.sin ---------------- (2)

Symmetrical point calculations:(- x, y)

(x, y)

ry
rx

(-x, -y)

(x, -y)

y
Slope = -1
Region -1

ry
Region - 2
rx

Midpoint Ellipse Drawing algorithm


Let us define an ellipse function with (, ) = (0,0), as
f(x, y) = (x/rx)2 + (y/ry)2 1
= x2.ry2 + y2.rx2 rx2.ry2
Let (x1, y1) be a point on the ellipse, then
f (x1, y1) = 0
on the ellipse boundary
<0
inside the ellipse boundary
>0
outside the ellipse boundary
So, we may conclude that the ellipse function may be
served as decision parameter
Contd.
6

(Xk,Yk)

Yk

(Xk+1,Yk+1)
Either
Xk+1

(Yk)

or
(Yk-1)

Yk 1/2

Yk - 1

Xk

Xk+1

Starting at (0, ry), 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(ry2x2)] + d/dx(rx2y2)] = 0
dy/dx = - (2.x.ry2) /(2.y.rx2)
But at the boundary between region 1 and region 2,
dy/dx = -1 , so 2.x.ry2 = 2.y.rx2
Move out of region 1 whenever 2.x.ry2 2.y.rx2

The decision parameter (P1k) at region 1 at the mid point


between the pixel Yk and Yk 1 , which is given by
P1k = f(xk+1, yk )
= ry2.(xk+1)2 + rx2.(yk )2 - rx2.ry2
if P1k < 0 , then the next point is (Xk+1, Yk)
otherwise
the next point is (Xk+1, Yk1)

Calculate the successive decision parameter for region 1


using incremental calculation i.e. at next sampling position
(XK+1+1) i.e. (Xk+2), the decision parameter is given by
P1k+1 = f(Xk+1+1,Yk+1 )
= ry2(X k+1+1)2 + rx2(Yk+1 ) 2 - rx2ry2
Hence
P1k+1 P1k= ry2[(Xk+1 +1)2 (xk+1)2] + rx2[(Yk+1 )2-(yk )2]
= 2.ry2.(Xk+1)+ry2+rx2.[(Yk+12 Yk2) (Yk+1-Yk)]
where Yk+1 is either yk or Yk 1 depending on the sign of P1k

10

When P1k < 0, then next point is (Xk+1,Yk) since Yk+1 = Yk ,


So P1k+1 = P1k+2.ry2.xk+1+ry2
When P1k 0, then Yk+1 =Yk 1 and next point is (Xk+1,Yk 1)
So P1k+1 = P1k+2.ry2.xk+1+ry2 +rx2[(Yk-1)2 Yk2] - rx2[Yk-1 Yk]
= P1k+2.ry2.xk+1 +ry2 2.rx2.Yk+1

11

In region 1, the initial value of the decision parameter is


Obtained as At the start position(x0,y0) = (0,ry)
Then P10 = f(1, ry - )
= ry2 +rx2(ry- )2 rx2.ry2
= ry2+rx2ry2 rx2 ry + .rx2 - rx2ry2
= ry2 rx2 ry + .rx2
Hence P10 = ry2 rx2 ry + .rx2

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
P2k= f(xk+ , yk 1)
= ry2 (xk+ )2+ rx2(yk 1)2 rx2.ry2
if P2k > 0 , then the next point is (Xk, Yk 1)
otherwise
the next point is (Xk+1, Yk1)

13

The successive decision parameter is evaluated at next


sampling step yk+1 -1, ie yk -2
P2k+1 = f(xk+1+, yk+11)
= ry2(xk+1+ )2+rx2(yk+11)2 rx2.ry2
Hence
P2k+1 P2k = ry2[(xk+1+)2 (xk+)2] +rx2[(yk+11)2-(yk-1)2]
= ry2[(xk+1+)2(xk+)2]+rx2[{(yk1) 1}2-(yk-1)2]
Finally
P2k+1 = P2k+ry2[2xk+2] 2rx2(yk1) + rx2
where xk+1 is either set to xk or xk+1 depending on the sign of
P2k

14

If P2k > 0, then next point is (xk, yk 1) and


P2k+1 = P2k 2rx2(yk 1) + ry2(2xk +2) + rx2
= P2k 2rx2yk+1+ rx2
If P2k 0, then next point is (xk+1, yk 1) and
P2k+1 = P2k+2[xk+1]ry2 2rx2(yk 1) + rx2
= P2k+2ry2xk+1 2rx2yk+1 + rx2

15

The initial decision parameter in Region 2 is given by


P20 = f (x0+ , y0 1)
= ry2(x0 + )2 + rx2(y0 1)2 rx2 ry2

16

Ellipse Drawing algorithm


The steps are :1.

2.

Input (rx, ry) and ellipse centre (, ) and find the first
point on the ellipse centered on origin as (X0,Y0) =
(0,ry)
Calculate the initial value of decision parameter in
region 1 as P10 = ry2 rx2ry + rx2
At each xk position in region -1 at k = 0, perform the
following test :
If P1k < 0 , the next point is (xk+1,yk) and
P1k+1 = P1k + 2ry2xk+1 + ry2
otherwise , the next point (xk+1, yk 1) and
P1k+1 = P1k + 2ry2xk+1 + ry2 2rx2yk+1
17

Calculate the initial decision parameter at Region 2


using the last point, calculated in region -1 as
P20= ry2(x0+ )2 + rx2(y0 1)2 rx2 ry2
At each yk position in Region 2, stating at k = 0,
perform the following test :
If P2k > 0 , the next point is (xk, yk- 1) and
P2k+1 = P2k - 2rx2yk+1 + rx2
otherwise, the next point (xk+1, yk 1) and
P2k+1 = P2k + 2ry2xk+1 + rx2 2rx2yk+1

18

6
7
8

Determine the symmetry points in the other three


quadrant
Move each calculated pixel positions (x, y) onto the
elliptical path and plot the co ordinates values.
Repeat the steps until 2ry2x 2rx2y

19

Potrebbero piacerti anche