Solved

Need a calculation to check if 2 quadrangles overlap

Posted on 2009-05-06
5
306 Views
Last Modified: 2012-05-06
Below is a little graph with an example.
I have 2 quadrangles and I know every point location of both of them.
Now I'd need a calculation that lets me check if they overlap or not.
The quadrangles are always convex.

I came as far as this:
if the minimum x value of quad2 is higher than the maximum x value of quad1 or the maximum x value of quad2 is smaller than the minimum x value of quad1, they can never overlap
if the minimum y value of quad2 is higher than the maximum y value of quad1 or the maximum y value of quad2 is smaller than the minimum y value of quad1, they can never overlap

but that's not enough, the blue quadrangle passes these 2 criteria and yet it doesn't overlap with the black one.
Anyone got an idea?
Thanks in advance.
mathproblem.jpg
0
Comment
Question by:Snapples
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 24315350
Try this
http://pesona.mmu.edu.my/~ypwong/yr1999sem2/tcs2111cg/note9.PDF

search on: "To determine if a point P is within a polygon" and you'll find the passage.
0
 
LVL 15

Accepted Solution

by:
David L. Hansen earned 500 total points
ID: 24315459
It sounds like you determine a line from each point in your polygon (in your case quadrangle) to the point P in question, thus forming four adjoining triangles.  Then just calculate the area of each and sum those all together.  If the resulting area is equal to the area of the original quadrangle then point P does lie within the quadrangle, if not, it lies outside of it.
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 24315996
Just detecting whether a corner is in the polygon is not good enough.  Imagine you have two long narrow quadrangles forming a cross.

The separating axis method is robust and easy enough to implement.  See http://gpwiki.org/index.php/Polygon_Collision
0
 
LVL 20

Expert Comment

by:thehagman
ID: 24317484
Two quadrangels are disjoint iff no two edges intersect --  there are only 16 intersections to check.
To check whether AB intersects CD,
compare the signs of   (D-A) x (B-A)  and  (C-A) x (B-A) -- if they are the same, no intersection occurs
then compare the signes of (A-C) x (D-C) and (B-C) x (D-C) -- if they are the same, no intersection occurs
If none of these two tests hinted at "no intersection", then the segments *do* intersect.
(In the above, (D-A) x (B-A) stands for  (xD-xA)*(yB-yA) - (yD-yA)*(xB-xA) etc.)
0
 
LVL 20

Expert Comment

by:thehagman
ID: 24317514
Oops, forgot the case of one quadrangle completely containing the other.
To take care of that, check for a single vertex of one whether it is inside the other and also vice versa
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
The greatest common divisor (gcd) of two positive integers is their largest common divisor. Let's consider two numbers 12 and 20. The divisors of 12 are 1, 2, 3, 4, 6, 12 The divisors of 20 are 1, 2, 4, 5, 10 20 The highest number among the c…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now