Question: I know there are many algorithms to verify whether two line segments are intersected.

The line segments I'm talking about are length line constructed by 2 end points.

But once they encountered parallel condition, they just tell the user a big "No" and  

pretend there is no overlap, share end point, or end point collusion.

I know I can can calculate the distance between 2 lines segments.  

If the distance is 0, check the end points located in the other line segments or not.  

And this means I have to use a lot of if else and && || conditions.

This is not difficult, but my question is

**"Is there a trick( or mathematics) method to calculate this special parallel case?"**

**I hope this picture clarify my question  

<http://judark.myweb.hinet.net/parallel.JPG>**

Answer: 
Yes, given the formulas for both of the lines, test whether their slopes are equal. If they are, the lines are parallel and never intersect.

If you have points on each of the lines, you can use the [slope formula](http://cs.selu.edu/~rbyrd/math/slope/).

If both are perpendicular to the x-axis, they will both have infinite slopes, but they will be parallel. All points on each line will have equal x coordinates.

To deal with line segments, calculate the point of intersection, then determine if that point of intersection exists for both of the segments.
i found this (modified a little by me to suit)
it will return the intercetion x,y else if no intercetion found it will return -1,-1

```
    Public Function intercetion(ByVal ax As Integer, ByVal ay As Integer, ByVal bx As Integer, ByVal by As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal dx As Integer, ByVal dy As Integer) As Point
    '//  Determines the intersection point of the line segment defined by points A and B
    '//  with the line segment defined by points C and D.
    '//
    '//  Returns YES if the intersection point was found, and stores that point in X,Y.
    '//  Returns NO if there is no determinable intersection point, in which case X,Y will
    '//  be unmodified.

    Dim distAB, theCos, theSin, newX, ABpos As Double

    '//  Fail if either line segment is zero-length.
    If ax = bx And ay = by Or cx = dx And cy = dy Then Return New Point(-1, -1)

    '//  Fail if the segments share an end-point.
    If ax = cx And ay = cy Or bx = cx And by = cy Or ax = dx And ay = dy Or bx = dx And by = dy Then Return New Point(-1, -1)

    '//  (1) Translate the system so that point A is on the origin.
    bx -= ax
    by -= ay
    cx -= ax
    cy -= ay
    dx -= ax
    dy -= ay

    '//  Discover the length of segment A-B.
    distAB = Math.Sqrt(bx * bx + by * by)

    '//  (2) Rotate the system so that point B is on the positive X axis.
    theCos = bx / distAB
    theSin = by / distAB
    newX = cx * theCos + cy * theSin
    cy = cy * theCos - cx * theSin
    cx = newX
    newX = dx * theCos + dy * theSin
    dy = dy * theCos - dx * theSin
    dx = newX

    '//  Fail if segment C-D doesn't cross line A-B.
    If cy < 0 And dy < 0 Or cy >= 0 And dy >= 0 Then Return New Point(-1, -1)

    '//  (3) Discover the position of the intersection point along line A-B.
    ABpos = dx + (cx - dx) * dy / (dy - cy)

    '//  Fail if segment C-D crosses line A-B outside of segment A-B.
    If ABpos < 0 Or ABpos > distAB Then Return New Point(-1, -1)

    '//  (4) Apply the discovered position to line A-B in the original coordinate system.
    '*X=Ax+ABpos*theCos
    '*Y=Ay+ABpos*theSin

    '//  Success.
    Return New Point(ax + ABpos * theCos, ay + ABpos * theSin)
End Function

```

[Origin](http://alienryderflex.com/intersect/)