1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <iostream>
double det( const double, const double, const double, const double );
int main()
{
double x = 0;
double y = 0;
double x1, y1, x2, y2, x3, y3, x4, y4;
x1 = 15; y1 = 10;
x2 = 15; y2 = 20;
x3 = 7; y3 = 28;
x4 = 45; y4 = 9;
double denominator = det(x1 - x2, y1 - y2, x3 - x4, y3 - y4);
if(denominator != 0)
{
x = det( det(x1, y1, x2, y2), x1 - x2, det(x3, y3, x4, y4), x3 - x4 ) / denominator;
y = det( det(x1, y1, x2, y2), y1 - y2, det(x3, y3, x4, y4), y3 - y4 ) / denominator;
std::cout << "Intersection X: " << x << " Y: " << y << '\n';
}
else
std::cout << "Lines don't intersect.\n";
return 0;
}
double det( const double a, const double b, const double c, const double d)
{
return a * d - b * c;
}
|