poj 1269 计算几何


 1 /**
2 判断直线位置关系
3 **/
4 #include <iostream>
5 #include <cmath>
6 #include <cstdio>
7 using namespace std;
8 struct point {
9 double x,y;
10 point(double x=0,double y=0):x(x),y(y){}
11 };
12
13 typedef point Vector;
14
15 Vector operator - (point A,point B){
16 return Vector(A.x-B.x,A.y-B.y);
17 }
18
19 struct line {
20 point a,b;
21 };
22 double length(Vector v){
23 return sqrt(v.x*v.x+v.y*v.y);
24 }
25
26 double cross(Vector A,Vector B){
27 return A.x*B.y-A.y*B.x;
28 }
29
30 double distoline(point P,point A,point B){
31 Vector v1 =B-A,v2 = P-A;
32 return fabs(cross(v1,v2))/length(v1);
33 }
34
35 int main()
36 {
37 int n;
38 cin>>n;
39 line l1,l2;
40 cout<<"INTERSECTING LINES OUTPUT"<<endl;
41 while(n--){
42 cin>>l1.a.x>>l1.a.y>>l1.b.x>>l1.b.y;
43 cin>>l2.a.x>>l2.a.y>>l2.b.x>>l2.b.y;
44 Vector tmp1,tmp2;
45 tmp1.x = l1.b.x-l1.a.x;
46 tmp1.y = l1.b.y-l1.a.y;
47 tmp2.x = l2.b.x-l2.a.x;
48 tmp2.y = l2.b.y-l2.a.y;
49 //cout<<tmp1.x<<" "<<tmp1.y<<endl;
50 //cout<<tmp2.x<<" "<<tmp2.y<<endl;
51 //cout<<cross(tmp1,tmp2)<<endl;
52 if(cross(tmp1,tmp2)==0){
53 if(distoline(l1.a,l2.a,l2.b)==0){
54 cout<<"LINE"<<endl;
55 }else
56 cout<<"NONE"<<endl;
57 }else{
58 double x,y;
59 if(l1.a.x==l1.b.x&&l2.a.x!=l2.b.x){
60 x = l1.a.x;
61 double k = (l2.b.y-l2.a.y)/(l2.b.x-l2.a.x);
62 double b = l2.a.y-k*l2.a.x;;
63 y = k*x+b;
64 }else if(l1.a.x!=l1.b.x&&l2.a.x==l2.b.x){
65 x = l2.a.x;
66 double k = (l1.b.y-l1.a.y)/(l1.b.x-l1.a.x);
67 double b = l1.a.y-k*l1.a.x;
68 y = k*x+b;
69 }else{
70 double k1= (l1.b.y-l1.a.y)/(l1.b.x-l1.a.x);
71 double b1=l1.a.y-k1*l1.a.x;
72 double k2 = (l2.b.y-l2.a.y)/(l2.b.x-l2.a.x);
73 double b2=l2.a.y-k2*l2.a.x;
74 x =(b2-b1)/(k1-k2);
75 y = k1*x+b1;
76 }
77
78 printf("POINT %.2lf %.2lf\n",x,y);
79 }
80 }
81 cout<<"END OF OUTPUT"<<endl;
82 return 0;
83 }

poj 1269 计算几何

时间: 2024-10-14 16:46:15

poj 1269 计算几何的相关文章

poj 1269 线段与线段相交

Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13605   Accepted: 6049 Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three

POJ 1269 Intersecting Lines(线段相交,水题)

Intersecting Lines 大意:给你两条直线的坐标,判断两条直线是否共线.平行.相交,若相交,求出交点. 思路:线段相交判断.求交点的水题,没什么好说的. struct Point{ double x, y; } ; struct Line{ Point a, b; } A, B; double xmult(Point p1, Point p2, Point p) { return (p1.x-p.x)*(p2.y-p.y)-(p1.y-p.y)*(p2.x-p.x); } bool

POJ 2398 计算几何+二分+排序

Toy Storage Time Limit: 1000MS  Memory Limit: 65536K Total Submissions: 3953  Accepted: 2334 Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box t

POJ 1269 两线的关系

Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10967   Accepted: 4930 Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three

POJ 1269

中学的 又用上了. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 5 using namespace std; 6 7 int x1,y1,x2,y2,x3,y3,x4,y4; 8 double k1,k2,k3,d1,d2; 9 double x,y; 10 11 bool asure(){ 12 if(x1==x2||x3==x4){ 13 if(x1==x2&&x3

POJ 3304 计算几何

Segments Time Limit: 1000MS  Memory Limit: 65536K Total Submissions: 9564  Accepted: 2943 Description Given n segments in the two dimensional space, write a program, which determines if there exists a line such that after projecting these segments on

POJ 1269 Intersecting Lines(判断直线相交)

题目地址:POJ 1269 直接套模板就可以了...实在不想自己写模板了...写的又臭又长....不过这题需要注意的是要先判断是否有直线垂直X轴的情况. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h>

poj 1410 计算几何

1 /** 2 注意: 千万得小心..就因为一个分号,调了一个晚上... 3 **/ 4 #include <iostream> 5 #include <algorithm> 6 using namespace std; 7 struct point { 8 int x,y; 9 }; 10 11 struct line{ 12 point a; 13 point b; 14 }; 15 line l,lt;//l 直线 lt 矩形的边 16 int x1,x2,y1,y2; 17

poj 2653 计算几何

1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <cmath> 5 #include <cstdio> 6 using namespace std; 7 struct point { 8 double x,y; 9 }; 10 point be[100005],en[100005]; 11 int ans[100005]; 12 int re