consider this code:
Point findIntersection(Line l1, Line l2)
{
int T1, T2;
T2 = (l2.d.x*(l1.p.y-l2.p.y) + l2.d.y*(l2.p.x-l1.p.x))/(l1.d.x*l2.d.y - l1.d.y*l2.d.x);
T1 = (l1.p.x+l1.d.x*T2-l2.p.x)/l2.d.x;
if (T1>0 && 0<T2<1) {
return {l2.p.x+l2.d.x*T1, l2.p.y+l2.d.y*T1};
}
}
(full code http://pastebin.com/M6G40F4M)
this code causes a floating point exception on lines 3&4 (and 13&14 in the larger code snippet). My question is why does this happen, and what would be the correct way to find where two lines intersect. I know these errors usually occur when dividing by zero but I am not sure where I am doing that and how it could be prevented.