Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created December 20, 2017 05:34
Show Gist options
  • Save unilecs/a22b6a14389d90aa95e29e6121e2dedb to your computer and use it in GitHub Desktop.
Save unilecs/a22b6a14389d90aa95e29e6121e2dedb to your computer and use it in GitHub Desktop.
Задача 54: Окружности
using System;
public class Program
{
public static int GetCircleIntersection(int x1, int y1, int r1, int x2, int y2, int r2)
{
// по умолчанию будем считать, что наши окружности пересекаются
int result = 2;
// квадрат расстояния между центрами окружностей
int dist = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
// частный случай, окружности совпадают
if ((x1 == x2) && (y1 == y2) && (r1 == r2)) return -1;
// окружности имеют внещнюю точку касания
if ((r1 + r2) * (r1 + r2) == dist) return 1;
// окружности имеют внутреннюю точку касания
if ((r1 - r2) * (r1 - r2) == dist) return 1;
// окружности не имеют пересечений
if ((r1 + r2) * (r1 + r2) < dist) return 0;
if ((r1 - r2) * (r1 - r2) > dist) return 0;
return result;
}
public static void Main()
{
Console.WriteLine("@UniLecs");
Console.WriteLine(GetCircleIntersection(0, 0, 5, 5, 0, 5)); // 2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment