
Overlapping rectangles 
Rick
Member #3,572
June 2003

There was a simple way to find the overlapping rectangle after you found that 2 rectangles have collided using min max functions but I can't remember it. Anyone know what that is? ======================================================== 
Kris Asick
Member #1,424
July 2001

if (rect1.x1 > rect2.x1) finalrect.x1 = rect1.x1; else finalrect.x1 = rect2.x1; if (rect1.x2 < rect2.x2) finalrect.x2 = rect1.x2; else finalrect.x2 = rect2.x2; if (rect1.y1 > rect2.y1) finalrect.y1 = rect1.y1; else finalrect.y1 = rect2.y1; if (rect1.y2 < rect2.y2) finalrect.y2 = rect1.y2; else finalrect.y2 = rect2.y2; That's a guess BTW, that I came up with moments after reading your post... I could be totally wrong about that.  Kris Asick (Gemini)  Kris Asick (Gemini) 
HardTranceFan
Member #7,317
June 2006

[edit] Something like this? // // rect[n].<LeftRightTopBottom> // n = rectangle number  0 for first rectangle, 1 for second rectangle or 2 for overlap // Left = left edge // Right = right edge // Top = top edge // Bottom = bottom edge // rect[2].Left = max(rect[0].Left, rect[1].Left) rect[2].Right = min(rect[0].Right, rect[1].Right) rect[2].Top = max(rect[0].Top, rect[1].Top) rect[2].Bottom = min(rect[0].Bottom, rect[1].Bottom)
[edit] finalrect.y2 = (rect1.y2 < rect2.y2) ? rect1.y2 : rect2.y2; as an alternative to : if (rect1.y2 < rect2.y2) finalrect.y2 = rect1.y2; else finalrect.y2 = rect2.y2; [/edit]  
