问题描述
我绝对不是专业的程序员,所以请不要指望这里有一种复杂的方法或语言.不过,对于您提出的实现算法的建议和建议,我将不胜感激,稍后,我可以以编程方式将其添加到我的项目中……这是问题所在:
I'm in no way a professional programmer so, pls don't expect a sophisticated approach or language here. I'll however appreciate your advice and recommendations to materialize an algorithm which, at a later stage, I could programmatically add to my project... Here is the problem:
想象一下空间中具有以下属性的任意点(点X):
Imagine an arbitrary point (Point X) in space with the following properties:
- 有坐标
- 位于2D曲面上
- 是静止的
- 在任何给定时间都属于单个区域(其边界坐标也是已知的).即,它是其父"元素的唯一子".同样,如果它不在一个区域中,那么它肯定会在另一个区域中!
一个区域不是简单的正方形,四边形或圆形,而是不规则的形状.
An area is NOT a simple square, quadrangle, or a circle but instead is an irregular shape.
现在,我的问题是:如何确定:(i)如果X点位于该特定区域之内而不是相邻区域之内;(ii)该点属于哪个特定区域(在一组区域A,B或C中)?查看链接的图像以更好地显示问题:
Now, my question is: How can I determine:(i) if Point X lies inside that particular area and NOT the adjacent one;(ii) which specific area (among a set of areas A, B, or C) the point belongs to?!? See the linked image to better visualize the problem:
PS:我认为有可能处理多边形指向问题(尤其是射线投射算法"听起来很聪明!),但由于(i)区域可能彼此相邻,因此似乎不是解决方案.(ii)我需要确定一个点所属的区域,而不是它位于其内部/外部的范围.
PS: I perused a possibility of dealing with Point in Polygon problem (especially, the "ray casting algorithm" sounds quite smart!) but it doesn't seem to be a solution since (i) areas may be adjacent to each other; (ii) I need to determine the area a point belongs to more than it lies inside/outside of it.
非常感谢您!
推荐答案
程序员可以这样做:
-
一个函数将一系列区域和一个点作为参数.
A function is taking as parametres an array of areas and a point.
进行循环-检查您所有的区域以及每个区域
Make a cycle - check ALL your areas and for every one
通过射线投射算法检查该点是否属于该点.
check by the ray casting algorythm if the point belongs there.
如果否,请继续循环,
如果是,请完成返回当前区域编号的函数.
If yes, finish the function returning the number of the current area.
如果您不在区域内,请返回-1.
If you are out of areas, return -1.
当然,您可以在考虑通用边界的情况下改进算法,而不必为它们重复角度计算,但是这样的算法显然已经超出了您的可能性.甚至是一个优秀的程序员也会从简单但可行的方式入手.
Of course, you can improve the algorythm, taking into account the common borders, not repeating the counting of angles for them, but such algorythms are obviously out of your possiblilities now. And even a good programmer will start by something easy, but working.
这篇关于点在不规则形状内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!