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

This is example is very similar to Calculate the formula for a circle selected by the user in C# except it allows the user to pick 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 shown in the top picture above.


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 normal Graphics objects 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:

Rearrange the result to group related terms and get:

This is the desired format where:

Where:

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.