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
题意:有很多棍子,从棍子中选出两个棍子集合,使他们的和相等,求能取得的最多棍子数. 解法:容易看出有一个多阶段决策的过程,对于每个棍子,我们有 可以不选,或是选在第一个集合,或是选在第二个集合 这三种 ...
随机推荐
- mssql分页原理及效率分析
下面是常用的分页,及其分页效率分析. 1.分页方案一:(利用Not In和SELECT TOP分页) 语句形式: SELECT TOP 10 * FROM TestTable WHERE (ID NO ...
- [置顶] ROS探索总结(十一)——机器视觉
机器视觉在计算机时代已经越来越流行,摄像头价格越来越低廉,部分集成深度传感器的混合型传感器也逐渐在研究领域普及,例如微软推出的Kinect,而且与之配套的软件功能十分强大,为开发带来了极大的便利.RO ...
- crudandroidandroid——CRUD(在上一篇博客的基础上)
废话就不多说了,开始... 1.Person package com.njupt.sqlite; public class Person { private Integer id; private S ...
- vsftpd配置seccomp_sandbox=NO
在ubuntu14.04 配置vsftp时如果不加上seccomp_sandbox=NO这一句会出现莫名的530错误
- 应用Git Flow—Git团队协作最佳实践
规范的Git使用 Git是一个很好的版本管理工具,不过相比于传统的版本管理工具,学习成本比较高. 实际开发中,如果团队成员比较多,开发迭代频繁,对Git的应用比较混乱,会产生很多不必要的冲突或者代码丢 ...
- ArrayList、HashSet、HashTable、List、Dictionary的区别
在C#中,数组由于是固定长度的,所以常常不能满足我们开发的需求. 由于这种限制不方便,所以出现了ArrayList. ArrayList.List<T> ArrayList是可变长数组,你 ...
- DotNetZip 压缩下载
var fs = Response.OutputStream; using (ZipFile zip = new ZipFile(System.Text.Encoding.UTF8)) //编码是解决 ...
- CentOS 添加本地yum源
1 创建保存RPM包的路径: mkdir -p /share/CentOS/7/local/x86_64/RPMS 2 安装createrepo工具 yum install createrepo 3 ...
- ubuntu_虚拟机和SD卡链接失败,可能的原因
这个问题很简单吧,但是自己解决却用了很长时间,说一下方法吧! 1.有的虚拟机不兼容USB3.0的接口,所以在接SD卡(读卡器)时,请将读卡器拔出,插入笔记本USB2.0的接口上(当时自己没注意到这点, ...
- 效果网址http://sc.chinaz.com/tag_jiaoben/tupianlunbo.html
http://sc.chinaz.com/tag_jiaoben/tupianlunbo.html