title: Efficient maths algorithm to calculate intersections
body: <p>For a game I am developing I need an algorithm that can calculate intersections. I have solved the problem, but the way I have done it is really nasty and I am hoping someone here might have a more elegant solution.</p>
  
  <p>A pair of points represent the end points of a line drawn between them. Given two pairs of points, do the drawn lines intersect, and if so, at what point? </p>
  
  <p>So for example call the lines (A.x, A.y)-(B.x, B.y) and (C.x, C.y)-(D.x, D.y)</p>
  
  <p>Can anyone think of a solution? A solution in any language will do.</p>
  
  <p><b>Edit:</b> A point I should have made clearer, the algorithm must return false if the point of intersection is beyond the lengths of the line segments.</p>