Checking overlap and tangent of 5 rectangles

22 Views Asked by At

I wanna draw a rulbase architectural paln, for Simplifying the problem i start with rectangle, now i need to know How to check that 5 or more rectangles don't overlap and be tangent to each other? i don't wanna use rectangle paching way! I try to use matrix(as i saw in tetris game's code), with inserx smalls matrix into a big one as a big empty space so the cell has 0 value are empty and the others had filled.(for avoiding overlap)

import numpy as np

class MatrixModifier:
    def __init__(self, matrix):
        self.matrix = matrix

    def insert_matrix(self, smaller_matrix, row_start, col_start):
        if row_start < 0 or col_start < 0:
            print("Invalid starting position.")
            return
        
        if row_start + smaller_matrix.shape[0] > self.matrix.shape[0] or \
           col_start + smaller_matrix.shape[1] > self.matrix.shape[1]:
            print("Smaller matrix doesn't fit at the specified position.")
            return
        
        self.matrix[row_start:row_start + smaller_matrix.shape[0],
                    col_start:col_start + smaller_matrix.shape[1]] = smaller_matrix

# Example usage

larger_matrix = np.array([[0, 0, 0],
                          [0, 0, 0],
                          [0, 0, 0]])

smaller_matrix = np.array([[1, 1],
                           [1, 1]])

modifier = MatrixModifier(larger_matrix)
modifier.insert_matrix(smaller_matrix, row_start=1, col_start=1)

print("Modified Matrix:")
print(modifier.matrix)

0

There are 0 best solutions below