求线段交点,输入两组线段端点(整型),求其交点,不相交和无穷交点输出一句话就行,输出交点带小数的。
输入:
0 0 5 5
0 2 2 0
输出:1 1
#include<iostream>
using namespace std;
int main() {
int x0, y0, x1, y1;
int x2, y2, x3, y3;
cin >> x0 >> y0 >> x1 >> y1;
cin >> x2 >> y2 >> x3 >> y3;
int k1 = (y1 - y0) / (x1 - x0);
int k2 = (y3 - y2) / (x3 - x2);
int b1 = y1 - k1 * x1;
int b2 = y2 - k2 * x2;
int x = (b2 - b1) / (k1-k2);
int y = k1 * x + b1;
cout << x <<" "<<y;
system("pause");
return 0;
}