平面内两直线位置判断,若有交点,求交点位置,只要推出公式就可以了。
#include<iostream>
#include<stdio.h>
using namespace std;
double x,y,x1,y1,x2,y2,x3,y3,x4,y4,k1,k2,b1,b2;
void process(){
if((x4-x3)*(y2-y1)==(y4-y3)*(x2-x1)){
if((y2-y1)*(x3-x1)==(x2-x1)*(y3-y1)){
cout<<"LINE"<<endl;
}
else cout<<"NONE"<<endl;
return ;
}
if(x1==x2){
k2=(y4-y3)/(x4-x3);
b2=y3-k2*x3;
x=x1;
y=k2*x1+b2;
printf("POINT %.2f %.2f\n",x,y);
return ;
}
if(x3==x4){
k1=(y2-y1)/(x2-x1);
b1=y1-k1*x1;
x=x3;
y=k1*x3+b1;
printf("POINT %.2f %.2f\n",x,y);
return ;
}
k1=(y2-y1)/(x2-x1);
b1=y1-k1*x1;
k2=(y3-y4)/(x3-x4);
b2=y3-k2*x3;
x=(b2-b1)/(k1-k2);
y=k1*x+b1;
printf("POINT %.2f %.2f\n",x,y);
return ;
}
int main(){
int t,i,j;
cout<<"INTERSECTING LINES OUTPUT"<<endl;
cin>>t;
while(t--){
cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
process();
}
cout<<"END OF OUTPUT"<<endl;
return 0;
}