检测3D空间中的相邻节点 [英] Detect Adjacent Nodes in 3D Space

查看:91
本文介绍了检测3D空间中的相邻节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

请给出一些好主意或一段代码,以检测3D空间usig C ++中的相邻节点.
例如,输入radius,SW应该标识具有特定球面的节点.

//输入:具有许多节点的3D空间

在Advanced中感谢

Hi all

Please give some good idea or piece of code to detect Adjacent Nodes in 3D Space usig C++.
For Example, enter radius , SW should identify the nodes which are with the specfici sphere.

//Input : a 3D Space with Lots of Nodes

Thanks in Advanced

推荐答案

简单解决方案:
-计算并存储半径的平方
-遍历所有节点
-对于每个节点,计算节点与球体中心之间的距离的平方
-将结果与平方半径进行比较-如果结果较大,则说明该点在球体外部,否则在内部

更复杂的解决方案:
-在地理数据结构中组织3D点,例如G. Octree [
Simple solution:
- calculate and store the square of the radius
- loop over all nodes
- for each node, calculate the square of the distance between the node and the center of the sphere
- compare the result to the square radius - if it''s greater, then the point is outside the sphere, else inside

More complex solution:
- organize your 3D points in a geomatrical data structure, e. g. an Octree[^]
- determine which of the segments of this data structures contain part or all of the sphere
- for all those specific segments, do the simple solution search described above.

P.S.:
If performance is not an issue, you can also do the very simple solution (as suggested above):
- loop over all nodes
- for each node, calculate the distance between the node and the center of the sphere
- compare the result to the radius - if it''s greater, then the point is outside the sphere, else inside

I consider that ''very'' simple, but at the same time possibly better than either of the above, because it explicitely does the obvious thing. Anyone with a minimum of knowledge about geometry looking at the code will immediately understand it. This may make it more maintainable than the other solutions.


如果您有参考点坐标和其他点坐标,为什么不计算它们之间的距离并将其与那个球体的半径?如果距离小于球体半径,则其在球体中.

为避免计算平方根,请阅读此页面:
http://freespace.virgin.net/hugo.elias/routines/r_dist.htm [ ^ ]

希望对您有所帮助.
If you have the reference point coordinate and other points coordinates, why don''t you compute the distance between them and compare it with the radius of that sphere ? If the distance was lower than the sphere radius then its in the sphere.

to avoid computing square roots read this page :
http://freespace.virgin.net/hugo.elias/routines/r_dist.htm[^]

Hope it helps.


这篇关于检测3D空间中的相邻节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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