I'm trying to intersect two rectangles but I have no clue on how to do it. I've done two classes which are point and color and they work fine. Now I'm trying to get this intersection done. That's the rectangle class i've wrote
class Rectangle:
def __init__(self,Point,width,lenght,Color):
self.x = Point.x
self.y = Point.y
self.x1 = self.x + lenght
self.y1 = self.y + width
self.r = Color.r
self.g = Color.g
self.b = Color.b
self.w = width
self.l = lenght
And as far as I've tried the intersection function it didn't work. I tried something like this
def inter(self,r):
if ((self.x > r.x1) or (self.x1 < r.x) or (self.y > r.y1) or (self.y1 < r.y)):
return None
else:
return Rectangle(Point(x,y),w,h,Color.mix(self,r))
Where i defined the .mix
function into the color class. The input of this function is the existent rectangle self
and another one rectangle that is r
As an example i can put this
A is the rectangle that starts at (100,40), width 70, lenght 40 and color (200,200,200) and
B is the rectangle that starts at (120,90), width 40, lenght 60 and color (100,100,100)
you will get a rectangle starting at (120,90), width 20, lenght 20 and color (150,150,150)
Keep in mind that the axis that I'm working on are placed like this
0 - - - - - X
-
-
Y
And i have to do everything using only standar libraries