计算几何——直线交点poj1269
求直线交点还是要推一个公式的。。
见博客https://blog.csdn.net/u013050857/article/details/40923789
还要学一下向量的定点比分法
另外poj精度好像卡的厉害,zoj1280就没啥问题
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- #include<algorithm>
- #include<cmath>
- using namespace std;
- const double esp = 1e-;
- const double inf = 1e20;
- const double pi = acos(-1.0);
- const int maxp = ;
- int sgn(double x){
- if(fabs(x) < esp)return ;
- if(x < )return -;
- else return ;
- }
- inline double sqr(double x){return x*x;}
- struct Point{
- double x,y;
- Point(){}
- Point(double _x,double _y):x(_x),y(_y){}
- void input(){scanf("%lf%lf",&x,&y);}
- void output(){printf("%.2lf %.2lf\n",x,y);}
- bool operator==(Point b)const {
- return sgn(x-b.x)== && sgn(y-b.y)==;
- }
- bool operator < (Point b)const {//判左下
- if( sgn(x-b.x)== ) //横坐标相等
- return sgn(y-b.y)<;
- return x<b.x;
- }
- Point operator - (const Point &b)const {
- return Point(x-b.x,y-b.y);
- }
- double operator ^(const Point &b)const {
- return x*b.y-y*b.x;
- }
- double operator *(const Point &b)const {
- return x*b.x+y*b.y;
- }
- double len(){
- return hypot(x,y);
- }
- double len2(){
- return x*x+y*y;
- }
- double distance(Point p){
- return hypot(x-p.x,y-p.y);
- }
- Point operator +(const Point &b)const {
- return Point(x+b.x,y+b.y);
- }
- Point operator *(const double &k)const {
- return Point(x*k,y*k);
- }
- Point operator /(const double &k)const {
- return Point(x/k,y/k);
- }
- double rad(Point a,Point b){
- Point p=*this;
- return fabs(atan2( fabs((a-p)^(b-p)),(a-p)*(b-p) ));
- }
- Point trunc(double r){
- double l=len();
- if(!sgn(l))return *this;
- r/=l;
- return Point(x*r,y*r);
- }
- Point rotleft(){
- return Point(-y,x);
- }
- Point rotright(){
- return Point(y,-x);
- }
- Point rotate(Point p,double angle){
- Point v=(*this)-p;
- double c=cos(angle),s=sin(angle);
- return Point(p.x+v.x*c-v.y*s, p.y+v.x*s+v.y*c);
- }
- };
- struct Line{
- Point s,e;
- Line(){}
- Line(Point s,Point e):s(s),e(e){}
- bool operator ==(Line v){
- return (s==v.s) && (e==v.e);
- }
- Line(Point p,double angle){
- s=p;
- if(sgn(angle-pi/)==)
- e=s+Point(,);
- else e=s+Point(,tan(angle));
- }
- Line(double a,double b,double c){
- if(sgn(a)==){
- s=Point(,-c/b);
- e=Point(,-c/b);
- }
- else if(sgn(b)==){
- s=Point(-c/a,);
- e=Point(-c/a,);
- }
- else {
- s=Point(,-c/b);
- e=Point(,(-c-a)/b);
- }
- }
- void input(){
- s.input();
- e.input();
- }
- void adjust(){
- if(e<s)swap(e,s);
- }
- double length(){
- return s.distance(e);
- }
- double angle(){
- double k=atan2(e.y-s.y,e.x-s.x);
- if(sgn(k)<)k+=pi;
- if(sgn(k-pi)==) k-=pi;
- return k;
- }
- int relation(Point p){
- int c=sgn((p-s)^(e-s));
- if(c<)return ;
- else if(c>)return ;
- else return ;
- }
- bool pointonseg(Point p){
- return sgn((p-s)^(e-s))== && sgn((p-s)*(p-e))<=;
- }
- bool parallel(Line v){
- return sgn((e-s)^(v.e-v.s))==;
- }
- int segcrossseg(Line v){
- int d1=sgn((e-s)^(v.s-s));
- int d2=sgn((e-s)^(v.e-s));
- int d3=sgn((v.e-v.s)^(s-v.s));
- int d4=sgn((v.e-v.s)^(e-v.s));
- if( (d1^d2)==- && (d3^d4)==-) return ;
- return (d1== && sgn((v.s-s)*(v.s-e))<=) ||
- (d2== && sgn((v.e-s)*(v.e-e))<=) ||
- (d3== && sgn((s-v.s)^(s-v.e))<=) ||
- (d4== && sgn((e-v.s)^(e-v.e))<=);
- }
- int linecrossseg(Line v){
- int d1=sgn((e-s)^(v.s-s));
- int d2=sgn((e-s)^(v.e-s));
- //cout<<(d1^d2)<<'\n';
- if((d1^d2)==-)return ;
- return d1== || d2==;
- }
- int linecrossline(Line v){
- if((*this).parallel(v))
- return v.relation(s)==;
- return ;
- }
- Point crosspoint(Line v){
- double a1=(v.e-v.s)^(s-v.s);//面积
- double a2=(v.e-v.s)^(e-v.s);
- return Point((s.x*a2-e.x*a1)/(a2-a1),
- (s.y*a2-e.y*a1)/(a2-a1));
- }
- double dispointtoline(Point p){
- return fabs((p-s)^(e-s))/length();
- }
- double dispointtoseg(Point p){
- if(sgn((p-s)*(e-s))< || sgn((p-e)*(s-e))<)
- return min(p.distance(s),p.distance(e));
- return dispointtoline(p);
- }
- double dissegtoseg(Line v){
- return min(min(dispointtoseg(v.s),dispointtoseg(v.e)),
- min(v.dispointtoline(s),v.dispointtoline(e)));
- }
- Point lineprog(Point p){//s+vt
- return s+( ((e-s)*((e-s)*(p-s)))/(e-s).len2() );
- }
- Point symmetrypoint(Point p){
- Point q=lineprog(p);
- return Point(*q.x-p.x,*q.y-p.y);
- }
- };
- //判两直线是否相交
- int main(){
- int t;cin>>t;
- puts("INTERSECTING LINES OUTPUT");
- for(int tt=;tt<=t;tt++){
- double x1,y1,x2,y2;
- cin>>x1>>y1>>x2>>y2;
- Line line1=Line(Point(x1,y1),Point(x2,y2));
- cin>>x1>>y1>>x2>>y2;
- Line line2=Line(Point(x1,y1),Point(x2,y2));
- if(line1.linecrossline(line2)==)
- puts("NONE");
- else if(line1.linecrossline(line2)==)
- puts("LINE");
- else if(line1.linecrossline(line2)==){
- Point p=line1.crosspoint(line2);
- printf("POINT %.2lf %.2lf\n",p.x,p.y);
- }
- }
- puts("END OF OUTPUT");
- }
计算几何——直线交点poj1269的更多相关文章
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)
Area Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- UVA 11178 Morley's Theorem(旋转+直线交点)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18543 [思路] 旋转+直线交点 第一个计算几何题,照着书上代码打 ...
- POJ_1269_Intersecting Lines_求直线交点
POJ_1269_Intersecting Lines_求直线交点 Description We all know that a pair of distinct points on a plane ...
- ZOJ 1280 Interesting Lines | 求两直线交点
原题: 求两直线交点 思路借鉴于:http://blog.csdn.net/zxy_snow/article/details/6341282 感谢大佬 #include<cstdio> # ...
- 2017 ACM-ICPC乌鲁木齐网络赛 B. Out-out-control cars(计算几何 直线相交)
题目描述 Two out-of-control cars crashed within about a half-hour Wednesday afternoon on Deer Park Avenu ...
- hdu 1086 You can Solve a Geometry Problem too 求n条直线交点的个数
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- poj1269(直线交点)
传送门:Intersecting Lines 题意:给出N组直线,每组2条直线,求出直线是否相交.如果共线则输出LINE,相交则输入点坐标,否则输出NONE. 分析:模板裸题,直接上模板... #in ...
- poj1269计算几何直线和直线的关系
We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a p ...
随机推荐
- LNMP之PHP
PHP LNMP环境下的PHP安装 CGI指的是通用网关接口,为HTTP服务器与其他机器上的程序服务通信交流的一种工具,性能差,所以被淘汰了. FastCGI,是一个可以伸缩.高速的在HTTP服务器和 ...
- projects
layout title project 开源项目 本文记录我收藏的开源项目
- C#反射从入门到放弃(这部分遇到的新东西太多了让人接受不能)
首先,我们需要知道type,type是类型的类型(笑 官方点的说法是,BCL声明了一个Type抽象类,它被设计用来包含类型的特性, 使用这个类的对象(抽象类的对象?这显然是错误的,但是这里用的其实是T ...
- python编程语言学习day02
格式化输出 (1)info 格式 (2)%字符串占位 %s 表示字符串占位 %d 表示整数占位 %f 表示浮点数占位 中间的% 之后是所需要输入的值 多个占位, % 之后用()括号括起 ...
- jQuery - 动画相关
// 显示隐藏 $("div").show(); // 显示 $("div").hide(); // 隐藏 // 显示过程3秒, 3秒之内, 元素的宽,高和透明 ...
- mui请求数据接口问题
今天我在本地模拟做一个数据请求,第一次用的mui自带的方法来请求数据,当时我的本地接口地址是http://localhost:8087/jeecg/sightseerController.do?che ...
- 通过队列实现进程间的通信(使用阻塞方式调用func函数)
#_author:来童星#date:2019/12/17#通过队列实现进程间的通信from multiprocessing import Poolimport osimport timedef fun ...
- windows启动redis失败
# Warning: no config file specified, using the default config. In order to specify a config file use ...
- NX二次开发-UFUN设置工程图PNG图片高度UF_DRF_set_image_height
#include <uf.h> #include <uf_drf.h> UF_initialize(); //插入PNG char* file_name = "D:\ ...
- faster-rcnn代码阅读-rpn-data层
这一节讲述rpn-data层,和这一层有关的结构图如下: rpn-data层的prototxt定义如下: layer { name: 'rpn-data' type: 'Python' bottom: ...