# Drawing an Ellipse with Mid Point Ellipse Algorithm in C/C++

The theory for drawing Ellipse with Mid Point Algorithm is the same as that of Circle drawing. But the difference is that the Ellipse is divided into two regions because it has two radii. The regions are separated from each other at a point where the slope of the tangent line is –1. So we need to draw 2 regions in first quadrant and draw in other quadrant symmetrically.
The following section implements Mid – Point Ellipse Algorithm in C/C++. The source code is complied using gcc Compiler and Code::Blocks IDE. To print a pixel, SetPixel() function of windows.h is used.

Note: to run this code in your machine with Code::blocks IDE, add a link library libgdi32.a (it is usually inside MinGWlib )  in linker setting.

Source Code

Output SHARE Drawing an Ellipse with Mid Point Ellipse Algorithm in C/C++

### 2 Responses

1. Roger Gonsalves says:

With the above algorithm I am facing following problem.

When drawEllipse(200, 200, 0, 100); is called, it draws a vertical line. When drawEllipse(200, 200, 100, 0); is called it displays a single dot.
I was expecting it to draw a horizontal line.

2. Bibek123 says: 