Poj 1269 Intersecting Lines (直线交点)
来源:互联网 发布:抹黑中国的网络大v 编辑:程序博客网 时间:2024/06/05 09:30
题意:分别给出两条直线上的两个点,求这两条直线的位置关系,如果相交则输出交点。
思路:利用向量。
#include <cmath>#include <cstdio>#include <cstring>struct Point //点,向量{double x,y;Point(){}Point(double _x,double _y){x=_x;y=_y;}Point operator-(const Point &b)const{return Point(x-b.x,y-b.y);} Point operator+(const Point &b){return Point(x+b.x,y+b.y);} Point operator*(const double k) //数乘 {return Point(x*k,y*k);}double operator*(const Point a) //点乘 {return x*a.x+y*a.y;} double operator^(const Point a) //叉乘 {return x*a.y-y*a.x;}};int DB (double x){if(fabs(x)<1e-6) return 0;return x>0?1:-1;}//求两条直线交点,输入直线1上两点A,B,直线2上两点C,D,点ans保存交点//返回0表示平行//返回1表示重合//返回2表示相交,此时ans会保存交点int Line_cross_line (Point A,Point B,Point C,Point D,Point& ans){ Point AB=B-A;Point AC=C-A;Point AD=D-A;Point CD=D-C;if (DB(AB^CD)==0) //叉乘 { if (DB(AC^AD)==0)return 0; else return 1; } double d=sqrt(AB.x*AB.x+AB.y*AB.y); double s1=AC^AB,s2=AB^AD; double k=s1/(s1+s2); ans=C+CD*k; return 2;}int main (){#ifdef ONLINE_JUDGE#elsefreopen("read.txt","r",stdin);#endifint T;scanf("%d",&T);printf("INTERSECTING LINES OUTPUT\n");while (T--){ Point A,B,C,D,ans; scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&D.x,&D.y); int flag=Line_cross_line(A,B,C,D,ans); if (flag==0) printf("LINE\n"); else if (flag==1) printf("NONE\n"); else printf("POINT %.2lf %.2lf\n",ans.x,ans.y);}printf("END OF OUTPUT\n");return 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 1269Intersecting Lines (直线相交判断,求相交交点)
- POJ 1269 Intersecting Lines(计算几何 直线交点 点在直线上 直线平行)
- POJ 1269 Intersecting Lines(几何 + 直线问题)
- POJ 1269 Intersecting Lines(判断两直线关系)
- POJ 1269 Intersecting Lines(判断直线相交)
- 10 个最佳的免费项目管理工具
- 再来一个!放松一下!
- NLB下设置FTP跨网段不能访问
- 字符雨
- poj 2139 Six Degrees of Cowvin Bacon (Floyd 算法)
- Poj 1269 Intersecting Lines (直线交点)
- 类对象数组初始化(三种方法)
- 如何在改变了html表单里的“提交按钮的背景图片”
- 腾讯敏捷开发及快速迭代
- Android布局 实现圆角边框 tablelayout
- 请定义一个宏,比较两个数a、b的大小,不能使用大于、小于、if语句
- Oracle相关操作总结1
- 归并排序算法
- 如何让你的程序支持HA?