def segments_intersect(seg1, seg2):
    """ Returns whether or not two line segments intersect. """
    
    def orientation(p1, p2, p3):
        ''' Returns 1 if p1, p2, and p3 are in counterclockwise order, -1 if 
        they are in clockwise order, and 0 if they are collinear.
        
        '''
        
        p1x, p1y = p1
        p2x, p2y = p2
        p3x, p3y = p3
        
        # Line 1: p1 -> p2
        # Line 2: p1 -> p3
        
        result = (p3y - p1y) * (p2x - p1x) - (p3y - p1y) * (p2x - p1x)
        
        if result > 0:
            return 1
        elif result < 0:
            return -1
        else:
            return 0
            
    def point_on_segment(p, segStart, segEnd):
        ''' Determines whether or not the point 'p' is on the given line 
        segment.
        
        '''
        
        px, py = p
        segStartX, segStartY = segStart
        segEndX, segEndY = segEnd
        
        return all(
                (
                    px <= max(segStartX, segEndX),
                    px >= min(segStartX, segEndX),
                    py <= max(segStartY, segEndY),
                    py >= min(segStartY, segEndY),
                )
            )
            
    seg1Start, seg1End = seg1
    seg2Start, seg2End = seg2
    
    o1 = orientation(seg1Start, seg1End, seg2Start)
    o2 = orientation(seg1Start, seg1End, seg2End)
    o3 = orientation(seg2Start, seg2End, seg1Start)
    o4 = orientation(seg2Start, seg2End, seg1End)
    
    if o1 != o2 and o3 != o4:
        return True
        
    else:
        return any(
                (
                    (o1 == 0
                        and point_on_segment(seg2Start, seg1Start, seg1End)),
                    (o2 == 0
                        and point_on_segment(seg2End, seg1Start, seg1End)),
                    (o3 == 0
                        and point_on_segment(seg1Start, seg2Start, seg2End)),
                    (o4 == 0
                        and point_on_segment(seg1End, seg2Start, seg2End)),
                )
            )