POJ1269解题报告

版权声明:仅供研究,转载请注明出处。 https://blog.csdn.net/CSUstudent007/article/details/83448956

 利用叉乘:https://blog.csdn.net/zxy_snow/article/details/6341282

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream> 
using namespace std;
#define abs(x) ((x)>0?(x):-(x))
#define inf 1e-8
struct line
{
    double a,b,c,d;
}a,b;
double x,y;
void intersection()
{
    double a1=a.b-a.d,b1=a.c-a.a,c1=a.a*a.d-a.c*a.b;
    double a2=b.b-b.d,b2=b.c-b.a,c2=b.a*b.d-b.c*b.b;
    x=(c1*b2-c2*b1)/(a2*b1-a1*b2);
    y=(a2*c1-a1*c2)/(a1*b2-a2*b1);
}
int main()
{
    int t;
    cout<<"INTERSECTING LINES OUTPUT"<<endl;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.a,&a.b,&a.c,&a.d,&b.a,&b.b,&b.c,&b.d);
        if(abs((a.a-a.c)*(b.b-b.d)-(a.b-a.d)*(b.a-b.c))<inf)//判断是否平行
        {
            if(abs((a.c-a.a)*(b.b-a.b)-(a.d-a.b)*(b.a-a.a))<inf)//判断是否共线
               cout<<"LINE"<<endl;
            else
               cout<<"NONE"<<endl;
        }
        else
        {
            intersection();//计算交点
            printf("POINT %.2f %.2f\n",x,y);
        }
    }
    cout<<"END OF OUTPUT"<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/CSUstudent007/article/details/83448956