指向不规则形状内部 [英] Point inside an irregular shape

查看:32
本文介绍了指向不规则形状内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绝不是一个专业的程序员,所以请不要指望这里有一种复杂的方法或语言.但是,我将感谢您提出的实现算法的建议和建议,在稍后阶段,我可以以编程方式将其添加到我的项目中......问题是:

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:

  • 有坐标
  • 位于二维表面
  • 是静止的
  • 在任何给定时间都属于单个区域(其边界坐标也是已知的).也就是说,它是其父"元素的唯一子".再说一次,如果它不在一个区域内,它肯定会在另一个区域内!

区域不是简单的正方形、四边形或圆形,而是不规则的形状.

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.

在此先非常感谢您!!!

Thank you very much in advance!!!

推荐答案

程序员会这样做:

  1. 一个函数将一个面积数组和一个点作为参数.

  1. 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.

这篇关于指向不规则形状内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆