当前位置:网站首页>Check whether the point is within the polygon
Check whether the point is within the polygon
2022-06-25 08:32:00 【Jason? thirteen】
Check whether the point is within the polygon C# edition
- Ray method : Draw a ray from the target point , Look at the number of intersections of this ray and all sides of the polygon . If there are odd intersections , It means inside , If there are even intersections , It means it's outside
There are many ways to judge whether a point is within a polygon , This is the ray method

Draw a horizontal line on the point of judgment , Look at the intersection of this line and the polygon , The number of points on either side is odd , Then the point is in the polygon ( Because the intersection of a horizontal line and a polygon is an even number , If the point is within the polygon , Then its left or right intersection points must be an odd number , So just judge the situation on one side )
According to the two-point formula, the intersection of the horizontal line and any two adjacent points of the polygon can be obtained
Two point formula :
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;// spot P1 and P2 Formal parameter connection
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;
}
边栏推荐
- Rqt command
- 打新债安全不 有风险吗
- What is the role of software validation testing? What is the price of the confirmation test report?
- Retrieval model rough hnsw
- tp5与tp6的区别是啥呀?
- What do various optimizers SGD, adagrad, Adam and lbfgs do?
- Scanpy (VII) spatial data analysis based on scanorama integrated scrna seq
- InfluxDB时序数据库
- 420 sequence traversal of binary tree 2 (429. sequence traversal of n-ary tree, 515. find the maximum value in each tree row, 116. fill in the next right node pointer of each node, 104. maximum depth
- 微信小程序_7,项目练习,本地生活
猜你喜欢

Stm32cubemx learning (5) input capture experiment

检测点是否在多边形内

Scanpy (VII) spatial data analysis based on scanorama integrated scrna seq

Data preprocessing: discrete feature coding method

DNS protocol and its complete DNS query process

Home server portal easy gate

C language "Recursion Series": recursively realizing the n-th power of X

UEFI:修复 EFI/GPT Bootloader

Word2vec, phrases, phraser, keyedvectors commonly used in gensim

leetcode.13 --- 罗马数字转整数
随机推荐
浏览器查看当前页面所有的监听事件
openid是什么意思?token是什么意思?
A solution to slow startup of Anaconda navigator
初识生成对抗网络(12)——利用Pytorch搭建WGAN-GP生成手写数字
GIL问题带来的问题,解决方法
What problems do you worry about when you want to switch to software testing?
Nips 2014 | two stream revolutionary networks for action recognition in videos reading notes
tp6自动执行的文件是哪个?tp6核心类库有什么作用呢?
Wechat applet introduction record
【操作教程】TSINGSEE青犀视频平台如何将旧数据库导入到新数据库?
Beam search and five optimization methods
打新债安全不 有风险吗
EasyPlayer流媒体播放器播放HLS视频,起播速度慢的技术优化
Getting to know the generation confrontation network (11) -- using pytoch to build wgan to generate handwritten digits
测一测现在的温度
4个不可不知的采用“安全左移”的理由
Almost taken away by this wave of handler interview cannons~
What are the indicators of VIKOR compromise?
Websocket understanding and application scenarios
SwipeRefreshLayout+RecyclerView无法下拉问题排查