Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Computer Graphics Lab Experiment No: - 04

Aim: Implement Midpoint Ellipse Line Drawing algorithm

Midpoint Ellipse Line Algorithm

The midpoint ellipse algorithm efficiently draws ellipses in computer graphics by iteratively determining
boundary points. It uses symmetry properties to calculate points within the ellipse's quarter and mirrors
them for the other quarters. With initial parameters and a decision parameter, the algorithm adjusts x
and y coordinates based on conditions, generating accurate ellipse representations on pixel grids.
While newer methods exist, the midpoint algorithm remains a foundational technique for ellipse
rendering.

Algorithm

Step 1: Start

Step 2: Declare rx , ry , x , y , m , dx , dy , P , P2.

Step 3: Initialize initial point of region1 as

x=0 , y = ry

Step 4: Calculate P= ry2 + rx2 / 4 - ry rx2

dx = 2 ry2 x

dy = 2 rx2 y

Step 5: Update values of dx and dy after each iteration.

Step 6: Repeat steps while (dx < dy):

Plot (x,y)

if(P < 0)

Update x = x+1 ;

P += ry2 [2x + 3 ]

Else

Update x = x + 1

y= y - 1

Step 7: When dx ≥ dy, plot region 2:

Step 8: Calculate P2 = ry2 ( x+1 / 2)2 + rx2 (y -1)2- rx2ry2

1
TSEC Batch:- S1-2 AI&DS Name:- AARYA GURAV Roll No:-33
Computer Graphics Lab Experiment No: - 04

Aim: Implement Midpoint Ellipse Line Drawing algorithm

Step 9: Repeat till (y > 0)

If (P2 > 0)

Update y = y-1 (x will remain same)

P2 = P2 -2 y rx2 + rx2

else

x = x+1

y = y-1

P2= P2+ 2 ry2 [2x] -2 y rx2 + rx2

Step 10: End

Code

2
TSEC Batch:- S1-2 AI&DS Name:- AARYA GURAV Roll No:-33
Computer Graphics Lab Experiment No: - 04

Aim: Implement Midpoint Ellipse Line Drawing algorithm

3
TSEC Batch:- S1-2 AI&DS Name:- AARYA GURAV Roll No:-33
Computer Graphics Lab Experiment No: - 04

Aim: Implement Midpoint Ellipse Line Drawing algorithm

Output

Conclusion: LO is mapped

4
TSEC Batch:- S1-2 AI&DS Name:- AARYA GURAV Roll No:-33

You might also like