Problem Intersecting Lines (POJ 1269)

题目大意

  给定两条直线,问两条直线是否重合,是否平行,或求出交点。

解题分析

  主要用叉积做,可以避免斜率被0除的情况。

  求交点P0: 已知P1 P2 P3 P4

  运用 P0P1 X P0P2 = 0 和 P0P3 X P0P4 = 0

  C++ 用%.2lf g++ 用 %.2f!!!

  C++ 用%.2lf g++ 用 %.2f!!!

  C++ 用%.2lf g++ 用 %.2f!!!

参考程序

 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; #define eps 1e-8 struct P{
double x,y; P(){}
P(double x,double y):x(x),y(y){} friend P operator +(P a,P b){
return P(a.x+b.x,a.y+b.y);
}
friend P operator -(P a,P b){
return P(a.x-b.x,a.y-b.y);
}
friend double operator *(P a,P b){
return a.x * b.y - a.y * b.x ;
}
friend double operator /(P a,P b){
return a.x * b.x + a.y * b.y ;
}
friend bool operator ==(P a,P b){
return fabs(a.x-b.x)<eps && fabs(a.y-b.y)<eps;
}
friend bool operator !=(P a,P b){
return !(a==b);
}
friend bool operator <(P a,P b){
if (fabs(a.y-b.y)<eps) return a.x<b.x;
return a.y<b.y;
}
friend double turn(P a,P b,P c){ //向量AB X 向量AC
return (b-a)*(c-a);
}
friend void print(P a){
printf("%.2lf %.2lf\n",a.x,a.y);
}
}; struct L{
P a,b;
L(){}
L(P a,P b):a(a),b(b){}
friend P subl(L a){ //向量l
return P(a.b.x-a.a.x,a.b.y-a.a.y);
}
}; bool online(L l,P p){
if (fabs(turn(l.a,l.b,p))<eps) return ;
return ;
}
P solve(double a1,double b1,double c1,double a2,double b2,double c2){
P a;
a.x = (b1*c2-b2*c1)/(a1*b2-a2*b1);
a.y = (a1*c2-a2*c1)/(a2*b1-a1*b2);
return a;
}
void check(L lx,L ly){
if (online(lx,ly.a) && online(lx,ly.b)) printf("LINE\n"); else
if (fabs(subl(lx)*subl(ly))<eps) printf("NONE\n"); else
{
double x1=lx.a.x , y1=lx.a.y;
double x2=lx.b.x , y2=lx.b.y;
double x3=ly.a.x , y3=ly.a.y;
double x4=ly.b.x , y4=ly.b.y;
double a1 = y1 - y2 , b1 = x2 - x1 , c1 = x1*y2 - x2*y1 ;
double a2 = y3 - y4 , b2 = x4 - x3 , c2 = x3*y4 - x4*y3 ;
printf("POINT ");
print(solve(a1,b1,c1,a2,b2,c2));
}
} int main(){
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%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
P a(x1,y1),b(x2,y2),c(x3,y3),d(x4,y4);
L lx(a,b),ly(c,d);
check(lx,ly);
}
printf("END OF OUTPUT\n");
}

POJ 1269 (直线求交)的更多相关文章

  1. POJ 1269 (直线相交) Intersecting Lines

    水题,以前总结的模板还是很好用的. #include <cstdio> #include <cmath> using namespace std; ; int dcmp(dou ...

  2. poj 1269 直线间的关系

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9360   Accepted: 421 ...

  3. POJ 1269 Intersecting Lines 直线交

    不知道谁转的计算几何题集里面有这个题...标题还写的是基本线段求交... 结果题都没看就直接敲了个线段交...各种姿势WA一遍以后发现题意根本不是线段交而是直线交...白改了那个模板... 乱发文的同 ...

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

    题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...

  5. 判断两条直线的位置关系 POJ 1269 Intersecting Lines

    两条直线可能有三种关系:1.共线     2.平行(不包括共线)    3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...

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

    题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...

  7. 直线相交 POJ 1269

    // 直线相交 POJ 1269 // #include <bits/stdc++.h> #include <iostream> #include <cstdio> ...

  8. OpenCASCADE直线与平面求交

    OpenCASCADE直线与平面求交 在<解析几何>相关的书中都给出了直线和平面的一般方程和参数方程.其中直线的一般方程有点向式形式的. 由于过空间一点可作且只能作一条直线平行于已知直线, ...

  9. HDU - 3982:Harry Potter and J.K.Rowling(半平面交+圆与多边形求交)(WA ing)

    pro:给定一枚蛋糕,蛋糕上某个位置有个草莓,寿星在上面切了N刀,最后寿星会吃含有草莓的那一块蛋糕,问他的蛋糕占总蛋糕的面积比. sol:显然需要半平面交求含有蛋糕的那一块,然后有圆弧,不太方便求交. ...

随机推荐

  1. PHP——字符串统一转码为GBK,自动判断是否UTF8并转码

    public static function strToGBK($strText) { $encode = mb_detect_encoding($strText, array('UTF-8','GB ...

  2. C#WPF做FTP上传下载获取文件列表

    Xaml.cs: using Microsoft.Win32;using System;using System.Collections.Generic;using System.IO;using S ...

  3. BZOJ4002 [JLOI2015]有意义的字符串

    据说这两场加起来只要170= =而这是最简单的题目了QAQ 看到$(\frac {b + \sqrt {d} } {2} )^n$,第一反应是共轭根式$(\frac {b - \sqrt {d} } ...

  4. Mysql date_sub函数使用

    mysql中内置函数date_add和date_sub能对指定的时间进行增加或减少一个指定的时间间隔,语法如下: DATE_ADD(date,INTERVAL expr type) DATE_SUB( ...

  5. 创建论坛Discuz

    下载discuz! mkdir /data/wwwcd /data/wwwwget  http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GB ...

  6. 基于TCP的通信 客户端

    #include <WINSOCK2.H> #include <stdio.h> // socket 套接字 #pragma comment (lib,"Ws2_32 ...

  7. Black 全面分析

    Black 全面分析 如果有Block语法不懂的,可以参考fuckingblocksyntax,里面对于Block 为了方便对比,下面的代码我假设是写在ViewController子类中的 1.第一部 ...

  8. struts2 ModelDriven 和 Preparable 拦截器

    Struts2 运行流程图-1

  9. jquery easyui DataGrid 动态的改变列显示的顺序

    $.extend($.fn.datagrid.methods,{ columnMoving: function(jq){ return jq.each(function(){ var target = ...

  10. HDU 5439 Aggregated Counting

    题目大意: 由1开始不断往数组中添加数 就是按照当前所在位置所在的数表示的个数添加这个数目的数 1 2 2 3 3 后面因为要填4,而4号位置为3,说明之后要填3个4 问题就是给定一个n,找到n出现的 ...