I'm working on a flocking boids simulation just for fun, and I want to optimise it a bit. The area that needs work is finding boids near a given boid. 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. 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 . 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.
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. I think it would be well suited for your goal.
Honestly, I would start with an unoptimized version and see how far you can take it (how many boids). After that, try different methods and measure what difference they make. I think that would be the best way to learn.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.