x1 = int(input("x1 = "))
y1 = x1
x2 = int(input("x2 = "))
y2 = x2
a1 = int(input("dlina = "))
b1 = a1
a2 = int(input("dlina_2 = "))
b2 = a2
if ((x1<=x2 and x2<=x1+a1) and (y1<=y2 and y2<=y1+b1) ):
print("Пересекаются")
else:
print("не пересекаются")
class Rectangle(object):
def __init__(self, x, y, w, h):
self.x1 = x
self.x2 = x + w
self.y1 = y
self.y2 = y + h
def is_involved(self, other):
if all([other.x1 <= self.x1,
other.y1 <= self.y1,
other.x2 >= self.x2,
other.y2 >= self.y2]):
return True
return False
def is_intersected(self, other):
if any([all([other.x1 <= self.x1 <= other.x2, other.y1 <= self.y1 <= other.y2]),
all([other.x1 <= self.x2 <= other.x2, other.y1 <= self.y1 <= other.y2]),
all([other.x1 <= self.x1 <= other.x2, other.y1 <= self.y2 <= other.y2]),
all([other.x1 <= self.x2 <= other.x2, other.y1 <= self.y2 <= other.y2])]):
return True
return False
print("Rectangle 1:")
rect1 = Rectangle(int(input("x = ")), int(input("y = ")), int(input("width = ")), int(input("height = ")))
print()
print("Rectangle 2:")
rect2 = Rectangle(int(input("x = ")), int(input("y = ")), int(input("width = ")), int(input("height = ")))
print()
print('а) Принадлежат ли все точки первого прямоугольника второму:')
print(rect2.is_involved(rect1))
print('б) Принадлежат ли все точки одного из прямоугольников другому:')
print(rect2.is_involved(rect1) or rect1.is_involved(rect2))
print('в)* Пересекаются ли эти прямоугольники:')
print(rect2.is_intersected(rect1) or rect1.is_intersected(rect2))