zoj 1280 Intersecting Lines(两直线交点)

题意:n组数据,每组两条直线两端点坐标,判断线段平行、重合,相交;

思路:利用叉积跨立实验判断重合与平行,交点公式求交点;zoj过了,可是poj1269过不了,不知道为什么。。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const double epsi=1e-10;
inline int sign(const double &x){
    if(x>epsi) return 1;
    if(x<-epsi) return -1;
    return 0;
}
struct point{
    double x,y;
    point(double xx=0,double yy=0):x(xx),y(yy){}
    point operator -(const point &op2) const{
        return point(x-op2.x,y-op2.y);
    }
    double operator ^(const point &op2) const{
        return x*op2.y-y*op2.x;
    }
};
inline double sqr(const double &x){
    return x*x;
}
inline double mul(const point &p0,const point &p1,const point &p2){
    return (p1-p0)^(p2-p0);
}
inline double dis2(const point &p0,const point &p1){
    return sqr(p0.x-p1.x)+sqr(p0.y-p1.y);
}
inline double dis(const point &p0,const point &p1){
    return sqrt(dis2(p0,p1));
}
inline int cross(const point &p1,const point &p2,const point &p3,const point &p4,point &p){
    double a1=mul(p1,p2,p3),a2=mul(p1,p2,p4);
    if(sign(a1)==0&&sign(a2)==0) return 2;//重叠
    if(sign(a1-a2)==0) return 0;
    p.x=(a2*p3.x-a1*p4.x)/(a2-a1);
    p.y=(a2*p3.y-a1*p4.y)/(a2-a1);    //利用公式计算交点
    return 1;
}
point p1,p2,p3,p4,p;
int main()
{
   int test=0;
   scanf("%d",&test);
   printf("INTERSECTING LINES OUTPUT\n");
   while(test--){
     scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y,&p4.x,&p4.y);
     int m=cross(p1,p2,p3,p4,p);
     if(m==0) printf("NONE\n");
     else if(m==2) printf("LINE\n");
     else  printf("POINT %.2lf %.2lf\n",p.x,p.y);
   }
   printf("END OF OUTPUT\n");
   return 0;
}
时间: 2024-07-30 00:40:40

zoj 1280 Intersecting Lines(两直线交点)的相关文章

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

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

编程求取直线一般式表达式,两直线交点

背景介绍 ??最近在水面无人艇(USV)模拟仿真中,用到了一些点和线的关系求解,本文主要讲述一下两点确认直线,点到直线距离,两条直线的交点等问题的解决方法,并给出python程序.部分内容非原创,文中给出链接,需要者可以参考. 两点确定直线 表达式定义 ??空间直线的表达式有多种,比如一般式Ax+By+C=0.点斜式y-y0=k(x-x0).截距式x/a+y/b=1.两点式:(y-y1)/(y1-y2)=(x-x1)/(x1-x2)等,它们具有彼此的约束条件,如下所示. ??由上可以看出来,一般

Fermat Point in Quadrangle(hdu 3694 求两直线交点

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3694 画几个图应该就可以知道凸四边形就是对角线交点 凹四边形就是凹进去的那个点 so 只要枚举四个点以及对角线交点 找个minn就可以 求两直线交点模板: double cross(double x1,double y1,double x2,double y2) { return x1*y2-x2*y1; } bool getcross(double x1,double y1,double x2,d

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

题目链接:POJ 1269 Problem 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 ways: 1) no intersection because they are parallel, 2) intersect in a line becau

POJ1269 Intersecting Lines[线段相交 交点]

Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15145   Accepted: 6640 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

题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /************************************************ * Author :Running_Time * Created Time :2015/10/24 星期六 09:08:55 * File Name :POJ_1269.cpp *********************************

n条直线交点拟合求交点

直线方程的公式有以下几种形式: 斜截式:y=kx+b 截距式:x/a+y/b=1 两点式:(x-x1)/(x2-x1)=(y-y1)/(y2-y1) 一般式:ax+by+c=0(可以表达任意直线) 只要知道两点坐标,代入任何一种公式,都可以求出直线的方程 一般式方程在计算机领域的重要性 常用的直线方程有一般式 点斜式 截距式 斜截式 两点式等等.除了一般式方程,它们要么不能支持所有情况下的直线(比如跟坐标轴垂直或者平行),要么不能支持所有情况下的点(比如x坐标相等,或者y坐标相等).所以一般式方

POJ 1127 Jack Straws ( 求直线交点, 判断线段是否相交(含端点) )

题目:传送门 题意: 给你 n 条线段的两个端点, 然后有多次询问, 每次询问, 问你线段 x 和 线段 y 是否相交. 若线段 A 和线段 B 相交且线段 A 和线段 C 相交,那么线段 B 和线段 C 相交.     1 < n < 13 题解: 暴力求线段是否相交, 然后再跑个 Floyd 或者并查集都可以的. #include <iostream> #include <stdio.h> #include <string.h> #include <

POJ1269:Intersecting Lines(判断两条直线的关系)

题目:POJ1269 题意:给你两条直线的坐标,判断两条直线是否共线.平行.相交,若相交,求出交点. 思路:直线相交判断.如果相交求交点. 首先先判断是否共线,之后判断是否平行,如果都不是就直接求交点了. #include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #include <math.h> #include <queue> #