' TRUE if line objects L1 and L2 self-intersect
Sub intersects(L1 As line, L2 As line) As Boolean
Return (pointside(L1, L2.p0) <> (pointside(L1, L2.p1))) And (pointside(L2, L1.p0) <> (pointside(L2, L1.p1)))
End Sub
' Determine on which side of line L point P lies
Sub pointside(L As line, P As point) As Int
Dim a As Float
a = ((L.p1.x - L.p0.x) * (P.y - L.p0.y)) - ((P.x - L.p0.x) * (L.p1.y - L.p0.y))
If (a > 0) Then Return 1
If (a < 0) Then Return -1
Return 0
End Sub