[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: See where two conic sections intersect in C#

See where two conic sections intersect

This example uses techniques demonstrated in several earlier posts to let you see where two conic sections intersect.

To use the example, click the left mouse button five times each to select one conic section> Then click the right mouse button five times to select the second conic section. The program then uses the techniques demonstrated by the example Select a conic section in C# to find the equations for the conic sections that satisfy the points selected by the user. (As in that example, this program doesn't worry about weird cases such as when the user selects points that all have the same X coordinate.)

After a conic section has been selected, the program uses the techniques demonstrated by the example Draw a conic section from its polynomial equation in C# to draw it.

After the user has selected both conic sections, the program uses the techniques demonstrated by the example See where two ellipses intersect in C#, Part 4 to find the points of intersection between the two conic sections.

This code still sometimes has problems finding all of the possible zeros for the difference equations. You can work on making the code more robust if you like, but this is good enough to show the general technique.

Taken all together, this example is fairly complicated. It uses these techniques:

  • It uses Gaussian elimination (twice) to find the equation for the conic section that satisfies five points selected by the user.
  • It examines several cases of positive and negative roots to draw the equations of the conic sections.
  • It calculates the difference equations between the equations of the two conic sections.
  • It uses binary division (or Newton's method) to find roots of the difference equations.

Individually the steps are non-trivial but manageable. When you put them together, you get this fairly complicated program for finding conic section intersections.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.