Useful functions - sample 05 - The intersection of two line segments

I want to help people coding in ‪#‎javascript‬ ‪#‎HTML5‬ ‪#‎CSS3‬ so I have decided to solve
problems they can encounter, create functions ready to be used and illustrate the point
with interactive samples.

The problem : You want to know if two line segments intersect or not. You can check
the source code of this page and use my function SegmentsIntersection(segment1,segment2)
that returns the intersection with x=null and y=null if they do not intersect.

The sample : Ten balls are moving and bouncing randomly. The mouse cursor is one of them
All the line segments between the balls are drawn and their intersections are shown.

Click here for more content