计算几何基础 POJ 1269 Intersecting Lines 【直线相交判断,求交点】

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn=1e5+50;
const double eps=1e-8;
typedef long long ll;
struct point
{
    double x,y;
    point(double _X=0,double _Y=0)
    {
        x=_X;y=_Y;
    }
    point operator - (const point &oth)const
    {
        return point(x-oth.x,y-oth.y);
    }
        point operator + (const point &oth)const
    {
        return point(x+oth.x,y+oth.y);
    }
        point operator * (const double oth)const
    {
        return point(x*oth,y*oth);
    }
        point operator / (const double oth)const
    {
        return point(x/oth,y/oth);
    }
};
int dcmp(double x)
{
    if(fabs(x)<eps)return 0;
    else return x<0?-1:1;
}
double cross(point a,point b)
{
    return a.x*b.y-b.x*a.y;
}
point glt(point a,point a1,point b,point b1)
{
    point v= a1-a;
    point w=b1-b,u = a-b;
    double t = cross(w,u)/cross(v,w);
    return a+v*t;
}
int main()
{
    //freopen("d://duipai//data.txt","r",stdin);
    //freopen("d://duipai//out1.txt","w",stdout);
    int T;
    scanf("%d",&T);
    printf("INTERSECTING LINES OUTPUT\n");
    while(T--)
    {
        double x1,y1,x2,y2,x3,y3,x4,y4;
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
        scanf("%lf%lf%lf%lf",&x3,&y3,&x4,&y4);
        point a,b,c,d;
        a=point(x1,y1);
        b=point(x2,y2);
        c=point(x3,y3);
        d=point(x4,y4);

        if(cross(b-a,d-c))
        {
            point t=glt(a,b,c,d);
            printf("POINT %.2lf %.2lf\n",t.x,t.y);

        }
        else
        {
            if(!cross(b-a,c-b)) puts("LINE");
            else puts("NONE");
        }
    }
    printf("END OF OUTPUT\n");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值