当前位置:网站首页>检测点是否在多边形内
检测点是否在多边形内
2022-06-25 07:16:00 【Jason?13】
检测点是否在多边形内C#版本
- 引射线法:从目标点出发引一条射线,看这条射线和多边形所有边的交点数目。如果有奇数个交点,则说明在内部,如果有偶数个交点,则说明在外部
判断一个点是否在多边形内的方法有很多,这里是射线法

在判断的点上画一条水平线,看这条线与多边形的交点,任意一边的点是奇数个,那么该点就在多边形内(因为一条水平线与多边形的交点是偶数个,如果该点在多边形内,那么它的左边或右边相交的点必定是奇数个,所以只要判断一边的情况就行了)
根据两点式可以求出水平线与多边形任意两个相邻点的交点
两点式公式:
private bool InArea(Vector2 rPlayerPos, List<Vector3> rPointList)
{
if (rPointList.Count < 3)
return false;
int nCrossings = 0;
for (int i = 0; i < rPointList.Count; i++)
{
Vector2 rPos1 = new Vector2(rPointList[i].x, rPointList[i].z);
var bTmpIndex = (i + 1) % rPointList.Count;//点P1和P2形参连线
Vector2 rPos2 = new Vector2(rPointList[bTmpIndex].x, rPointList[bTmpIndex].z);
if (rPos1.y == rPos2.y)
continue;
if (rPlayerPos.y < Mathf.Min(rPos1.y, rPos2.y))
continue;
if (rPlayerPos.y >= Mathf.Max(rPos1.y, rPos2.y))
continue;
float fX = (rPlayerPos.y - rPos1.y) * (rPos2.x - rPos1.x) / (rPos2.y - rPos1.y) + rPos1.x;
if (fX > rPlayerPos.x)
nCrossings++;
}
return (nCrossings % 2) == 1;
}
边栏推荐
- 4 raisons inconnues d'utiliser le "déplacement sûr à gauche"
- The era of enterprise full cloud -- the future of cloud database
- Quickly build a real-time face mask detection system in five minutes (opencv+paddlehub with source code)
- What are the indicators of entropy weight TOPSIS method?
- Find out the possible memory leaks caused by the handler and the solutions
- Scanpy(七)基于scanorama整合scRNA-seq实现空间数据分析
- Ffmpeg+sdl2 for audio playback
- GIL问题带来的问题,解决方法
- VOCALOID notes
- 如何设计测试用例
猜你喜欢

Log in to MySQL 5.7 under ubuntu18 and set the root password

Static web server

如何设计测试用例

What are the indicators of VIKOR compromise?

Biweekly investment and financial report: capital ambush Web3 infrastructure

Measure the current temperature

GPU calculation

双周投融报:资本埋伏Web3基础设施

Find the nearest common ancestor (Sword finger offer) of two nodes in the binary tree (search tree)

Apache CouchDB Code Execution Vulnerability (cve-2022-24706) batch POC
随机推荐
First experience Amazon Neptune, a fully managed map database
Scanpy (VII) spatial data analysis based on scanorama integrated scrna seq
配置、软件配置项、软件配置管理项辨析
Nips 2014 | two stream revolutionary networks for action recognition in videos reading notes
在二叉树(搜索树)中找到两个节点的最近公共祖先(剑指offer)
Apache CouchDB Code Execution Vulnerability (cve-2022-24706) batch POC
现在网上开通股票账号安全吗?
微信小程序_7,项目练习,本地生活
DNS protocol and its complete DNS query process
How to calculate the information entropy and utility value of entropy method?
在哪个平台买股票开户安全?求分享
软件测试月薪10K如何涨到30K,只有自动化测试能做到
The era of enterprise full cloud -- the future of cloud database
LeetCode_ Hash table_ Medium_ 454. adding four numbers II
What do various optimizers SGD, adagrad, Adam and lbfgs do?
4個不可不知的采用“安全左移”的理由
Basic record of getting started with PHP
家庭服务器门户Easy-Gate
How to interpret the information weight index?
Stm32cubemx Learning (5) Input capture Experiment