lines_intersect(unsigned int xl, unsigned int yl, unsigned int x2, unsigned int y2, unsigned int x3, unsigned int y3, unsigned int x4, unsigned int y4) { long al, a2, bl, b2, cl, c2; /* Coefficients of line eqns. */ long rl, r2, r3, r4; /* 'Sign' values */ long denom, offset, num; /* Intermediate values */ //Check to see if the two points overlap if(xl==x2 && yl==y2) return DONTINTERSECT; /* Compute al, bl, cl, where line joining points 1 and 2 *is"alx + bl y + cl = 0". */ al = y2 yl; bl = xl -x2; cl =x2 yl -xl *y2; /* Compute r3 and r4. */ r3 = al x3 +bl y3 + cl; r4=al *x4+bl *y4+cl; /* Check signs of r3 and r4. If both point 3 and point 4 lie on same side of line 1, the line segments do not intersect. */ if(r3 != 0 && r4!= 0 && SAME_SIGNS( r3, r4 )) return ( DONTINTERSECT ); /* Compute a2, b2, c2 */ a2 = y4 y3; b2 = x3 x4; c2 = x4 y3 x3 y4; /* Compute rl and r2 */ rl =a2 *xl +b2 yl + c2; r2 = a2 x2 + b2 y2 + c2;