Poj_1269 Intersecting Lines -判两直线状态(水题、坑OJ)

题意:判直线相交、平行、重合

吐槽:坑OJ,G++WA,C++AC,模版题

/************************************************
Author        :DarkTong
Created Time  :2016/8/3 23:02:25
File Name     :Poj_1269.cpp
*************************************************/

//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define eps 1e-9
typedef long long LL;
typedef double Db;
struct Point
{
    Db x, y;
    Point(Db x=0, Db y=0):x(x), y(y){}
}C;
typedef Point Vector;
//向量或点的四则运算
Vector operator + (Vector A, Vector B){ return Vector(A.x+B.x, A.y+B.y);}
Vector operator - (Vector A, Vector B){ return Vector(A.x-B.x, A.y-B.y);}
Vector operator * (Vector A, Db p){ return Vector(A.x*p, A.y*p);}
Vector operator / (Vector A, Db p){ return Vector(A.x/p, A.y/p);}
int dcmp(Db x){    if(fabs(x)<eps) return 0; else return x<0 ? -1 : 1;}
Db Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y;}    /*点积: 角度分布:>0(-90, 90), ==0(90或-90), <0((-180,90)或(90,180])*/
Db Cross(Vector A, Vector B){ return A.x*B.y - A.y*B.x;}    /*叉积(判<180的角): ==0(共线), >0(逆时针), <0(顺时针)  */
Point GetLineIntersection(Point P, Vector v, Point Q, Vector w)
{
    Vector u = P-Q;
    double t = Cross(w, u)/Cross(v, w); //刚好时两个向量同向,所以不用取绝对值
    return P+v*t;
}
/**************************************************************/
Point poi[4];

int main()
{
    int T, cas=1;
    scanf("%d", &T);
    puts("INTERSECTING LINES OUTPUT");
    while(T--)
    {
        for(int i=0;i<4;++i) scanf("%lf%lf", &poi[i].x, &poi[i].y);
        Vector v1 = poi[1]-poi[0], v2 = poi[3]-poi[2];
        if(dcmp(Cross(v1, v2))==0)
        {
            if(dcmp(Cross(poi[0]-poi[2], v1))==0) puts("LINE");
            else puts("NONE");
        }
        else 
        {
            Point t = GetLineIntersection(poi[0], v1, poi[2], v2);
            printf("POINT %.2lf %.2lf\n", t.x, t.y);
        }
    }
    puts("END OF OUTPUT");
    
    return 0;
}

转载于:https://www.cnblogs.com/DarkTong/p/5735040.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值