I'm programming a game, and i need to detect intersections between two CGRects. To do this, i've no problem. I do like this :
CGRect rect1 = CGRectMake (x1, y1, a1, b1);
CGRect rect2 = CGRectMake (x2, y2, a2, b2);
if (CGRectIntersectsRect(rect1, rect2))
{
//do some stuff...
}
So i've no problem. But i would if it was possible to know the precise point of intersection from this two CGRect ? And if it's possible, how to ?
Thanks !
Use the CGRectIntersection()
function to get the common part of two intersecting rectangles. From the result of that function call, you can calculate the edges of the rectangle using the CGRectGet[Max|Min][X|Y]()
functions.