poj 1269 Intersecting Lines 直线位置关系
来源:互联网 发布:淘宝上可靠的韩国代购 编辑:程序博客网 时间:2024/05/16 01:13
题目地址:poj1269
水题,直接用叉积判断
代码:
#include<iostream>#include<cmath>#include<cstdio>#include<algorithm>const double eps=1e-8;using namespace std;struct Point{ double x; double y; Point(double x=0,double y=0):x(x),y(y){} void operator<<(Point &A) {cout<<A.x<<' '<<A.y<<endl;}};int dcmp(double x) {return (x>eps)-(x<-eps); }typedef Point Vector;Vector operator +(Vector A,Vector B) { return Vector(A.x+B.x,A.y+B.y);}Vector operator -(Vector A,Vector B) { return Vector(A.x-B.x,A.y-B.y); }Vector operator *(Vector A,double p) { return Vector(A.x*p,A.y*p); }Vector operator /(Vector A,double p) {return Vector(A.x/p,A.y/p);}// ps coutostream &operator<<(ostream & out,Point & P) { out<<P.x<<' '<<P.y<<endl; return out;}bool operator< (const Point &A,const Point &B) { return A.x<B.x||(A.x==B.x&&A.y<B.y); }bool operator== ( const Point &A,const Point &B) { return dcmp(A.x-B.x)==0&&dcmp(A.y-B.y)==0;}double Dot(Vector A,Vector B) {return A.x*B.x+A.y*B.y;}double Cross(Vector A,Vector B) {return A.x*B.y-B.x*A.y; }double Length(Vector A) { return sqrt(Dot(A, A));}double Angle(Vector A,Vector B) {return acos(Dot(A,B)/Length(A)/Length(B));}double Area2(Point A,Point B,Point C ) {return Cross(B-A, C-A);}Vector Rotate(Vector A,double rad) { return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));}Vector Normal(Vector A) {double L=Length(A);return Vector(-A.y/L,A.x/L);}Point GetLineIntersection(Point P,Vector v,Point Q,Vector w){ Vector u=P-Q; double t=Cross(w, u)/Cross(v,w); return P+v*t; }double DistanceToLine(Point P,Point A,Point B){ Vector v1=P-A; Vector v2=B-A; return fabs(Cross(v1,v2))/Length(v2); }double DistanceToSegment(Point P,Point A,Point B){ if(A==B) return Length(P-A); Vector v1=B-A; Vector v2=P-A; Vector v3=P-B; if(dcmp(Dot(v1,v2))==-1) return Length(v2); else if(Dot(v1,v3)>0) return Length(v3); else return DistanceToLine(P, A, B); }Point GetLineProjection(Point P,Point A,Point B){ Vector v=B-A; Vector v1=P-A; double t=Dot(v,v1)/Dot(v,v); return A+v*t;}bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2){ double c1=Cross(b1-a1, a2-a1); double c2=Cross(b2-a1, a2-a1); double c3=Cross(a1-b1, b2-b1); double c4=Cross(a2-b1, b2-b1); return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0 ; }bool OnSegment(Point P,Point A,Point B){ return dcmp(Cross(P-A, P-B))==0&&dcmp(Dot(P-A,P-B))<=0;}double PolygonArea(Point *p,int n){ double area=0; for(int i=1;i<n-1;i++) { area+=Cross(p[i]-p[0], p[i+1]-p[0]); } return area/2; }Point read_point(){ Point P; scanf("%lf%lf",&P.x,&P.y); return P;}int main(){ int T; cin>>T; cout<<"INTERSECTING LINES OUTPUT"<<endl; Point p[4]; while(T--) { for(int i=0;i<4;i++) p[i]=read_point(); if(dcmp(Cross(p[1]-p[0],p[3]-p[2]))!=0) { Point ip=GetLineIntersection(p[0], p[1]-p[0], p[2], p[3]-p[2]); printf("POINT %.2lf %.2lf\n",ip.x,ip.y); } else if(dcmp(Cross(p[1]-p[0],p[3]-p[2]))==0) { if(dcmp(Cross(p[0]-p[2],p[3]-p[2]))==0) { cout<<"LINE"<<endl; } else { cout<<"NONE"<<endl; } } } cout<<"END OF OUTPUT"<<endl; }
0 0
- poj 1269 Intersecting Lines 直线位置关系
- POJ 1269 Intersecting Lines(判断直线的位置关系)
- POJ 1269 Intersecting Lines(直线位置关系,水)
- poj 1269 Intersecting Lines 判断直线的位置关系
- poj 1269 Intersecting Lines (叉积 判断两直线位置关系)
- poj 1269 Intersecting Lines[直线的关系]
- POJ 1269 Intersecting Lines (两直线之间的位置关系)
- POJ 1269 Intersecting Lines(判断两直线的位置关系)
- POJ 1269 Intersecting Lines(判断两条直线的位置关系)
- POJ 1269 Intersecting Lines(判断两条直线关系)
- POJ 1269 Intersecting Lines(判断两直线关系)
- POJ 1269 Intersecting Lines(两直线间关系判定)
- POJ 1269 Intersecting Lines(简单判断直线关系)
- poj 1269 Intersecting Lines 【判断两条直线的关系】
- POJ 1269 Intersecting Lines(两直线间关系判定)
- poj 1269 Intersecting Lines--直线相交
- poj 1269 Intersecting Lines 直线交点
- Poj 1269 Intersecting Lines (直线交点)
- KMP字符串模式匹配详解
- 中美军衔中英文对照表
- Skyline_DateTime
- CXF-RESTFUL入参是复合对象的使用方法(读asopapi有感)
- @queryparam 与 @DefaultValue("name")
- poj 1269 Intersecting Lines 直线位置关系
- 护士资格证考试
- thinking in java——Generics
- thinking in java Generics2
- 金融校园通
- 患伺靥夜厥伦椒狄端刚跃谔炮琢啬
- Skyline_Analysis_CreateFlood
- Struts2输入校验
- 第六周作业——编码实现哈夫曼树