Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 41427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:10:45+00:00 2026-05-10T15:10:45+00:00

I’m looking for an algorithm to detect if two rectangles intersect (one at an

  • 0

I’m looking for an algorithm to detect if two rectangles intersect (one at an arbitrary angle, the other with only vertical/horizontal lines).

Testing if a corner of one is in the other ALMOST works. It fails if the rectangles form a cross-like shape.

It seems like a good idea to avoid using slopes of the lines, which would require special cases for vertical lines.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:10:45+00:00Added an answer on May 10, 2026 at 3:10 pm

    The standard method would be to do the separating axis test (do a google search on that).

    In short:

    • Two objects don’t intersect if you can find a line that separates the two objects. e.g. the objects / all points of an object are on different sides of the line.

    The fun thing is, that it’s sufficient to just check all edges of the two rectangles. If the rectangles don’t overlap one of the edges will be the separating axis.

    In 2D you can do this without using slopes. An edge is simply defined as the difference between two vertices, e.g.

      edge = v(n) - v(n-1) 

    You can get a perpendicular to this by rotating it by 90°. In 2D this is easy as:

      rotated.x = -unrotated.y   rotated.y =  unrotated.x 

    So no trigonometry or slopes involved. Normalizing the vector to unit-length is not required either.

    If you want to test if a point is on one or another side of the line you can just use the dot-product. the sign will tell you which side you’re on:

      // rotated: your rotated edge   // v(n-1) any point from the edge.   // testpoint: the point you want to find out which side it's on.    side = sign (rotated.x * (testpoint.x - v(n-1).x) +                 rotated.y * (testpoint.y - v(n-1).y); 

    Now test all points of rectangle A against the edges of rectangle B and vice versa. If you find a separating edge the objects don’t intersect (providing all other points in B are on the other side of the edge being tested for – see drawing below). If you find no separating edge either the rectangles are intersecting or one rectangle is contained in the other.

    The test works with any convex polygons btw..

    Amendment: To identify a separating edge, it is not enough to test all points of one rectangle against each edge of the other. The candidate-edge E (below) would as such be identified as a separating edge, as all points in A are in the same half-plane of E. However, it isn’t a separating edge because the vertices Vb1 and Vb2 of B are also in that half-plane. It would only have been a separating edge if that had not been the case http://www.iassess.com/collision.png

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 102k
  • Answers 102k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm afraid you'll have to write one for yourself, because… May 11, 2026 at 8:15 pm
  • Editorial Team
    Editorial Team added an answer Try something like this: if($(this).is(':checked')) { $(this).parent().parent().parent().find('.green').removeClass('green'); $(this).parent().addClass('green'); } This… May 11, 2026 at 8:15 pm
  • Editorial Team
    Editorial Team added an answer Check out linux/stacktrace.h Here is an API reference: http://www.cs.cmu.edu/afs/cs/Web/People/tekkotsu/dox/StackTrace_8h.html Should… May 11, 2026 at 8:15 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.