Computer Graphics Lec_3

19
1 Ellipse Drawing Algorithm Using Ellipse equation Using Mid point Ellipse Algorithm

Transcript of Computer Graphics Lec_3

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 1/19

1

Ellipse Drawing Algorithm

Using Ellipse equation

Using Mid point Ellipse Algorithm

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 2/19

2

Ellipse Drawing Algorithm

The equation of an ellipse can be written as

[(x – α)/r x]2 + [(y - β)/r y]

2 = 1 -------------------(1)

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 3/19

3

Using polar co –ordinates (r, θ) :

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

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

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 4/19

4

r x

r y(x, y)

(x, -y)

(- x, y)

(-x, -y)

Symmetrical point calculations:-

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 5/19

5

r x

r yRegion -1

Region - 2

Slope = -1

x

y

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 6/19

6

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

= x2.r y2 + y2.r x

2 – r x2.r y

2

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….

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 7/19

7

(Xk,Yk)

(Xk+1,Yk+1)

Either 

(Yk-1)(Yk)

or 

Xk+1

Yk

Yk – 1/2

Yk - 1

Xk Xk+1

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 8/19

8

Starting at (0, r y), take unit steps in X-direction until reachthe 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 y2x2)] + d/dx(r x

2y2)] = 0

dy/dx = - (2.x.r y2) /(2.y.r x

2)

But at the boundary between region 1 and region 2,

dy/dx = -1 , so 2.x.r y2 = 2.y.r x

2

Move out of region 1 whenever 2.x.r y2 ≥ 2.y.r x

2

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 9/19

9

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

between the pixel Yk and Yk – 1 , which is given byP1k = f(xk+1, yk – ½ )

= r y2.(xk+1)

2 + r x2.(yk – ½ )2 - r x

2.r y2

if P1k < 0 , then the next point is (Xk+1, Yk)otherwise

the next point is (Xk+1, Yk –1)

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 10/19

10

Calculate the successive decision parameter for region – 1using incremental calculation i.e. at next sampling position(X

K+1

+1) i.e. (Xk

+2), the decision parameter is given by

P1k+1 = f(Xk+1+1,Yk+1 – ½)

= r y2(X k+1+1)2 + r x

2(Yk+1 – ½) 2 - r x2r y

2

Hence

P1k+1 – P1k= r y2[(Xk+1 +1)2 – (xk+1)

2] + r x2[(Yk+1 – ½)2-(yk – ½ )2]

= 2.r y2.(Xk+1)+r y

2+r x2.[(Yk+1

2 – Yk2) – (Yk+1-Yk)]

where Yk+1 is either yk or Yk – 1 depending on the sign of P1k

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 11/19

11

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

So P1k+1 = P1k+2.r y2.xk+1+r y2

When P1k ≥ 0, then Yk+1 =Yk –1 and next point is (Xk+1,Yk – 1)

So P1k+1 = P1k+2.r y2.xk+1+r y

2 +r x2[(Yk-1)2 – Yk

2] - r x2[Yk- 1 – Yk]

= P1k+2.r y2.xk+1 +r y

2 – 2.r x2.Yk+1

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 12/19

12

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

Obtained as -

 At the start position(x0,y0) = (0,r y)

Then P10 = f(1, r y - ½)

= r y2 +r x

2(r y- ½)2 – r x2.r y

2

= r y2+r x

2r y2 – r x

2 r y + ¼.r x2 - r x

2r y2

= r y2 – r x

2 r y + ¼.r x2

Hence P10 = r y2 – r x

2 r y + ¼.r x2

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 13/19

13

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)= r y

2 (xk+ ½ )2+ r x2(yk –1)2 – r x

2.r y2

if P2k > 0 , then the next point is (Xk, Yk – 1)

otherwise

the next point is (Xk+1, Yk –1)

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 14/19

14

The successive decision parameter is evaluated at next

sampling step yk+1 -1, ie yk -2

P2k+1 = f(xk+1+½, yk+1 –1)= r y

2(xk+1+½ )2+r x2(yk+1 –1)2 –r x

2.r y2

Hence

P2k+1 – P2k = r y2[(xk+1+½)2 – (xk+½)2] +r x

2[(yk+1 –1)2-(yk-1)2]

= r y2

[(xk+1+½)

2

 –(xk+½)

2

]+r x2

[{(yk –1) –1}

2

-(yk-1)

2

]Finally

P2k+1 = P2k+r y2[2xk+2] – 2r  x

2(yk –1) + r x2

where xk+1 is either set to xk or xk+1 depending on the sign of 

P2k

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 15/19

15

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

P2k+1 = P2k – 2r x2(yk –1) + r y2(2xk +2) + r x2

= P2k – 2r x2yk+1+ r x

2

If P2k ≤ 0, then next point is (xk+1, yk –1) and

P2k+1 = P2k+2[xk+1]r y2 – 2r x

2(yk –1) + r x2

= P2k+2r y2

xk+1 – 2r x2

yk+1 + r x2

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 16/19

16

The initial decision parameter in Region 2 is given byP20 = f (x0+ ½ , y0 – 1)

= r y2(x0 + ½ )2 + r x

2(y0 – 1)2 – r x2 r y

2

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 17/19

17

Ellipse Drawing algorithm

The steps are :-

1. Input (r x, r y) and ellipse centre (α, β) and find the firstpoint on the ellipse centered on origin as (X0,Y0) =

(0,r y)

2. Calculate the initial value of decision parameter in

region 1 as P10 = r y2 – r x

2r y + ¼ r x2

3 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 + 2r y2xk+1 + r y

2

otherwise , the next point (xk+1, yk – 1) andP1k+1 = P1k + 2r y

2xk+1 + r y2 – 2r x

2yk+1

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 18/19

18

4 Calculate the initial decision parameter at Region 2

using the last point, calculated in region -1 asP20= r y

2(x0+½ )2 + r x2(y0 – 1)2 – r x

2 r y2

5  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) andP2k+1 = P2k - 2r x

2yk+1 + r x2

otherwise, the next point (xk+1, yk – 1) and

P2k+1 = P2k + 2r y2xk+1 + r x

2 – 2r x2yk+1

8/10/2019 Computer Graphics Lec_3

http://slidepdf.com/reader/full/computer-graphics-lec3 19/19

19

6 Determine the symmetry points in the other three

quadrant

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

8 Repeat the steps until 2r y2x ≥ 2r x

2y