POJ1410 Intersection 计算几何
题目大意:给出一个线段的两端,和矩形两端(不一定是左上和右下),问线段是否与矩形相交(若线段在矩形内也算相交)。这题蒸鹅心……
题目思路:判断所有情况:线段是否在矩形内,线段内一点是否在矩形内,线段是否与四边相交(叉积),线段的两端是否在矩形上,矩形的四点是否在线段上。
要注意的是:
1.如果两条线段的叉积为0,也可能共线但不相交。
2.判断点在线段上的方法:叉积为0,且到两点的距离与线段等长。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define MAXSIZE 100005
#define INF 0x3f3f3f3f
#define LL long long using namespace std; //给出一个线段的两端,和矩形两端(不一定是左上和右下),问线段是否与矩形相交(若线段在矩形内也算相交)。这题蒸鹅心…… int px1,py1,px2,py2,lx,ly,rx,ry; int Cross(int x1,int y1,int x2,int y2,int x3,int y3)
{
return (x1-x2)*(y2-y3)-(x2-x3)*(y1-y2);
} int Check(int x1,int y1,int x2,int y2)
{
int op1=Cross(px1,py1,x1,y1,x2,y2)*Cross(px2,py2,x1,y1,x2,y2);
int op2=Cross(x1,y1,px1,py1,px2,py2)*Cross(x2,y2,px1,py1,px2,py2);
if(op1< && op2 <)
return ;
return ;
} int Dist(int x1,int y1,int x2,int y2,int x3,int y3)
{
double d1=sqrt((x2-x1)*(x2-x1)*1.0+(y2-y1)*(y2-y1)*1.0);
double d2=sqrt((x3-x1)*(x3-x1)*1.0+(y3-y1)*(y3-y1)*1.0);
double d3=sqrt((x3-x2)*(x3-x2)*1.0+(y3-y2)*(y3-y2)*1.0);
if(fabs(d1+d2-d3) < 1e-)
return ;
return ;
} int Solve()
{
//线段是否在圆内
if(px1>=lx && px1<=rx && py1<=ly && py1>=ry)
return ;
if(px2>=lx && px2<=rx && py2<=ly && py2>=ry)
return ;
//四角是否在线段上
if(Cross(lx,ly,px1,py1,px2,py2)== && Dist(lx,ly,px1,py1,px2,py2))
return ;
if(Cross(lx,ry,px1,py1,px2,py2)== && Dist(lx,ry,px1,py1,px2,py2))
return ;
if(Cross(rx,ry,px1,py1,px2,py2)== && Dist(rx,ry,px1,py1,px2,py2))
return ;
if(Cross(rx,ly,px1,py1,px2,py2)== && Dist(rx,ly,px1,py1,px2,py2))
return ;
//线段是否平行与边且覆盖
if(Cross(px1,py1,lx,ly,lx,ry)== && Cross(px2,py2,lx,ly,lx,ry)== && Dist(lx,ly,px1,py1,px2,py2))
return ;
if(Cross(px1,py1,lx,ry,rx,ry)== && Cross(px2,py2,lx,ry,rx,ry)== && Dist(lx,ry,px1,py1,px2,py2))
return ;
if(Cross(px1,py1,rx,ry,rx,ly)== && Cross(px2,py2,rx,ry,rx,ly)== && Dist(rx,ry,px1,py1,px2,py2))
return ;
if(Cross(px1,py1,rx,ly,lx,ly)== && Cross(px2,py2,rx,ly,lx,ly)== && Dist(rx,ly,px1,py1,px2,py2))
return ;
//线段是否与矩形边相交
if(Check(lx,ry,lx,ly))
return ;
if(Check(lx,ry,rx,ry))
return ;
if(Check(rx,ry,rx,ly))
return ;
if(Check(rx,ly,lx,ly))
return ;
return ;
} int main()
{
int T,x1,y1,x2,y2;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d%d%d%d%d",&px1,&py1,&px2,&py2,&x1,&y1,&x2,&y2);
lx=min(x1,x2);
ly=max(y1,y2);
rx=max(x1,x2);
ry=min(y1,y2);
int op=Solve();
if(!op)
printf("F\n");
else
printf("T\n");
}
return ;
}
POJ1410 Intersection 计算几何的更多相关文章
- POJ 1410 Intersection (计算几何)
题目链接:POJ 1410 Description You are to write a program that has to decide whether a given line segment ...
- poj-1410 Intersection
计算几何的题目, 学cv的要做一下.poj 地址: http://poj.org/problem?id=1410 题意:判断一个直线段,是否与一个矩形有相交点. 解决方案: 判断矩形的每一条边是否与直 ...
- codeforces D. Area of Two Circles' Intersection 计算几何
D. Area of Two Circles' Intersection time limit per test 2 seconds memory limit per test 256 megabyt ...
- Intersection(计算几何)
Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)To ...
- hdu-5120 Intersection(计算几何)
题目链接: Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Ot ...
- [poj1410]Intersection
题目大意:求线段与实心矩形是否相交. 解题关键:转化为线段与线段相交的判断. #include<cstdio> #include<cstring> #include<al ...
- 【kuangbin专题】计算几何基础
1.poj2318 TOYS 传送:http://poj.org/problem?id=2318 题意:有m个点落在n+1个区域内.问落在每个区域的个数. 分析:二分查找落在哪个区域内.叉积判断点与线 ...
- poj分类解题报告索引
图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...
- 计算几何(容斥原理,圆交):HDU 5120 Intersection
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...
随机推荐
- 仿qq的条目抽屉动画效果_ViewDragHelper
GitHub地址: https://github.com/OOOOOldZhu/DrawerItemView import android.content.Context; import androi ...
- SURF 特征法
public static void FindMatch(Mat modelImage, Mat observedImage, out long matchTime, out VectorOfKeyP ...
- 清理SharePoint 2010的SQL Server 2008 R2日志数据库的方法!
//来源:http://www.cnblogs.com/nbpowerboy/p/3380079.html 公司用SharePoint 2010已有三年多的时间了,上BPM项目也有2年多的时间,之前供 ...
- vim 删除行末所有内容
%s/\s*$//g
- .net MVC 中“MvcPager” 插件的简单使用。
.net MVC 中提供了一个分页组件"MvcPager",用起来还算方便,实用性较强. 简单写一下使用方法,如有不足的地方,请各位大大给小弟指正出来. 一.准备工作 使用这个组件 ...
- hql中的in查询
public List<ShopDianpu> findbymiaosha(long id, List<Object> list) throws Exception { Str ...
- 百度地图api写在html上可以实现,在jsp上会出现Bmap未定义的问题
在html上引用时用:<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0& ...
- selenium grid的使用与配置
一.selenium grid的组成与作用:由一个集线器hub和多个客户机node组成,如果你的程序需要在不用的浏览器,不同的操作系统上测试,而且比较多的case需要多线程远程执行,那么一个比较好的测 ...
- liunx下试用yum进行php及opchache扩展安装
Centos 6.6 环境: php 5.6.29 nginx:1.10.2 1.配置安装包源 # CentOs 6.x rpm -Uvh http://mirror.webtatic.com/yum ...
- Spring 后置处理器 PropertyPlaceholderConfigurer 类(引用外部文件)
一.PropertyPlaceholderConfigurer类的作用 PropertyPlaceholderConfigurer 是 BeanFactory 后置处理器的实现,也是 BeanFact ...