Intersecting Lines POJ - 1269

Posted vampire6

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Intersecting Lines POJ - 1269相关的知识,希望对你有一定的参考价值。

Intersecting Lines

题目链接:https://vjudge.net/problem/POJ-1269

题目:

技术图片

 

技术图片

 

技术图片

 

 

 题意:判断给出的两条线是否相等平行还是相交,若相交求出交点坐标。。水题坑点就是提交G++WA,而提交C++A了,,

 1 // 
 2 // Created by HJYL on 2020/1/13.
 3 //
 5 #include<iostream>
 6 #include<cstring>
 7 #include<cstdio>
 8 #include<cmath>
 9 #define eps 1e-6
10 using namespace std;
11 struct Point
12 {
13     double x,y;
14 };
15 struct Line
16 {
17     double a,b,c,angle;
18     Point p1,p2;
19     Line(Point s,Point e)
20     {
21         a=s.y-e.y;
22         b=e.x-s.x;
23         c=s.x*e.y-e.x*s.y;
24         angle=atan2(e.y-s.y,e.x-s.x);
25         p1=s;p2=e;
26     }
27     Line(){}
28 };
29 Point sub(Point a,Point b)
30 {
31     Point t;
32     t.x=a.x-b.x;
33     t.y=a.y-b.y;
34     return t;
35 }
36 double Cross(Point a,Point b)
37 {
38     return a.x*b.y-b.x*a.y;
39 }
40 
41 double turn(Point p1,Point p2,Point p3)
42 {
43     return Cross(sub(p2,p1),sub(p3,p1));
44 }
45 
46 bool IsEqual(Line a,Line b)
47 {
48     if(fabs(turn(a.p1,a.p2,b.p1)*turn(a.p1,a.p2,b.p2))>eps)return 0;
49     if(fabs(turn(b.p1,b.p2,a.p1)*turn(b.p1,b.p2,a.p2))>eps)return 0;
50     return 1;
51 }
52 bool IsParallel(Line a,Line b)
53 {
54     if(fabs(Cross(sub(a.p1,a.p2),sub(b.p1,b.p2)))<eps)return 1;
55     return 0;
56 }
57 Point Intersection(Line a,Line b)
58 {
59     double k1,k2,t;
60     k1=Cross(sub(a.p2,b.p1),sub(b.p2,b.p1));
61     k2=Cross(sub(b.p2,b.p1),sub(a.p1,b.p1));
62     t=k1/(k1+k2);
63     Point ans;
64     ans.x=a.p2.x+(a.p1.x-a.p2.x)*t;
65     ans.y=a.p2.y+(a.p1.y-a.p2.y)*t;
66     return ans;
67 }
68 int main()
69 {
70     //freopen("text","r",stdin);
71     int T;
72     scanf("%d",&T);
73     printf("INTERSECTING LINES OUTPUT
");
74     Line s1,s2;
75     while(T--)
76     {
77         scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&s1.p1.x,&s1.p1.y,&s1.p2.x,&s1.p2.y,&s2.p1.x,&s2.p1.y,&s2.p2.x,&s2.p2.y);
78         if(IsEqual(s1,s2))
79             printf("LINE
");
80         else if(IsParallel(s1,s2))
81             printf("NONE
");
82         else
83         {
84             Point cc=Intersection(s1,s2);
85             printf("POINT %.2lf %.2lf
",cc.x,cc.y);
86         }
87     }
88     printf("END OF OUTPUT
");
89     return 0;
90 
91 }

 

 

 

以上是关于Intersecting Lines POJ - 1269的主要内容,如果未能解决你的问题,请参考以下文章

POJ 1269 Intersecting Lines (判断直线位置关系)

●POJ 1269 Intersecting Lines

POJ1269 Intersecting Lines[线段相交 交点]

Intersecting Lines POJ - 1269

[POJ 1269]Intersecting Lines

POJ_1269_Intersecting Lines_求直线交点