如何找到 3D 向量的哈希值?
我正在尝试使用固定网格大小的方法执行宽相碰撞检测。因此,对于每个实体的位置:(x,y,z)(每个浮点数类型),我需要找到实体位于哪个单元格中。然后我打算将所有单元格存储在哈希表中,然后迭代报告(如果有)碰撞。
所以,这就是我正在做的事情: 网格单元的位置:(int类型)(Gx,Gy,Gz)=> (x / M, y / M, z / M) 其中 M 是网格的大小。
有一次,我有一个单元格,我想将其添加到哈希表中,其键是基于(Gx,Gy,Gz)的唯一哈希值,值是单元格本身。现在,我想不出一个好的哈希函数,我需要一些帮助。
有人可以建议我一个好的哈希函数吗?
谢谢
I am trying to perform broad-phase collision detection with a fixed-grid size approach. Thus, for each entity's position: (x,y,z) (each of type float), I need to find which cell does the entity lie in. I then intend to store all the cells in a hash-table and then iterate through to report (if any) collisions.
So, here is what I am doing:
Grid-cell's position: (int type) (Gx, Gy, Gz) => (x / M, y / M, z / M) where M is the size of the grid.
Once, I have a cell, I'd like to add it to a hash-table with its key being a unique hash based on (Gx, Gy, Gz) and the value being the cell itself. Now, I cannot think of a good hash function and I need some help with that.
Can someone please suggest me a good hash function?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果有人仍然对此感兴趣,我想出了一个可以在这里使用的解决方案:
http://www.gamedev.net/community/forums/topic.asp?topic_id=567378
If someone is still interested in this, I figured out a solution that works over here:
http://www.gamedev.net/community/forums/topic.asp?topic_id=567378
网格方法在网格框边界附近会出现问题。为什么不使用 BSP 树来代替呢?
The grid approach is going to have problems near the boundaries of the grid boxes. Why not use BSP trees instead?
对于这种向量,我首选的散列函数是将每个分量的位旋转不同的常数并将它们异或在一起。
它非常快,并且位旋转有助于减少冲突并确保使用尽可能多的密钥空间。
My preferred hashing function for this kind of vector is to rotate the bits of each component by a different constant and XOR them together.
It's very fast, and the bit rotations are helpful to reduce collisions and ensure as much of the key space as possible is used.
这里有一些您可以查看的参考资料。 Warren 的论文详细讨论了哈希算法:
一种并行哈希八叉树 N 体算法
便携式并行粒子程序
here are a few references you could look at. Warren's papers discuss the hash algorithm in detail:
A parallel hashed Oct-Tree N-body algorithm
A portable parallel particle program