How do you know if 2 points on a x,y plane that have rectangles around them are intersecting?

KaizenMath

New member
Joined
Mar 14, 2022
Messages
2
Hi Community, I'm not sure if I should post this here ;but I have the following:

1647261982601.png


2 Points on a x,y plane > we know the x and y coordinates of both points.
We also know the width and height of each rectangle from the center that is each point.

I have different scenario’s and in each one of them these 8 variables can change per scenario.

Is there a formula I can use to see if these 2 “rectangles” are intersecting with each other ?

P.S.: I put “” here because the width and heights can be made the same to create a square or any other “box” shape for that matter ,but it will always be some kind of square or rectangle.

To prep for this I took something much easier, I looked at 2 circles around the points:
You take the "straight line distance between two points: r = sqrt ( (x^2-x^1)^2 + (y^2-y^1)^2 ),
and if it is less than or equal to the radius of your circle you know they are intersecting. I don't need to know where ,I just need to know if they are intersecting or not.

The only thing that I can think of to make this easy for me is to break the problem down into tiny parts :
1) every point will be accompanied by 4 straight lines (left, right, top and bottom lines)
2) I get the equation of every straight line (since I have the width and height I can work out the x,y of every corner of every square - I should then have 2 points for all 4 lines)
3) I test the intersection of all 4 lines one by one ,with all 4 lines of the other point
4) If they do not intersect I can skip the the combination/set of 2 lines
5) If two lines do intersect ,I can keep testing, I know the points on the edges of every square/rectangle
6) if the intersecting y or x falls within the 2 x's or 2 y's points that make up the edges of the square/rectangle then we have an intersection
1647264218431.png


This is how I am currently thinking about this problem, but if you have an easier approach I would appreciate it.

Thank you in advance
 
Hi Community, I'm not sure if I should post this here ;but I have the following:

2 Points on a x,y plane > we know the x and y coordinates of both points.
We also know the width and height of each rectangle from the center that is each point.

I have different scenario’s and in each one of them these 8 variables can change per scenario.

Is there a formula I can use to see if these 2 “rectangles” are intersecting with each other ?

P.S.: I put “” here because the width and heights can be made the same to create a square or any other “box” shape for that matter ,but it will always be some kind of square or rectangle.
Hi KaizenMath,

First point: A square is a rectangle! There is no need to 'differentiate' between them. A rectangle is defined as a quadrilateral with opposite sides of equal length and 90° vertices; any plane figure that meets those criteria is a rectangle and any that doesn't is not!

Secondly, in your various "scenarios", is there any defined relationship between the points at the centre of the rectangles and their respective heights & widths?
 
2 Points on a x,y plane > we know the x and y coordinates of both points.
We also know the width and height of each rectangle from the center that is each point.

The only thing that I can think of to make this easy for me is to break the problem down into tiny parts :
1) every point will be accompanied by 4 straight lines (left, right, top and bottom lines)
2) I get the equation of every straight line (since I have the width and height I can work out the x,y of every corner of every square - I should then have 2 points for all 4 lines)
3) I test the intersection of all 4 lines one by one ,with all 4 lines of the other point
4) If they do not intersect I can skip the the combination/set of 2 lines
5) If two lines do intersect ,I can keep testing, I know the points on the edges of every square/rectangle
6) if the intersecting y or x falls within the 2 x's or 2 y's points that make up the edges of the square/rectangle then we have an intersection
Do you notice that two rectangles overlap only if the set of x-coordinates in each overlap, and the set of y-coordinates in each overlap? That is, you can separately look just at the x's and just at the y's.

So here's an example of the x's:

Code:
      a          a
+----------A----------+
                 +------B------+
                     b     b
           <------------>
                 d

These overlap; why? because the distance d between A and B (horizontally) is less than the sum of their half-widths a and b.

Does that tell you what to do?
 
Do you notice that two rectangles overlap only if the set of x-coordinates in each overlap, and the set of y-coordinates in each overlap? That is, you can separately look just at the x's and just at the y's.

So here's an example of the x's:

Code:
      a          a
+----------A----------+
                 +------B------+
                     b     b
           <------------>
                 d

These overlap; why? because the distance d between A and B (horizontally) is less than the sum of their half-widths a and b.

Does that tell you what to do?

Hi Dr.Peterson,

Thank you for your answer.

Yes it makes sense, this way I would not have to check all 8 lines individually.

If I understand you correctly, I just need to check 4 lines (2 x lines and 2 y lines) and if both of them overlap with each other; then there is intersection (but if only one set overlaps then there is no intersection).

Thank you ?
 
As I see the problem:

Draw a circle, centered at point 1 and radius of 1/2*(diagonal) of the rectangle 1, and,​
Draw a circle, centered at point 2 and radius of 1/2*(diagonal) of the rectangle 2​

If these two circles intersect - the rectangles might intersect (when the sides are not parallel to the x-axis and y-axis).
 
Top