   Detrmine if two segments on the same line overlaps
  Hello everybodymaybe what I'm going to ask has been already discussed previously, anyway I shortly explain my problem.I am developing a game in Actionscript 3, and I'd like to know if two segments, which lie on the same line, overlap.I have the first segment ( defined by two points A(xa, ya) and B(xb,yb) ) and I need to know if it overlaps the other ( defined by the points C(xc, yc) and D(xd, yd) ).Thank  you all for your attention   
  Yeah the dot product can figure out if two rays point the same general direction. You can use this property so given the segments A to B and C to D you just need to do:if (Dot(C - B, A - B) >= 0 && Dot(D - A, B - A) >= 0){  // overlapping}Expanding this since you might not have a vector class you'll end up with:var temp1:Point = new Point(C.x - B.x, C.y - B.y);var temp2:Point = new Point(A.x - B.x, A.y - B.y);var temp3:Point = new Point(D.x - A.x, D.y - A.y);var temp4:Point = new Point(B.x - A.x, B.y - A.y);if (temp1.x * temp2.x + temp1.y * temp2.y >= 0 && temp3.x * temp4.x + temp3.y * temp4.y >= 0){  // overlapping}   ;  thanks.It worked perfectly.   ;Quote:Original post by gianis6I am developing a game in Actionscript 3, and I'd like to know if two segments, which lie on the same line, overlap.If you know they are on the same line, then the segments overlap iff the AABBs of the segments overlap.;Quote:Original post by Christer EricsonQuote:Original post by gianis6I am developing a game in Actionscript 3, and I'd like to know if two segments, which lie on the same line, overlap.If you know they are on the same line, then the segments overlap iff the AABBs of the segments overlap.Good observation. Not sure if he'll see this but:if (Math.Min(A.x, B.x) < Math.Max(C.x, D.x) && Math.Max(A.x, B.x) > Math.Min(C.x, D.x) && Math.Min(A.y, B.y) < Math.Max(C.y, D.y) && Math.Max(A.y, B.y) > Math.Min(C.y, D.y)){  // overlap}It can be optimized (though the Math.Min and Max functions are probably faster than expanding the operations), but that would be the general formula. Too bad you don't have SSE instructions in AS3 :PTo see the operations expanded though here:var min1:Point = new Point();var max1:Point = new Point();var min2:Point = new Point();var max2:Point = new Point();if (A.x < B.x){  min1.x = A.x;  max1.x = B.x;}else{  min1.x = B.x;  max1.x = A.x;}if (A.y < B.y){  min1.y = A.y;  max1.y = B.y;}else{  min1.y = B.y;  max1.y = A.y;}if (C.x < D.x){  min2.x = C.x;  max2.x = D.x;}else{  min2.x = D.x;  max2.x = C.x;}if (C.y < D.y){  min2.y = C.y;  max2.y = D.y;}else{  min2.y = D.y;  max2.y = C.y;}if (min1.x < max2.x && max1.x > min2.x && min1.y < max2.y && max1.y > min2.y){  // overlap}Curious what the fastest implementation of this looks like. o_O   