[C# Helper]
Index Books FAQ Contact About Rod
[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]

[Beginning Software Engineering]

[C# 5.0 Programmer's Reference]

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

Title: Find circles that are tangent to three given circles (Apollonius' Problem) in C#

[Find circles that are tangent to three given circles (Apollonius' Problem) in C#]

Given three objects that can be a point, line, or circle, you can try to draw circles that are tangent to each. The case using three circles is called Apollonius' Problem. Originally these problems were studied by Euclid (c. 300 BC) and Apollonius of Perga (c. 262 BC - c. 190 BC) and they were solved geometrically with straight edge and compass.

This example solves Apollonius' Problem by finding solutions to the three following equations algebraically.

(X - X1)2 + (Y - Y1)2 = (R ± R1)2 (X - X2)2 + (Y - Y2)2 = (R ± R2)2 (X - X3)2 + (Y - Y3)2 = (R ± R3)2

Unfortunately solving the equations requires dividing by some terms that may be zero and in those cases the solution doesn't work. In some cases that's because some solutions are degenerate. For example, suppose the three circles have the same radii and are all tangent to the X axis. Then two of the tangent "circles" are actually lines, one along the X axis and one parallel to the X axis on the other side of the circles.

In other cases the division by zero seems to be caused by the method for solving the equations and real solutions do exist. This is a tricky problem and I haven't yet found a solution. If you figure out how to solve these equations without these problems, please let me know.

For more discussion of the problem and how to solve the equations, see:

See the code for additional details about how this program works.

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

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