The (pseudo)code snippet there:
return (C.y-A.y) * (B.x-A.x) > (B.y-A.y) * (C.x-A.x)
Return true if line segments AB and CD intersect
return ccw(A,C,D) != ccw(B,C,D) and ccw(A,B,C) != ccw(A,B,D)
Looks pretty interesting(and pretty concise!) I will try that.
This sorta works...
#formula is y= g1 * x + c1
c2 = line2 - (g2 * line2)
#formula is y= g2 * x + c2
both formulas will be equal at the intersection,
i.e. one minus the other equals zero
(g1 * x) + c1 - (g2 * x) - c2 = 0
#solve for x...
xinter = (c2-c1) / (g1-g2)
but is xinter somewhere in the correct range?
eg the range of one of the lines x bounds
note: needs work as needs to limit to overlapping x range
if xinter in range(line1,line1):
I just sketched this out using linear equations and it worked, and it seems like others on the web do the same - find the point where both linear equations equal each other ( or if they don't, then your lines don't intersect)
Nice example here :
But wonder if something more elegant using the "in" function for rectangles might work...hmmm