POJ 1269 Intersecting Lines 判断直线相交
2014-11-11 11:01
429 查看
#include "stdio.h" #include "math.h" #define EPS 1e-8 struct point { double x, y; }; struct line { struct point a, b; }; double xProduct(struct point a, struct point b) { return a.x*b.y - a.y*b.x; } void judge(struct line l1, struct line l2) { struct point v1, v2; v1.x = l1.b.x - l1.a.x; v1.y = l1.b.y - l1.a.y; v2.x = l2.b.x - l2.a.x; v2.y = l2.b.y - l2.a.y; double prod = xProduct(v1, v2); if (fabs(prod) < EPS) { struct point v3; v3.x = l2.a.x - l1.a.x; v3.y = l2.a.y - l1.a.y; if (fabs(xProduct(v1, v3)) < EPS) { printf("LINE\n"); } else { printf("NONE\n"); } } else { double a = -v1.y; double b = v1.x; double c = l1.a.y*l1.b.x - l1.a.x*l1.b.y; double d = -v2.y; double e = v2.x; double f = l2.a.y*l2.b.x - l2.a.x*l2.b.y; double y = (c*d - f*a) / (b*d - a*e); double x = (c*e - f*b) / (a*e - b*d); printf("POINT %.2lf %.2lf\n", x, y); } } int main() { printf("INTERSECTING LINES OUTPUT\n"); int t; struct line l1, l2; scanf("%d", &t); while (t--) { scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &l1.a.x, &l1.a.y, &l1.b.x, &l1.b.y, &l2.a.x, &l2.a.y, &l2.b.x, &l2.b.y); judge(l1, l2); } printf("END OF OUTPUT\n"); return 0; }
相关文章推荐
- poj 1269 判断直线相交,并求交点
- POJ 1269 Intersecting Lines 直线相交判断
- POJ 1269 判断直线与直线相交
- 【POJ 1269】判断两直线相交
- POJ 1269 Intersecting Lines(直线相交的判断)
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
- poj 1269Intersecting Lines (直线相交判断,求相交交点)
- POJ 1269 Intersecting Lines(判断直线相交)
- poj 1269 Intersecting Lines(直线相交判断,求相交交点)
- Intersecting Lines(poj1269,判断直线与直线相交)
- POJ 1269 Intersecting Lines 判断直线间的状态(平行、重合、相交于一点)
- POJ 1269 Intersecting Lines(直线相交的判断)
- POJ 1269 Intersecting Lines 判断直线关系(相交(求交点),重合,平行)
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
- poj 1269 Intersecting Lines(判断直线相交 求交点)
- POJ-1269 直线相交的判断及交点
- POJ - 1269:Intersecting Lines__判断两直线相交
- POJ 1269 Intersecting Lines 判断直线关系(相交(求交点),重合,平行)
- POJ 1269 判断直线的关系:相交,平行,重合