#include "point.h" #include "line.h" //Construct the point where the two lines intersect. //Throw an exception if the two lines are parallel. point::point(const line& l1, const line& l2) throw (int) { const double a1 = l1.B.y - l1.A.y; const double b1 = l1.A.x - l1.B.x; const double c1 = b1 * l1.A.y + a1 * l1.A.x; const double a2 = l2.B.y - l2.A.y; const double b2 = l2.A.x - l2.B.x; const double c2 = b2 * l2.A.y + a2 * l2.A.x; const double determinant = a1 * b2 - a2 * b1; if (determinant == 0) { //lines are parallel throw 0; } x = (b2 * c1 - b1 * c2) / determinant; y = (a1 * c2 - a2 * c1) / determinant; }