This article is made by Jason-Cow.
Welcome to reprint.
But please post the writer's address.

http://www.cnblogs.com/JasonCow/

叉积判方向

点积判角度

角度和=0°在外面

否则在里面

AC Code 这么短的计算几何,君难道不想收入囊中吗?

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define sqr(x) ((x)*(x))
#define RG register
#define op operator
#define IL inline
#define db double
#define bl bool
const db pi=acos(-1.0),eps=1e-;
struct D{db x,y;D(db x=0.0,db y=0.0):x(x),y(y){}};
typedef D V;
V operator+(V A,V B){return V(A.x+B.x,A.y+B.y);}
V operator-(V A,V B){return V(A.x-B.x,A.y-B.y);}
V operator*(V A,db N){return V(A.x*N,A.y*N);}
V operator/(V A,db N){return V(A.x/N,A.y/N);}
V Rotate(V A,db a){return V(A.x*cos(a)-A.y*sin(a),A.x*sin(a)+A.y*cos(a));}
int dcmp(db x){if(fabs(x)<eps)return ;else return x>?:-;}
bl OnSegment(D A,D B,D P){return dcmp((P.x-A.x)*(P.x-B.x))<=&&dcmp((P.y-A.y)*(P.y-B.y))<=;}
db Len(D A){return sqrt(A.x*A.x+A.y*A.y);}
db Cross(V A,V B){return A.x*B.y-A.y*B.x;}
db Dot(V A,V B){return A.x*B.x+A.y*B.y;}
db VectorAngle(V a,V b){return acos(Dot(a,b)/(Len(a)*Len(b)));} bl InPolygon(D P,D*R,int n){
db ans=0.0;
R[]=R[n];
for(int i=;i<n;i++){
D A=R[i],B=R[i+];
int cross=dcmp(Cross(A-P,B-P));
if(cross==){if(OnSegment(A,B,P))return true;}
else{
db angle=VectorAngle(A-P,B-P);
ans+=(cross>?angle:-angle);
}
}
return dcmp(ans)!=;
}
const int maxn=(int)1e5+;
D A[maxn]; int main(){
int n,m,cnt=;
db a,b;
while(scanf("%d",&n)&&n){
if(cnt!=)puts("");
printf("Problem %d:\n",++cnt);
scanf("%d",&m);
for(int i=;i<=n;i++)scanf("%lf%lf",&A[i].x,&A[i].y);
for(int i=;i<=m;i++){
scanf("%lf%lf",&a,&b);
printf("%s\n",InPolygon(D(a,b),A,n)?"Within":"Outside");
}
}
return ;
}

计算几何-点与多边形的位置判断-zoj1081Points Within的更多相关文章

  1. Cupid's Arrow---hdu1756(判断点与多边形的位置关系 模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1756 题意:中文题,套模板即可: /* 射线法:判断一个点是在多边形内部,边上还是在外部,时间复杂度为 ...

  2. LightOj1190 - Sleepwalking(判断点与多边形的位置关系--射线法模板)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1190 题意:给你一个多边形含有n个点:然后又m个查询,每次判断点(x, y)是否在多边 ...

  3. 利用百度API(JavaScript 版)实现在地图上绘制任一多边形,并判断给定经纬度是否在多边形范围内。以及两点间的测距功能

    权声明:本文为博主原创文章,未经博主允许不得转载. 利用百度API(JavaScript 版)实现在地图上绘制任一多边形,并判断给定经纬度是否在多边形范围内.以及两点间的测距功能. 绘制多边形(蓝色) ...

  4. ZOJ1081 Points Within 点和多边形的位置关系

    ZOJ1081 给一个点和一个多边形 判断点在多边形内(边上)还是在多边形外 在多边形外的点引一条射线必然穿过多边形的两条边 而在多边形内的点则不一定. 当然凹多边形有特殊情况 但是总能找到对应位置关 ...

  5. hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. php查找字符串首次出现的位置 判断字符串是否在另一个字符串中

    strpos - 查找字符串首次出现的位置 说明 int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) 返回 nee ...

  7. UVA 10256 The Great Divide (凸包,多边形的位置关系)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34148 [思路] 凸包 求出红蓝点的凸包,剩下的问题就是判断两个凸 ...

  8. 【计算几何初步:多边形中心】【HDU1115】Lifting the Stone

    一.质点系重心公式 x=(x1*m1+x2*m2+x3*m3.....xn*mn)/M  (M=m1+m2+m3+m4...+mn) 二.三角形重心 可直接求得,但在多边形剖分中 各三角形的质点的质量 ...

  9. poj 1654 Area(计算几何--叉积求多边形面积)

    一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最 ...

随机推荐

  1. 【kuangbin带你飞】 MST专题

    唉,被班级合唱和复变考试搞得心力交瘁.新算法学不进去,更新下吧 A - Til the Cows Come Home The Head Elder of the tropical island of ...

  2. K3/cloud执行计划插件示例

    public class AutoCheckInventory : IScheduleService { /// <summary>        /// 实际运行的Run 方法      ...

  3. [CF1034A] Two Rabbits - 数学

    判断能否整除即可 #include <bits/stdc++.h> using namespace std; int x,y,a,b; int main() { int t; ios::s ...

  4. PP: Neural ordinary differential equations

    Instead of specifying a discrete sequence of hidden layers, we parameterize the derivative of the hi ...

  5. idea 配置 tomcat 教程

    最近在搞一个项目需要用到idea 配置tomcat,翻了翻网上的帖子发现稂莠不齐,最后决定还是自己写个吧!(其实我挺蠢的走了好多的弯路,哎~) 1.首先准备一个需要大家tomcat的工程,然后使用id ...

  6. join方法,wait()和sleep()

    join方法解释:方法x.join()的作用是使所属线程x 正常执行run()中的方法,而使得调用x.join()的线程处于无限期阻塞状态,等待x线程销毁后再继续执行线程z后面的代码. 1.方法joi ...

  7. 关于vue :style 的几种使用方式

    :style的使用 一 ,最通用的写法 <p :style="{fontFamily:arr.conFontFamily,color:arr.conFontColor,backgrou ...

  8. TensorFlow 2.0高效开发指南

    Effective TensorFlow 2.0 为使TensorFLow用户更高效,TensorFlow 2.0中进行了多出更改.TensorFlow 2.0删除了篇冗余API,使API更加一致(统 ...

  9. docker安装elasticsearch和head插件

    使用 Docker 拉取ElasticSearch镜像 docker pull elasticsearch:7.0.0 查看镜像 ID docker images 运行 docker run -e E ...

  10. 【原】librtmp源码详解

    “悟已往之不谏,知来者之可追”.后悔做了这么久的直播,却不曾理解rtmp协议的实现原理,现在意识到了这个问题,特此补救.同时谨以此文纪念曾经的雷霄骅同学,感谢他对音视频领域做出的卓越贡献和引领. 1. ...