0
$\begingroup$

I have two intersecting rectangles, A and B, with known dimensions and locations. In my example, Rectangle B's top-left point is on the origin. I get the intersecting rectangle, I, and its dimensions and location. With this information how can I get the intersecting rectangle's top-left coordinate relative to rectangle A's top-left? Is it possible to get a single formula for I_X and for I_Y?

Example Image

$\endgroup$
  • $\begingroup$ You have the coordinates of the top left point of $A,$ is that right? And the top-left coordinates of $B$ are $(0,0)$? And $(0,0)$ is also the top left of the intersecting rectangle in your figure? Then the answer is to just reverse the signs of the coordinates of $A.$ This seems so simple, I wonder if I misunderstood the question. $\endgroup$ – David K Feb 8 '17 at 5:09
  • $\begingroup$ @DavidK The topleft point of B is known, but only falls on the origin in my example to help in understanding the problem. Perhaps I should clarify that in the question. $\endgroup$ – I23BigC Feb 8 '17 at 5:14
  • $\begingroup$ It's still fairly simple; instead of subtracting $A$'s coordinates from zero, you subtract them from whatever coordinates $B$ actually has. $\endgroup$ – David K Feb 8 '17 at 5:17
  • $\begingroup$ @DavidK That wouldn't work if, for example, A and B were both 10 by 10. Topleft A = (1,-9), Topleft B = (0,0). Intersecting rectangle would be 9 by 1 at (1,0). I topleft relative to A topleft is (0,9), not (-1,9) as your comment would suggest, If I understand you correctly. $\endgroup$ – I23BigC Feb 8 '17 at 5:28
  • $\begingroup$ If both rectangles are of general dimensions in general position with no other restrictions (except I suppose their sides are parallel to the axes), then you don't know that there is an intersecting rectangle until you've examined the coordinates carefully. So the question becomes how to show whether there is an intersecting rectangle and find its upper left coordinate if it exists. Does that sound like a more complete description of what you need? $\endgroup$ – David K Feb 8 '17 at 5:33
0
$\begingroup$

Simple enough. Subtract the $A$ coordinate from the $I$ coordinate relative to $B$.

$I/A(x,y) = I/B(x,y)-A(x,y)$

$I(x,y)$ with respect to $A$ equals $I(x,y)$ with respect to $B$ minus $A(x,y)$

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.