<p>The first step in your existing code calculates the orientations of one line segment relative to each of the two end points of the other line segment, using the cross product. This allows testing whether the other line segment has one end point anticlockwise and the other end point clockwise from the first line segment, indicating that the line on which the first segment lies cuts the other segment.</p>

<p>Rather than writing a new test, you can use these same orientations to test for line segments that overlap (including partial overlap). If both segments lie on the same line, then all four orientations calculated in your first step will be zero, because none of the end points are either clockwise or anticlockwise from the line, since they are on the line. Then it remains only to check whether the two segments on the same line overlap, by checking whether either of them has an end point between the end points of the other segment.</p>

CC BY-SA 3.0
2016-04-30T01:06:36.060Z
2016-04-30T01:13:58.043Z
2016-04-30T01:13:58.043Z
trichoplax is on Codidact now
<p>If you're working in 2D, it should be enough to just take the dot product of the normals of the lines and if it is -1 or 1 then the lines are parallel, and either don't overlap or fully overlap. 2 lines cannot "partially overlap". They either meet at a single point, at every point, or no points.</p>

CC BY-SA 3.0
2016-04-30T00:42:17.940Z
Two lines cannot partially overlap, but two line segments can.
trichoplax is on Codidact now
CC BY-SA 3.0
2016-04-30T01:03:54.483Z
Ah, good point. I was thinking infinite lines. I'll update when I have a minute.
user1118321
CC BY-SA 3.0
2016-04-29T03:32:36.057Z
2016-04-29T03:32:36.057Z
user1118321
<p>I have implemented line segments <a href="https://computergraphics.stackexchange.com/questions/2362/line-segment-intersection-test-and-find-the-point-of-intersection">intersetion test</a> and at the very same test I want to include the fact that if two line segments overlap each other partially or fully , it will be flagged as no intersection.</p>

<p>Some hint to it would be great to have!</p>

CC BY-SA 3.0
2016-04-30T00:52:51.550Z
It would be helpful to see your code in this question to make the post self-contained. I'll add an answer that refers to your code but it will make more sense if the code is visible in the question.
trichoplax is on Codidact now
<2d-graphics>
Line segments overlapping
sajis997
# Line segments overlapping

(Asked by: username_0 on 2016-04-28)

I have implemented line segments [intersetion test](https://computergraphics.stackexchange.com/questions/2362/line-segment-intersection-test-and-find-the-point-of-intersection) and at the very same test I want to include the fact that if two line segments overlap each other partially or fully , it will be flagged as no intersection.

Some hint to it would be great to have!

**Tags:** 2d-graphics

> **Comments:**
> **username_1**: It would be helpful to see your code in this question to make the post self-contained. I'll add an answer that refers to your code but it will make more sense if the code is visible in the question.  

---

## 2 answers

### Answer by username_1 on 2016-04-30. Score: 1 | Accepted answer

The first step in your existing code calculates the orientations of one line segment relative to each of the two end points of the other line segment, using the cross product. This allows testing whether the other line segment has one end point anticlockwise and the other end point clockwise from the first line segment, indicating that the line on which the first segment lies cuts the other segment.

Rather than writing a new test, you can use these same orientations to test for line segments that overlap (including partial overlap). If both segments lie on the same line, then all four orientations calculated in your first step will be zero, because none of the end points are either clockwise or anticlockwise from the line, since they are on the line. Then it remains only to check whether the two segments on the same line overlap, by checking whether either of them has an end point between the end points of the other segment.


---

### Answer by username_2 on 2016-04-29. Score: 0

If you're working in 2D, it should be enough to just take the dot product of the normals of the lines and if it is -1 or 1 then the lines are parallel, and either don't overlap or fully overlap. 2 lines cannot "partially overlap". They either meet at a single point, at every point, or no points.

> **Comments:**
> **username_1**: Two lines cannot partially overlap, but two line segments can.  
> **username_2**: Ah, good point. I was thinking infinite lines. I'll update when I have a minute.  

---

