简体   繁体   English

适用于Java中的Flocking Boids的2D空间数据结构

[英]2D Spatial Data Structure suitable for Flocking Boids in Java

I'm working on a flocking boids simulation just for fun, and I want to optimise it a bit. 我正在进行植绒boids仿真,只是为了好玩,我想稍微优化一下。 The area that needs work is finding boids near a given boid. 需要工作的区域是在给定的boid附近找到boids。 I figure that to do that some kind of spatial data-structure suited to the task would be my best bet (see here and scroll down a bit.). 我认为要做到这一点,某种适合任务的空间数据结构将是我最好的选择(请参阅此处并向下滚动一下。)。

Whatever I go with, I'll implement myself, from scratch, in Java. 无论我采用什么,我都会用Java从头开始实现自己。 That way I'll learn more about the data structure I choose than I would if I just called a bunch of library functions. 这样我就可以学到更多关于我选择的数据结构的知识,而不是我刚才调用的一堆库函数。

I'm aware of R-Trees , kd trees , and Quadtrees . 我知道R-Treeskd treesQuadtrees They're all feasible options, in my opinion. 在我看来,它们都是可行的选择。 But I don't have any experience with these data structures and I'm not totally sure what best suits my purpose. 但我对这些数据结构没有任何经验,我不完全确定最适合我的目的。 I don't need anything on this scale - I'm talking maybe a few hundred boids, perhaps at most one thousand, rather than a million, although bear in mind I might end up running it on an Android phone eventually. 我不需要这么大规模的任何东西 - 我说的可能是几百个boids,也许最多只有一千,而不是一百万,尽管记住我最终可能最终在Android手机上运行它。

Please recommend me a data structure (not limited to the above, of course) for this, and give me a good reason to choose it over the alternatives. 请为此推荐一个数据结构(当然不限于上述内容),并给我一个很好的理由选择它。

Yes, I've seen this question . 是的,我已经看到了这个问题 No, I'm not satisfied with the answer - there's no reasoning given at all. 不,我对答案不满意 - 根本没有任何理由。

Oh, one other thing - like the title says, this is strictly for two dimensions only. 哦,另外一件事 - 就像标题所说的那样,这仅仅是针对两个维度的。

Quadtrees are a pretty standard data structure used for hit detection in video games. Quadtrees是一种非常标准的数据结构,用于视频游戏中的命中检测。 I think it would be well suited for your goal. 我认为它非常适合你的目标。

https://gamedevelopment.tutsplus.com/tutorials/quick-tip-use-quadtrees-to-detect-likely-collisions-in-2d-space--gamedev-374 https://gamedevelopment.tutsplus.com/tutorials/quick-tip-use-quadtrees-to-detect-likely-collisions-in-2d-space--gamedev-374

Honestly, I would start with an unoptimized version and see how far you can take it (how many boids). 老实说,我会从一个未优化的版本开始,看看你能走多远(多少个boid)。 After that, try different methods and measure what difference they make. 之后,尝试不同的方法并衡量它们之间的差异。 I think that would be the best way to learn. 我认为这将是最好的学习方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM