GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Mar-2009, 04:53
mandar_999 mandar_999 is offline
New Member
 
Join Date: Jan 2009
Posts: 9
mandar_999 is an unknown quantity at this point
Thumbs down

How to find whether 2 segments overlap each other or not


i have 2 segments

the first line has points whose coordinates are:

(x1,y1) and (x2,y2)

and second line has points whose coordinates are:

(u1,v1) and (u2,v2)

i want to find out whether these 2 segments overlap each other or not
(whether thy have more than 1 point common)
for example

A(2,2),B(6,6) & C(3,3),D(5,5)
now segment AB & CD overlaps each other
how to find it out mathematically
plz give explanation
  #2  
Old 18-Mar-2009, 10:42
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: how to find whether 2 segments overlap each other or not


Quote:
Originally Posted by mandar_999
...2 segments... (x1,y1) and (x2,y2)...and... (u1,v1) and (u2,v2)

I suggest that you might start by visualization, aided by actual visual construction.

In other words...

Draw the lines (with pencil and paper). Try to see whether you can convince yourself that the following claims are always true.

First of all, you need to know that the two infinite lines (the lines that contain the given segments) are collinear. That is, the equations for the lines are linearly dependent and consistent.

In general what might happen between the line segments?



I think that there are three possibilities:

They might have no points in common. (The segments don't overlap at all.)

They might have exactly one point in common. (One segment butts up against the other.)

They might overlap with an infinite number of common points
I suggest that you draw line segments that illustrate these three conditions. Are all possibilities covered? What else could happen with segments from collinear lines?

Then, given that the lines are collinear, and (x1 != x2) and (u1 != u2), lets see if we can make some general observations that might lead to something useful.

Let minx = min(x1,x2), maxx = max(x1,x2)
Let minu = min(u1,u2), maxu = max(u1,u2)

Consider the two cases:


Case 1: minx <= minu

Claim 1a: The line segments have exactly one point in common if and only if
minu == maxx

Claim 1b: The line segments overlap with an infinite number of common points if and only if
minu < maxx

Claim 1c (The only other possibility if neither the conditions for Claim 1a or Claim 1b hold): The line segments don't overlap if and only if
minu > maxx


Case 2: minu < minx

Claim 2a: The line segments have exactly one point in common if and only if
minx == maxu

Claim 2b: The line segments overlap with an infinite number of common points if and only if
minx < maxu

Claim 2c (The only other possibility if neither the conditions for Claim 1a or Claim 1b hold): The line segments don't overlap if and only if
minx > maxu


If these claims are true, then an implementation can be straightforward. Of course it is possible that a more elegant solution can be formulated, but I think an implementation that is obtained directly from observation might be practical, at least for starters.


Regards,

Dave
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find intersection point of 2 segments mandar_999 C++ Forum 4 17-Mar-2009 08:51
Find the @ in a file Bradster C++ Forum 9 09-Jul-2007 13:59
Program that can find a patern Anyways C++ Forum 4 23-Mar-2005 02:11
HELP!: find window width? Center a <div>? Kingherc Web Design Forum 2 06-Jul-2003 06:25

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:35.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.