PNPOLY - Point Inclusion in Polygon Test
https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
The C Code
Here is the code, for reference. Excluding lines with only braces, there are only 7 lines of code.
int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
{
int i, j, c = 0;
for (i = 0, j = nvert-1; i < nvert; j = i++) {
if ( ((verty[i]>testy) != (verty[j]>testy)) &&
(testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
c = !c;
}
return c;
}
| Argument | Meaning |
|---|---|
| nvert | Number of vertices in the polygon. Whether to repeat the first vertex at the end is discussed below. |
| vertx, verty | Arrays containing the x- and y-coordinates of the polygon's vertices. |
| testx, testy | X- and y-coordinate of the test point. |
The Method
I run a semi-infinite ray horizontally (increasing x, fixed y) out from the test point, and count how many edges it crosses. At each crossing, the ray switches between inside and outside. This is called the Jordan curve theorem.
The case of the ray going thru a vertex is handled correctly via a careful selection of inequalities. Don't mess with this code unless you're familiar with the idea ofSimulation of Simplicity. This pretends to shift the ray infinitesimally down so that it either clearly intersects, or clearly doesn't touch. Since this is merely a conceptual, infinitesimal, shift, it never creates an intersection that didn't exist before, and never destroys an intersection that clearly existed before.
The ray is tested against each edge thus:
- Is the point in the half-plane to the left of the extended edge? and
- Is the point's Y coordinate within the edge's Y-range?
Handling endpoints here is tricky.
PNPOLY - Point Inclusion in Polygon Test的更多相关文章
- PNPOLY - Point Inclusion in Polygon W. Randolph Franklin
测试目标点是否在多边形内int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) { int i, j, ...
- Determining if a point lies on the interior of a polygon
Determining if a point lies on the interior of a polygon Written by Paul Bourke November 1987 Solut ...
- [LeetCode] Convex Polygon 凸多边形
Given a list of points that form a polygon when joined sequentially, find if this polygon is convex ...
- Web Application Penetration Testing Local File Inclusion (LFI) Testing Techniques
Web Application Penetration Testing Local File Inclusion (LFI) Testing Techniques Jan 04, 2017, Vers ...
- 结合谷歌地图多边形(polygon)与Sql Server 2008的空间数据类型计算某个点是否在多边形内的注意事项
首先在利用 GEOGRAPHY::STPolyFromText(@GeoStr, 4326) 这样的函数把字符串转换为Geography类型时,字符串里经纬度的顺序是 “经度[空格]纬度”,即“lon ...
- [svg 翻译教程]Polyline(折线)polygon(多边形)
原文: http://tutorials.jenkov.com/svg/polygon-element.html Polyline 虽然说这个 元素我没用过,但是还是蛮强大的,也翻译下 示例 < ...
- [OpenGL][SharpGL]用Polygon Offset解决z-fighting和stitching问题
[OpenGL][SharpGL]用Polygon Offset解决z-fighting和stitching问题 本文参考了(http://www.zeuscmd.com/tutorials/open ...
- WebGIS中基于AGS的画圆查询简析以及通过Polygon来构造圆的算法
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 某个项目需求中需要在前端进行画圆查询,将圆范围上的多边形要素 ...
- 【ASC 23】G. ACdream 1429 Rectangular Polygon --DP
题意:有很多棍子,从棍子中选出两个棍子集合,使他们的和相等,求能取得的最多棍子数. 解法:容易看出有一个多阶段决策的过程,对于每个棍子,我们有 可以不选,或是选在第一个集合,或是选在第二个集合 这三种 ...
随机推荐
- The Event System
The Event System 在Qt中,事件是继承了虚拟类QEvent的对象,它代表了程序所发生的事情或者程序需要知道的一个外部活动的结果.事件可以被任意 QObject子类的实例接收和处理,是与 ...
- java.io.IOException: Unable to open sync connection!的解决方案
在学习Android的时候,经常是使用手机调试程序,很方便,后来 在使用手机调试程序的时候出现了 [2012-03-08 11:27:43 - Tea_marsListActivity] ------ ...
- 记一次修复被篡改的IE首页
今天开电脑,打开IE发现首页被篡改为http://www.you2000.cn/,下意识是恶意插件造成的,可是为什么金山卫士没发现呢(我电脑上只装了一个金山卫士)?我锁定首页的啊... 只好手动运行金 ...
- 以域管理账户连接到TFS或git时,设置IE允许Cookies
在 Windows 域环境中,每个项目组会创建一个项目管理账户,在和其他项目组进行数据交互时,只需要授予该项目管理账户相应的权限,方便了权限的管理.对于项目组管理账户:domain\admin,该域账 ...
- 文档在线预览开源实现方案二:OpenOffice + pdf.js
文档在线预览的另一种实现方式采用的技术栈是OpenOffice + pdf.js, office文档转换为pdf的工作依然由OpenOffice的服务来完成,pdf生成后我们不再将其转换为其他文件而是 ...
- 进度管理工具 planner
ganttproject 太简单,连个子项目都做不了.(也可能是我不会用,后来发现用缩进就可以了.呵呵).又重新有网上搜了一下,发现PLANNER符合我的想法... *进官网,下载. #tar xvJ ...
- 面向对象UML中类关系
如果你确定两件对象之间是is-a的关系,那么此时你应该使用继承:比如菱形.圆形和方形都是形状的一种,那么他们都应该从形状类继承而不是聚合.如果你确定两件对象之间是has-a的关系,那么此时你应该使用聚 ...
- Linux 操作命令列表记录
Linux 操作命令列表记录 SSH登录 登录 ## 范式 ssh [username]@[host] ## 例 ssh -p 1222 root@10.0.0.1 使用非默认端口(ssh默认端口22 ...
- 转:iOS程序main函数之前发生了什么
原文地址:http://blog.sunnyxx.com/2014/08/30/objc-pre-main/ 我是前言 一个iOS app的main()函数位于main.m中,这是我们熟知的程序入口. ...
- DP! | 不要怂!
跟一个博客刷: http://blog.csdn.net/cc_again/article/details/25866971 一.简单基础dp 1.递推 HDU 2084 #include <b ...