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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; double INF = 1e20; double EPS = 1e-8; bool (double x) { return -EPS < x && x < EPS; } struct CVector{ double x,y; CVector (){} CVector (double tx,double ty){ x=tx;y=ty; } CVector operator +(const CVector &b)const { return CVector(x+b.x,y+b.y); } CVector operator -(const CVector &b)const { return CVector(x-b.x,y-b.y); } double operator ^(const CVector &b)const { return x*b.y-y*b.x; } double operator *(const CVector &b)const { return x*b.x+y*b.y; } CVector operator *(const double k)const { return CVector(k*x,k*y); } }; #define Point CVector struct Line{ Point a,b; Line(){} Line(Point s,Point e) { a = s;b = e; } }; double area(CVector a,CVector b) { return (a^b)/2; } double onLine(Point p,Line l) { return fabs((p-l.a) ^ (l.b-l.a)); } Point intersect(Line l, Line m, int &t) { double x = area(m.a-l.a,l.b-l.a); double y = area(l.b-l.a,m.b-l.a); if(IsZero(x + y)) { if(IsZero(onLine(l.a, m))) t =1; else t =-1; return Point(-1100,-1100); } t=0; return m.a+(m.b-m.a)*(x/(x + y)); } int main() { int n,t; scanf("%d",&n); printf("INTERSECTING LINES OUTPUTn"); Point p,q; for(int i=1;i<=n;i++) { scanf("%lf%lf%lf%lf",&p.x,&p.y,&q.x,&q.y); Line l1(p,q); scanf("%lf%lf%lf%lf",&p.x,&p.y,&q.x,&q.y); Line l2(p,q); Point tmp=intersect(l1,l2,t); if(t==1) printf("LINEn"); else if(t==-1) printf("NONEn"); else printf("POINT %.2lf %.2lfn",tmp.x,tmp.y); } printf("END OF OUTPUTn"); return 0; }
|
近期评论