当前位置:网站首页>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;
}
边栏推荐
- 关于I/O——内存与CPU与磁盘之间的关系
- Websocket understanding and application scenarios
- Software engineering review questions
- Retrieval model rough hnsw
- NIPS 2014 | Two-Stream Convolutional Networks for Action Recognition in Videos 阅读笔记
- How to calculate the positive and negative ideal solution and the positive and negative ideal distance in TOPSIS method?
- Is it safe to open an account online? Xiaobai asks for guidance
- 417 sequence traversal of binary tree 1 (102. sequence traversal of binary tree, 107. level traversal of binary tree II, 199. right view of binary tree, 637. layer average of binary tree)
- 在网上股票开户安全吗?证券账户可以给别人用吗?
- 配置、软件配置项、软件配置管理项辨析
猜你喜欢

InfluxDB时序数据库

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

leetcode. 13 --- Roman numeral to integer

物联网毕设(智能灌溉系统 -- Android端)

Establish open data set standards and enable AI engineering implementation

检测点是否在多边形内

A solution to slow startup of Anaconda navigator

How to calculate the correlation coefficient and correlation degree in grey correlation analysis?

linux中的mysql有10061错误怎么解决

Super simple case: how to do hierarchical chi square test?
随机推荐
测一测现在的温度
Measure the current temperature
检测点是否在多边形内
初识生成对抗网络(11)——利用Pytorch搭建WGAN生成手写数字
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
Basic record of getting started with PHP
Is it safe to open an account online? Xiaobai asks for guidance
软件工程复习题
Getting to know the generation confrontation network (11) -- using pytoch to build wgan to generate handwritten digits
Go language learning tutorial (13)
物联网毕设(智能灌溉系统 -- Android端)
软件确认测试有什么作用?确认测试报告的价格是多少?
想要软件测试效果好,搭建好测试环境是前提
第五天 脚本与UI系统
Bluecmsv1.6-代码审计
Home server portal easy gate
打新债安全不 有风险吗
Rosparam statement
A solution to slow startup of Anaconda navigator
Nodehandle common member functions