当前位置:网站首页>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;
}
边栏推荐
- 软件工程复习题
- C language: count the number of characters, numbers and spaces
- Prepare these before the interview. The offer is soft. The general will not fight unprepared battles
- 第五天 脚本与UI系统
- NIPS 2014 | Two-Stream Convolutional Networks for Action Recognition in Videos 阅读笔记
- Use Adobe Acrobat pro to resize PDF pages
- tp6自动执行的文件是哪个?tp6核心类库有什么作用呢?
- How to calculate critical weight indicators?
- 浏览器查看当前页面所有的监听事件
- Getting to know the generation confrontation network (11) -- using pytoch to build wgan to generate handwritten digits
猜你喜欢
浏览器查看当前页面所有的监听事件
Overview of image super score: the past and present life of image super score in a single screen (with core code)
家庭服务器门户Easy-Gate
Similarity calculation method
With the beauty of technology enabled design, vivo cooperates with well-known art institutes to create the "industry university research" plan
《树莓派项目实战》第五节 使用Nokia 5110液晶屏显示Hello World
CVPR 2022 oral 2D images become realistic 3D objects in seconds
How to calculate the correlation coefficient and correlation degree in grey correlation analysis?
First experience Amazon Neptune, a fully managed map database
Stm32cubemx Learning (5) Input capture Experiment
随机推荐
打新债真的安全吗? 风险大吗
Problems caused by Gil problems and Solutions
TrendMicro:Apex One Server 工具文件夹
How to analyze the coupling coordination index?
Remove headers from some pages in a word document
C language "recursive series": recursive implementation of 1+2+3++ n
TCP MIN_ A dialectical study of RTO
2021 "Ai China" selection
QSS 不同风格的按钮
Index analysis of DEMATEL model
软件确认测试有什么作用?确认测试报告的价格是多少?
Jdbc-dao layer implementation
Internet of things (intelligent irrigation system - Android end)
开户券商怎么选择?在线开户是安全么?
Can I grant database tables permission to delete column objects? Why?
To achieve good software testing results, it is a prerequisite to build a good testing environment
打新债安不安全 有风险吗
Retrieval model rough hnsw
[QT] QT 5 procedure: print documents
Stm32cubemx Learning (5) Input capture Experiment