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?
How to find coordinate of intersected rectangle
0
$\begingroup$
geometry
coordinate-systems
rectangles
-
0You 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. – 2017-02-08
-
0@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. – 2017-02-08
-
0It's still fairly simple; instead of subtracting $A$'s coordinates from zero, you subtract them from whatever coordinates $B$ actually has. – 2017-02-08
-
0@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. – 2017-02-08
-
0If 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? – 2017-02-08
-
0@DavidK This question assumes that the proper checks have been made prior, to assure there is an intersecting rectangle with the given rectangles. It also goes as far as assuming you already possess the size and location of the intersecting rectangle, let alone that it exists. – 2017-02-08
-
0Then the information about $B$ is no longer relevant. I only used the coordinates of $B$ since they were the top left coordinates of the intersection in your example. Use the coordinates of the intersected rectangle instead. – 2017-02-08
-
0Basically you seem to have the coordinates of two points, and you want to know "how far to the right and how far down to get from the top left corner of $A$ to the top left corner of $I$?" You go far enough right to get from one $x$ coordinate to the other, and far enough down to get from one $y$ coordinate to the other. – 2017-02-08
-
0Thank you, this is the little kick I needed. I knew it was simple. What I am looking for is $I-A$ simple enough. – 2017-02-08
-
0Sometimes you just need to hash it out like this to get unstuck ... glad to help. – 2017-02-08
1 Answers
0
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)$