bool rectangleWithinRectangle_2dIntersection(Point2d pointRectangle_1_cornerMin, Point2d pointRectangle_1_cornerMax,
Point2d pointRectangle_2_cornerMin, Point2d pointRectangle_2_cornerMax)
{
// RETURN true IF ONE RECTANGLE LIES WITHIN ANOTHER RECTANGLE
bool returnValue = false;
// IF NOT POSITIVE THEN THERE IS AN INTERSECTION
if ((pointRectangle_2_cornerMin.x - pointRectangle_1_cornerMax.x) <= 0.0)
{
if ((pointRectangle_2_cornerMin.y - pointRectangle_1_cornerMax.y) <= 0.0)
{
if ((pointRectangle_2_cornerMax.x - pointRectangle_1_cornerMin.x) <= 0.0)
{
if ((pointRectangle_2_cornerMax.y - pointRectangle_1_cornerMin.y) <= 0.0)
{
return true;
}
}
}
}
return returnValue;
}
Rectangle within Rectangle
I have the following code to tell me if all the sides of one rectangle intersect with all the sides of another rectangle. But is there a way to know if one rectangle lies completely within another without touching any of its sides.
Off the top of my head:
// returns true if rectangle 1 is inside rectangle 2bool RectangleInsideRectangle(Point2d pointRectangle_1_cornerMin, Point2d pointRectangle_1_cornerMax, Point2d pointRectangle_2_cornerMin, Point2d pointRectangle_2_cornerMax){ return ( ( pointRectangle_1_cornerMax.x < pointRectangle_2_cornerMax.x ) && ( pointRectangle_1_cornerMax.y < pointRectangle_2_cornerMax.y ) && ( pointRectangle_1_cornerMin.x > pointRectangle_2_cornerMin.x ) && ( pointRectangle_1_cornerMin.y > pointRectangle_2_cornerMin.y ) );}
No way. Is that really all you need to do? I was thinking like convex hulls and stuff like that.
Please just one more. I don''t want any code, but could someone tell me how to tell if a circle is inside a rectangle, without touching any of the sides of the rectangle?
Put a rectangle around the centre of the circle with sides the same length of the diameter of the circle and do normal rect to rect checks.
The above method (and all the methods so far) have assumed the rectangle is axis-aligned though, I notice.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
The above method (and all the methods so far) have assumed the rectangle is axis-aligned though, I notice.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement