Results 1 to 11 of 11

Thread: Rectangle Intersection

  1. #1
    Member
    Joined
    Mar 2012
    From
    nyc
    Posts
    124
    Thanks
    1

    Rectangle Intersection

    Hello All,

    I'm doing a coding challenge in which I have to write a formula that returns the intersection of two rectangles. But before I do that, I want to attempt this mathematically. Can anyone provide resources to familiarize myself with on how to calculate the intersection of two rectangles? Any resources or information will be helpful.

    Thanks

    ETA: So one way of determining an intersection is to see if one corner (top left) of rectangle A is above the corner (top left) of rectangle B.
    Any other way?
    Last edited by noork85; Nov 3rd 2016 at 09:15 AM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    5,252
    Thanks
    2236

    Re: Rectangle Intersection

    Quote Originally Posted by noork85 View Post
    Hello All,

    I'm doing a coding challenge in which I have to write a formula that returns the intersection of two rectangles. But before I do that, I want to attempt this mathematically. Can anyone provide resources to familiarize myself with on how to calculate the intersection of two rectangles? Any resources or information will be helpful.

    Thanks

    ETA: So one way of determining an intersection is to see if one corner (top left) of rectangle A is above the corner (top left) of rectangle B.
    Any other way?
    what exactly do you mean by "the intersection"?

    a boolean that indicates the the two rectangles overlap?

    two corner points of the rectangle (or line, or point) that is the intersection?

    something else?
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member
    Joined
    Mar 2012
    From
    nyc
    Posts
    124
    Thanks
    1

    Re: Rectangle Intersection

    points, coordinates.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Joined
    Feb 2015
    From
    Ottawa Ontario
    Posts
    1,443
    Thanks
    272

    Re: Rectangle Intersection

    Quote Originally Posted by noork85 View Post
    points, coordinates.
    Why are you so "mysterious"?
    Will the 4 coordinates of each rectangle be givens?
    If so, then:
    1: do rectangles intersect?
    If so:
    2: calculate intersection points.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Member
    Joined
    Mar 2012
    From
    nyc
    Posts
    124
    Thanks
    1

    Re: Rectangle Intersection

    Quote Originally Posted by DenisB View Post
    Why are you so "mysterious"?
    Will the 4 coordinates of each rectangle be givens?
    If so, then:
    1: do rectangles intersect?
    If so:
    2: calculate intersection points.
    oh sorry, i wasn't trying to be mysterious lol
    I'm not sure I understand the problem myself.
    Yes, the coordinates will be given for the two rectangles.
    How do i calculate the intersection points? i mean, if i draw it out on a graph, i can do it. But without the aid of a graph, how do I go about attempting this problem?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor
    Joined
    Feb 2015
    From
    Ottawa Ontario
    Posts
    1,443
    Thanks
    272

    Re: Rectangle Intersection

    Well, can take years to explain by typing back and forth...

    Go hunt:
    https://www.google.ca/?gws_rd=ssl#q=...f+2+rectangles
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Member
    Joined
    Mar 2012
    From
    nyc
    Posts
    124
    Thanks
    1

    Re: Rectangle Intersection

    Quote Originally Posted by DenisB View Post
    Well, can take years to explain by typing back and forth...

    Go hunt:
    https://www.google.ca/?gws_rd=ssl#q=...f+2+rectangles
    i've already done that, thanks.
    I was looking for something more mathematical.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    MHF Contributor
    Joined
    Feb 2015
    From
    Ottawa Ontario
    Posts
    1,443
    Thanks
    272

    Re: Rectangle Intersection

    Quote Originally Posted by noork85 View Post
    I was looking for something more mathematical.
    More mathematical than what?

    You stated you're trying to code a "formula".
    Forget it: you'll need much more than that...

    As example, you'll need coding that uses the given coordinates
    and does comparisons to determine if the rectangles actually
    intersect each other.
    Like: is the highest x-coordinate of one rectangle lower than
    the lowest x-coordinate of the other rectangle...
    that's take a bit of tricky programming; something like:
    get rectangle A's 4 x-coordinates; u = highest
    get rectangle B's 4 x-coordinates; v = lowest
    is u < v?
    Follow Math Help Forum on Facebook and Google+

  9. #9
    MHF Contributor
    Joined
    Sep 2012
    From
    Australia
    Posts
    6,417
    Thanks
    1675

    Re: Rectangle Intersection

    Hey noork85.

    You can parameterize the edges of the rectangle and solve for where and when the lines intersect to get the new rectangle.
    Follow Math Help Forum on Facebook and Google+

  10. #10
    MHF Contributor
    Joined
    Feb 2015
    From
    Ottawa Ontario
    Posts
    1,443
    Thanks
    272

    Re: Rectangle Intersection

    Quote Originally Posted by chiro View Post
    You can parameterize the edges of the rectangle and solve for where and when the lines intersect to get the new rectangle.
    But there is no "new rectangle" as such; both are givens.

    There will be 3 cases:
    1: the given rectangles do not intersect
    2: they intersect at 2 points
    3: they intersect at 4 points
    (not possible to intersect at 1 point or at 3 points)

    Not sure, but intersecting at 6 points may be possible.
    Follow Math Help Forum on Facebook and Google+

  11. #11
    MHF Contributor
    Joined
    Feb 2015
    From
    Ottawa Ontario
    Posts
    1,443
    Thanks
    272

    Re: Rectangle Intersection

    This site kinda discusses this:

    https://www.careercup.com/question?id=3870800
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 1
    Last Post: Mar 2nd 2015, 10:00 PM
  2. Replies: 6
    Last Post: Jun 2nd 2011, 05:56 PM
  3. Rectangle intersection with curve(Object)
    Posted in the Geometry Forum
    Replies: 3
    Last Post: Jun 5th 2009, 06:06 AM
  4. How to find the Rectangle Intersection
    Posted in the Geometry Forum
    Replies: 3
    Last Post: Jun 2nd 2009, 06:07 PM
  5. rectangle intersection with arc
    Posted in the Geometry Forum
    Replies: 2
    Last Post: Jun 1st 2009, 10:28 PM

Search Tags


/mathhelpforum @mathhelpforum