We are making a program that determines whether squares overlap each other by receiving rectangular information (x-pos
, y-pos
, height
.
All inputs are int
type, and only rectangles will be entered.
I tried to make it in my own way, but it didn't work. Can anyone briefly explain what to do?
algorithm c++ geometry overlap rectangle
if (RectA.Left < RectB.Right && RectA.Right > RectB.Left &&
RectA.Top > RectB.Bottom && RectA.Bottom < RectB.Top )
Or if you use Cartesion coordinate
,
if (RectA.X1 < RectB.X2 && RectA.X2 > RectB.X1 &&
RectA.Y1 < RectB.Y2 && RectA.Y2 > RectB.Y1)
You must inspect with .
Let's divide the types
For Rect A, and Rect B, if either of the following four cases is true
, the two squares cannot overlap.
If (Cond1 Or Cond2 Or Cond3 Or Cond4) == true
the two squares can never overlap
If False, overlap.
Expressing this as a formula
© 2024 OneMinuteCode. All rights reserved.