Calculate the formula for an ellipse selected by the user in C#

Calculate the formula for an ellipse

This is example is very similar to Calculate the formula for a circle selected by the user in C# except it shows how to calculate the formula for an ellipse instead of a circle. See that post or download the example program for information about how the program lets the user select the shape and how the program draws the selected shape.

The big difference between the two examples is that this example uses the equation for an ellipse not a circle. The picture on the right shows the geometry for an ellipse with major and minor axes parallel to the X and Y axes.

After the user selects an ellipse, the program averages the minimum and maximum X and Y coordinates to find the center of the ellipse (Dx, Dy). It then divides the ellipse’s width and height by two to get the parameters Rx and Ry. It can then display the equation.

The equations on the left show how you can convert the normal form of the equation into a function that gives y in terms of x. As is the case with a circle, the result includes two equations that use positive and negative square roots.

Like the previous example that draws circles, this example verifies the function by using the Graphics object’s FillEllipse method to fill the ellipse and then drawing the points on the ellipse calculated by using the function.

Any conic section (circle, ellipse, parabola, or hyperbola) can be represented as an equation of the form:

Where A, B, C, D, E, and F are constants. To find this form of an equation for an ellipse, start with the following equation:

Multiply this out to get:

If you rearrange the result to group related terms, you get:

This is the desired format:


Download Example   Follow me on Twitter   RSS feed   Donate

This entry was posted in algorithms, geometry, graphics, mathematics and tagged , , , , , , , , , , . Bookmark the permalink.

2 Responses to Calculate the formula for an ellipse selected by the user in C#

  1. Pingback: See where two ellipses intersect in C#, Part 1 -

Leave a Reply

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