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




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

You may also like...

2 Responses

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

    Could you please explain this?

  2. Bibek123 says:

    Actually this program fails to draw ellipse when Ry = 0. The program starts drawing ellipse from (0, Ry) that is from point on y axis and steps clockwise along the elliptical path in the first quadrant. Starting to draw ellipse from point (0, Ry) is the reason why you cannot draw horizontal line. If you start drawing ellipse from (Rx, 0) you can draw horizontal line but again you cannot draw vertical line.
    Initially when you supply Rx = some value with Ry = 0, the value of both Px and Py becomes zero as a result region 1 is not drawn and also y becomes zero and region 2 is not drawn. Only a point on the origin is drawn that's why you get a point. But if you supply Rx = 0 and Ry = some value. Region 1 is still not drawn but region 2 is drawn that's why you get vertical line.

Leave a Reply

Your email address will not be published. Required fields are marked *