using System; using System.Collections.Generic; namespace TMI_practicum { public static class SimpleAlgorithm { public static IEnumerable Solve(IList circles) { var intersections = new Stack(); for (int i = 0; i < circles.Count - 1; i++) { for (int j = i + 1; j < circles.Count; j++) { var c1 = circles[i]; var c2 = circles[j]; CalculateIntersection(intersections, c1, c2); } } return intersections; } private static void CalculateIntersection(Stack intersections, Circle c1, Circle c2) { double d = c1.Distance(c2); if (d > c1.R + c2.R || d < Math.Abs(c1.R - c2.R)) return; if (d == 0.0 && c1.R - c2.R == 0.0) throw new ArgumentException("Circles may not be coincident!"); double a = (c1.R * c1.R - c2.R * c2.R + d * d) / (2.0*d); double px = c1.X + a * (c2.X - c1.X) / d; double py = c1.Y + a * (c2.Y - c1.Y) / d; double htemp = c1.R * c1.R - a * a; if (htemp == 0) { intersections.Push(new Intersection(px, py)); } else { double h = Math.Sqrt(htemp); intersections.Push(new Intersection(px + h * (c2.Y - c1.Y) / d, py - h * (c2.X - c1.X) / d)); intersections.Push(new Intersection(px - h * (c2.Y - c1.Y) / d, py + h * (c2.X - c1.X) / d)); } } } }