poj 1269 Intersecting Lines
2013-07-15 15:45
176 查看
这是很基础的计算几何的题目。
两直线判交,有交点就输出交点,没有交点共线或重合则输出相应的结果。
题目链接:http://poj.org/problem?id=1269
两直线判交,有交点就输出交点,没有交点共线或重合则输出相应的结果。
题目链接:http://poj.org/problem?id=1269
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #define eps 1e-8 using namespace std; struct Point// { double x, y; Point(){}; Point(double x, double y):x(x), y(y){}; }a[105], b[105]; //直线相交,平行返回0 重合返回1 相交返回2,有交点则存在p中 int jiaodian(Point a, Point b, Point c, Point d, Point &p) { double A1=b.y-a.y,A2=d.y-c.y,B1=a.x-b.x,B2=c.x-d.x; double C1=b.y*(b.x-a.x)-b.x*(b.y-a.y),C2=d.y*(d.x-c.x)-d.x*(d.y-c.y); if(A1*B2==B1*A2)//平行或重合 { if(A2*C1==A1*C2&&B1*C2==B2*C1) return 1;//重合 return 0;//平行 } p.x=(B1*C2-B2*C1)/(B2*A1-B1*A2); p.y=(A1*C2-A2*C1)/(A2*B1-A1*B2); return 2;//相交 } int main() { int Case; Point a, b, c, d, p; scanf("%d",&Case); printf("INTERSECTING LINES OUTPUT\n"); while (Case--) { 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); if (jiaodian(a, b, c, d, p) == 0) printf("NONE\n"); else if (jiaodian(a, b, c, d, p) == 1) printf("LINE\n"); else if (jiaodian(a, b, c, d, p) == 2) printf("POINT %.2f %.2f\n", p.x, p.y); } printf("END OF OUTPUT\n"); return 0; }
相关文章推荐
- poj1269 Intersecting Lines
- POJ 1269 判断直线和直线关系
- poj 1269 Intersecting Lines 判断两线段是否相交并求其交点
- poj解题报告——1269
- 计算两直线的交点 poj 1269 我的第一道几何题
- POJ 1269 Intersecting Lines 直线相交判断
- poj 1269 zoj 1280 Intersecting Lines
- POJ 1269 Intersecting Lines
- (计算几何step8.1.2.2)POJ 1269 Intersecting Lines(使用叉积来计算两条直线的交点)
- 【计算几何】 poj1269 Intersecting Lines
- POJ 1269
- POJ 1269直线相交
- 有向图和无向图的连通性学习小记 Poj 1269 迷宫城堡
- POJ 1269 Intersecting Lines 判断两直线关系
- POJ 1269(直线的交点)
- poj 1269 Intersecting Lines 直线交点
- POJ 1269 Intersecting Lines(判断两直线的位置关系)
- [POJ1269]Intersecting Lines(计算几何)
- POJ 1269 Intersecting Lines(判断两条直线的位置关系)
- POJ 1269 Intersecting Lines(计算几何)