POJ-1269-Intersecting Lines(判断直线相交,测板子)

题目链接:http://poj.org/problem?id=1269

题目大意:给出两条直线上的四个点(每条直线两个点),判断这两条直线:1重合(输出LINE),2.平行(输出NONE),3.相交(输出交点)。

思路:测试板子的一道题,把之前总结的板子写上就好了。

ACCode:

//#pragma comment(linker, "/STACK:1024000000,1024000000")
  
#include<stdio.h>
#include<string.h> 
#include<math.h> 
   
#include<map>  
#include<set>
#include<deque> 
#include<queue> 
#include<stack> 
#include<bitset>
#include<string> 
#include<fstream>
#include<iostream> 
#include<algorithm> 
using namespace std; 
  
#define ll long long 
#define Pair pair<int,int>
//#define max(a,b) (a)>(b)?(a):(b)
//#define min(a,b) (a)<(b)?(a):(b)
#define clean(a,b) memset(a,b,sizeof(a))// ??
//std::ios::sync_with_stdio(false);
//  register
const int MAXN=5e3+10;
const int INF32=0x3f3f3f3f;
const ll INF64=0x3f3f3f3f3f3f3f3f;
const ll mod=1e9+7;
const double PI=acos(-1.0);
const double EPS=1.0e-8;

struct Point{
	double x,y;
	Point(double _x=0,double _y=0){
		x=_x;y=_y;
	}
	friend Point operator - (const Point &a,const Point &b){
		return Point(a.x-b.x,a.y-b.y);
	}
	friend double operator ^ (const Point &a,const Point &b){
		return a.x*b.y-a.y*b.x;
	}
};
struct V{
	Point start,end;
	V(Point _start=Point(0,0),Point _end=Point(0,0)){
		start=_start;end=_end;
	}
};
V l[5];
int n;

int Parellel(V l1,V l2){
	return fabs((l1.end-l1.start)^(l2.end-l2.start))<EPS;
}
int Coincidence(V l1,V l2){//两条线重合 
	return fabs((l1.start-l2.start)^(l1.end-l2.start))<EPS;
}
Point LineInterDot(const V &l1,const V &l2){
	Point p=l1.start;
	double res=((l1.start-l2.start)^(l2.start-l2.end));
	res/=((l1.start-l1.end)^(l2.start-l2.end));
	p.x+=(l1.end.x-l1.start.x)*res;
	p.y+=(l1.end.y-l1.start.y)*res;
	return p;
}
int main(){
	while(~scanf("%d",&n)){
		printf("INTERSECTING LINES OUTPUT\n");
		while(n--){
			for(int i=1;i<=2;++i){
				scanf("%lf%lf%lf%lf",&l[i].start.x,&l[i].start.y,&l[i].end.x,&l[i].end.y);
			}
			if(Parellel(l[1],l[2])){//平行 
				if(Coincidence(l[1],l[2])) printf("LINE\n");
				else printf("NONE\n");
				continue;
			}Point Ans=LineInterDot(l[1],l[2]);
			printf("POINT %.2f %.2f\n",Ans.x,Ans.y);
		}printf("END OF OUTPUT\n");
	}
}

/*


*/

猜你喜欢

转载自blog.csdn.net/qq_40482358/article/details/88857296