Pretty simple implementation, hope it helps!
#include <iostream>
using namespace std;
int crossProduct(int* v1, int* v2){
int product = v1[1]*v2[2] - v1[2]*v2[1];
return product;
}
int pointProduct(int* v1, int* v2){
int product = v1[1]*v2[1] + v1[2]*v2[2];
return product;
}
int main()
{
//Variables inputs
int x1,x2,x3,x4,y1,y2,y3,y4,t,u;
cout << "Insert x1 ";
cin >> x1;
cout << "Insert y1 ";
cin >> y1;
cout << "Insert x2 ";
cin >> x2;
cout << "Insert y2 ";
cin >> y2;
cout << "Insert x3 ";
cin >> x3;
cout << "Insert y3 ";
cin >> y3;
cout << "Insert x4 ";
cin >> x4;
cout << "Insert y4 ";
cin >> y4;
//Array assignments
int r[2],s[2],q[2];
r[1] = x2 - x1;
r[2] = y2 - y1;
cout << "r: " << r[1] << ","<< r[2] << endl;
s[1] = x4 - x3;
s[2] = y4 - y3;
cout << "s: " << s[1] << "," << s[2] << endl;
q[1] = x3 - x1;
q[2] = y3 - y1;
cout << "q: " << q[1] << "," << q[2] << endl;
cout << "Assignments done\n";
//CrossProduct
int qsProd = crossProduct(q,s);
cout << "q x s: " << qsProd << endl;
int qrProd = crossProduct(q,r);
cout << "q x s " << qrProd << endl;
int rsProd = crossProduct(r,s);
cout << "r x s " << rsProd << endl;
if(rsProd != 0){
t = qsProd/rsProd;
u = qrProd/rsProd;
}
else{
cerr << "Cannot divide by zero!";
exit(1);
}
//PointProduct
int qrPoint = pointProduct(q,r);
int rrPoint = pointProduct(r,r);
int qsPoint = pointProduct(q,s);
int ssPoint = pointProduct(s,s);
//Conditions PrintOut
if(rsProd == 0 && qrProd == 0)
cout << "Lines are Collinear!\n";
if((rrPoint >= qrPoint && qrPoint >= 0) || (ssPoint >= qsPoint >= 0))
cout << "Lines are Overlapping!\n";
else
cout << "lines are Disjoint!\n";
if(rsProd == 0 && qrProd != 0)
cout << "The two lines are parallel and not intersecting\n";
if(rsProd != 0){
if((1 >= t && t >= 0) && (1 >= u && u >= 0))
cout << "The two lines intersect at P1+t*r\n";
else
cout << "The two line segments do not intersect\n";
}
}