i am an industrial engineer so you know my coding isn`t that good thats why i need your help. my problem is that i need to know first the area of intersection between two rectangles so that to check if there is overlapping occurring, this has to be done for 6 rectangles i need to check if they overlap. my second problem is that i have 6 rectangles inside a large warehouse with defined boundaries, i want to maximize the utilized area. how can i write a code to do so. i have used the bellow code which is online but i dont know how to use it to check for the 6 rectangles.
# Python program to check if rectangles overlap
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
# Returns true if two rectangles(l1, r1)
# and (l2, r2) overlap
def doOverlap(l1, r1, l2, r2):
# If one rectangle is on left side of other
if(l1.x >= r2.x or l2.x >= r1.x):
return False
# If one rectangle is above other
if(l1.y <= r2.y or l2.y <= r1.y):
return False
return True
# Driver Code
if __name__ == "__main__":
l1 = Point(0, 10)
r1 = Point(10, 0)
l2 = Point(5, 5)
r2 = Point(15, 0)
if(doOverlap(l1, r1, l2, r2)):
print("Rectangles Overlap")
else:
print("Rectangles Don't Overlap")
this may help you getting started:
a
Rectangle
is definded here with abase_point
(which is the lower left point) and asize
(how much it extends inx
andy
).rectangles overlap if they do overlap on the x and on the y axis. the code is probably overly designed... you may want to simplify it to suit your needs. but the way it is - i think - it showcases the idea well.
in order to find if more rectangles overlap you have to compare all of them agains one another...