function doesIntersect(p1, q1, p2, q2) {
  var result = false;

  var orient = [orientation(p1, q1, p2), orientation(p1, q1, q2), orientation(p2, q2, p1), orientation(p2, q2, q1)];

  // General Case
  if (orient[0] !== orient[1] && orient[2] !== orient[3]) {
    return true;
  }

  // Special Cases
  if (orient[0] === 0 && onSegment(p1, p2, q1)) {
    // If p1, q1 and p2 are colinear and p2 lies on segment p1q1
    result = true;
  } else if (orient[1] === 0 && onSegment(p1, q2, q1)) {
    // If p1, q1 and p2 are colinear and q2 lies on segment p1q1
    result = true;
  } else if (orient[2] === 0 && onSegment(p2, p1, q2)) {
    // If p2, q2 and p1 are colinear and p1 lies on segment p2q2
    result = true;
  } else if (orient[3] === 0 && onSegment(p2, q1, q2)) {
    // If p2, q2 and q1 are colinear and q1 lies on segment p2q2
    result = true;
  }

  return result;
}
/**
* Checks whether the line (p1,q1) intersects the line (p2,q2) via an orientation algorithm.
*
* @param {Object} p1 - Coordinates of the start of the line 1.
* @param {Object} q1 - Coordinates of the end of the line 1.
* @param {Object} p1 - Coordinates of the start of the line 2.
* @param {Object} q1 - Coordinates of the end of the line 2.
* @return {Boolean} - Whether lines (p1,q1) and (p2,q2) intersect.
*/
Checks whether the line (p1,q1) intersects the line (p2,q2) via an orientation algorithm.
Checks whether the line ( p1 q1 ) intersects the line ( p2 q2 ) via an orientation algorithm .
function doesIntersect(p1, q1, p2, q2) {
  var result = false;
  var orient = [orientation(p1, q1, p2), orientation(p1, q1, q2), orientation(p2, q2, p1), orientation(p2, q2, q1)];
  if (orient[0] !== orient[1] && orient[2] !== orient[3]) {
    return true;
  }
  if (orient[0] === 0 && onSegment(p1, p2, q1)) {
    result = true;
  } else if (orient[1] === 0 && onSegment(p1, q2, q1)) {
    result = true;
  } else if (orient[2] === 0 && onSegment(p2, p1, q2)) {
    result = true;
  } else if (orient[3] === 0 && onSegment(p2, q1, q2)) {
    result = true;
  }
  return result;
}
function doesIntersect ( p1 , q1 , p2 , q2 ) { var result = false ; var orient = [ orientation ( p1 , q1 , p2 ) , orientation ( p1 , q1 , q2 ) , orientation ( p2 , q2 , p1 ) , orientation ( p2 , q2 , q1 ) ] ; if ( orient [ 0 ] !== orient [ 1 ] && orient [ 2 ] !== orient [ 3 ] ) { return true ; } if ( orient [ 0 ] === 0 && onSegment ( p1 , p2 , q1 ) ) { result = true ; } else if ( orient [ 1 ] === 0 && onSegment ( p1 , q2 , q1 ) ) { result = true ; } else if ( orient [ 2 ] === 0 && onSegment ( p2 , p1 , q2 ) ) { result = true ; } else if ( orient [ 3 ] === 0 && onSegment ( p2 , q1 , q2 ) ) { result = true ; } return result ; }
Checks whether the line (p1,q1) intersects the line (p2,q2) via an orientation algorithm.
Checks whether the line ( p1 q1 ) intersects the line ( p2 q2 ) via an orientation algorithm .
// General Case // Special Cases // If p1, q1 and p2 are colinear and p2 lies on segment p1q1 // If p1, q1 and p2 are colinear and q2 lies on segment p1q1 // If p2, q2 and p1 are colinear and p1 lies on segment p2q2 // If p2, q2 and q1 are colinear and q1 lies on segment p2q2