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:
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
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
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
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