How to detect if two lines are intersecting?

In this case, either an off-screen PImage / PGraphics object or a 2D array of numbers, one per pixel / point.

See for example the Picking Library http://n.clavaud.free.fr/processing/library/picking/