using System.Collections.Generic;
public double X { get; set; }
public double Y { get; set; }
public Point(double x, double y)
public override string ToString() => $"({X}, {Y})";
public string Name { get; set; }
public Point Center { get; set; }
public double RotationAngle { get; private set; }
protected Shape(string name, double x, double y)
Center = new Point(x, y);
public void Move(double deltaX, double deltaY)
Center = new Point(Center.X + deltaX, Center.Y + deltaY);
public void Rotate(double angle)
RotationAngle = (RotationAngle + angle) % 360;
public abstract void Resize(double delta);
public abstract bool IsIntersect(Shape other);
public abstract override string ToString();
public double Radius { get; private set; }
public Circle(string name, double x, double y, double radius)
public override void Resize(double delta)
Console.WriteLine("Радиус не может быть меньше нуля.");
public override bool IsIntersect(Shape other)
if (other is Circle otherCircle)
double distance = Math.Sqrt(Math.Pow(Center.X - otherCircle.Center.X, 2) + Math.Pow(Center.Y - otherCircle.Center.Y, 2));
return distance <= Radius + otherCircle.Radius;
else if (other is Square otherSquare)
return IsCircleIntersectSquare(this, otherSquare);
public override string ToString()
return $"Круг: {Name}, Центр: {Center}, Радиус: {Radius}, Угол поворота: {RotationAngle}°";
private bool IsCircleIntersectSquare(Circle circle, Square square)
double halfSide = square.SideLength / 2;
double closestX = Math.Clamp(circle.Center.X, square.Center.X - halfSide, square.Center.X + halfSide);
double closestY = Math.Clamp(circle.Center.Y, square.Center.Y - halfSide, square.Center.Y + halfSide);
double distanceX = circle.Center.X - closestX;
double distanceY = circle.Center.Y - closestY;
double distanceSquared = distanceX * distanceX + distanceY * distanceY;
return distanceSquared <= (circle.Radius * circle.Radius);
public double SideLength { get; private set; }
public Square(string name, double x, double y, double sideLength)
public override void Resize(double delta)
Console.WriteLine("Длина стороны не может быть меньше нуля.");
public override bool IsIntersect(Shape other)
if (other is Square otherSquare)
double halfSide = SideLength / 2;
double halfOtherSide = otherSquare.SideLength / 2;
double thisLeft = Center.X - halfSide;
double thisRight = Center.X + halfSide;
double thisTop = Center.Y - halfSide;
double thisBottom = Center.Y + halfSide;
double otherLeft = otherSquare.Center.X - halfOtherSide;
double otherRight = otherSquare.Center.X + halfOtherSide;
double otherTop = otherSquare.Center.Y - halfOtherSide;
double otherBottom = otherSquare.Center.Y + halfOtherSide;
return !(thisLeft > otherRight || thisRight < otherLeft || thisTop > otherBottom || thisBottom < otherTop);
else if (other is Circle otherCircle)
return otherCircle.IsIntersect(this);
public override string ToString()
return $"Квадрат: {Name}, Центр: {Center}, Длина стороны: {SideLength}, Угол поворота: {RotationAngle}°";
public double Width { get; private set; }
public double Height { get; private set; }
public Rectangle(string name, double x, double y, double width, double height)
public override void Resize(double delta)
if (Width < 0) Width = 0;
if (Height < 0) Height = 0;
Console.WriteLine("Ширина или высота не могут быть меньше нуля.");
public override bool IsIntersect(Shape other)
public override string ToString()
return $"Прямоугольник: {Name}, Центр: {Center}, Ширина: {Width}, Высота: {Height}, Угол поворота: {RotationAngle}°";
static List<Shape> shapes = new List<Shape>();
Console.WriteLine("Меню:");
Console.WriteLine("1. Создать фигуру");
Console.WriteLine("2. Переместить фигуру");
Console.WriteLine("3. Изменить размер фигуры");
Console.WriteLine("4. Повернуть фигуру");
Console.WriteLine("5. Проверить пересечение двух фигур");
Console.WriteLine("6. Показать все фигуры");
Console.WriteLine("7. Выход");
Console.Write("Выберите действие: ");
string choice = Console.ReadLine();
Console.WriteLine("Неверный выбор, попробуйте еще раз.");
static void CreateShape()
Console.WriteLine("Выберите тип фигуры:");
Console.WriteLine("1. Круг");
Console.WriteLine("2. Квадрат");
Console.WriteLine("3. Прямоугольник");
Console.Write("Ваш выбор: ");
string choice = Console.ReadLine();
string name = Prompt("Введите имя фигуры: ");
double x = double.Parse(Prompt("Введите координату X центра: "));
double y = double.Parse(Prompt("Введите координату Y центра: "));
double radius = double.Parse(Prompt("Введите радиус круга: "));
shapes.Add(new Circle(name, x, y, radius));
double sideLength = double.Parse(Prompt("Введите длину стороны квадрата: "));
shapes.Add(new Square(name, x, y, sideLength));
double width = double.Parse(Prompt("Введите ширину прямоугольника: "));
double height = double.Parse(Prompt("Введите высоту прямоугольника: "));
shapes.Add(new Rectangle(name, x, y, width, height));
Console.WriteLine("Неверный выбор фигуры.");
string name = Prompt("Введите имя фигуры для перемещения: ");
Shape shape = FindShape(name);
double deltaX = double.Parse(Prompt("Введите смещение по X: "));
double deltaY = double.Parse(Prompt("Введите смещение по Y: "));
shape.Move(deltaX, deltaY);
Console.WriteLine("Фигура перемещена.");
Console.WriteLine("Фигура не найдена.");
static void ResizeShape()
string name = Prompt("Введите имя фигуры для изменения размера: ");
Shape shape = FindShape(name);
double delta = double.Parse(Prompt("Введите, на сколько изменить размер (радиус, длину или ширину): "));
Console.WriteLine("Размер фигуры изменен.");
Console.WriteLine("Фигура не найдена.");
static void RotateShape()
string name = Prompt("Введите имя фигуры для поворота: ");
Shape shape = FindShape(name);
double angle = double.Parse(Prompt("Введите угол поворота (в градусах): "));
Console.WriteLine("Фигура повернута.");
Console.WriteLine("Фигура не найдена.");
static void CheckIntersection()
string name1 = Prompt("Введите имя первой фигуры: ");
Shape shape1 = FindShape(name1);
string name2 = Prompt("Введите имя второй фигуры: ");
Shape shape2 = FindShape(name2);
if (shape1 != null && shape2 != null)
bool isIntersect = shape1.IsIntersect(shape2);
Console.WriteLine(isIntersect ? "Фигуры пересекаются." : "Фигуры не пересекаются.");
Console.WriteLine("Одна или обе фигуры не найдены.");
foreach (var shape in shapes)
Console.WriteLine(shape.ToString());
static string Prompt(string message)
return Console.ReadLine();
static Shape FindShape(string name)
return shapes.Find(s => s.Name == name);