# Is rectange fully inside another rectangles

• 02-04-2003
Roaring_Tiger
Is rectange fully inside another rectangles
I have two rectagle. User inputs the co-ordiates of both the rectagle.

Let us say, co-ordinates of big rectangle are

Bx1,By1,Bx2,By2,Bx3,By3,Bx4 and By4

and co-ordinates of small rectangle are

Sx1,Sy1,Sx2,Sy2,Sx3,Sy3,Sx4 and Sy4

Can anybody help me writing "C" program to check, whether small rectagle is fully inside the big rectangle?

It is simple if you use your own number of "if" and "else". I am looking at program that use minimum number of "if" condition.

Assume that, x increses from left to right and y increases from botton to top.

Thanks,
tiger
• 02-05-2003
Magos
First, you only need two points to define a rectangle (unless it's angled). Take a look at it and you'll see that some of the points (corners) in the rectangle have the same X or Y coordinates.
Code:

(X1, Y1)
¤-----------------+
|                |
|                |
|                |
|                |
|                |
|                |
+-----------------¤
(X2, Y2)

Assuming Point 1 is always the upper left corner, and Point 2 is always the bottom right corner, this will check if Rectangle 1 is completely inside Rectangle 2:
Code:

if((R1.X1 >= R2.X1) && (R1.X2 <= R2.X2))
{
if((R1.Y1 >= R2.Y1) && (R1.Y2 <= R2.Y2))
{
...
}
}