private IVector2[] GetCircleCenters(IVector2 p1, IVector2 p2, double radius) { try { if (radius < 0) { throw new ArgumentException("Negative radius."); } if (radius == 0) { if (p1 == p2) { return new[] { p1 } } ; else { throw new InvalidOperationException("No circles."); } } if (p1 == p2) { throw new InvalidOperationException("Infinite number of circles."); } double sqDistance = Math.Pow(p1.DistanceTo(p2), 2); double sqDiameter = 4 * radius * radius; if (sqDistance > sqDiameter) { throw new InvalidOperationException("Points are too far apart."); } var midPoint = new Vector2((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2); if (sqDistance == sqDiameter) { return new[] { midPoint } } ; double d = Math.Sqrt(radius * radius - sqDistance / 4); double distance = Math.Sqrt(sqDistance); double ox = d * (p2.X - p1.X) / distance, oy = d * (p2.Y - p1.Y) / distance; return(new[] { new Vector2(midPoint.X - oy, midPoint.Y + ox), new Vector2(midPoint.X + oy, midPoint.Y - ox) }); } catch (Exception) { throw; } }