How to find coordinate of intersected rectangle

71 Views Asked by At

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

1

There are 1 best solutions below

0
On

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)$