2

I'm experimenting jmonkeyengine and I've come across the need to return all points (from a predefined large set of points) that fall within a bounding volume. It's easy enough to create the volume itself but I'd like to get a map of all the contained points.

Does the community have any ideas? I'm happy to use other libraries if needs be, I'm drawn to jmonkey due to the community support and the BoundingCapsule shape.

Edit: I have considered iterating over all my Points and using .contains, unfortunately the space contains hundreds of thousands of points and relatively miniscule capsules. Surely there must be some clever maths I'm missing.

Arjun Sol
  • 731
  • 5
  • 18
  • 2
    From a mathematical stand point, there are infinitely many points inside a volume. I'm not familiar with jmonkeyengine specifically, but it sounds like you need to clarify your question a little in order to get some helpful answers. – Code-Apprentice Oct 29 '12 at 21:59
  • Do you mean that you have a set of Point objects and you would like to return all of *those* that are inside a bounding volume? – chm Oct 29 '12 at 22:02
  • Some clarification perhaps: I have a predefined set of Point objects, I'd like to lay the bounding volume (preferably a capsule) within this set and return all the points within the volume. – Arjun Sol Oct 29 '12 at 22:05

1 Answers1

0

If you only need to do this once, you can't get any better than checking each point against the bounding volume.

If you need to do multiple queries, you can improve the performance of your queries by setting up a spatial query structure. Note that you will first need to spend the time and memory to build and maintain your query structure, but that is fine if you can amortize the expense over a large number of queries.

Depending on your needs, you might want to use a grid, a quadtree, a K-d tree, or an R-tree to accelerate your spatial queries. The above is not an exhaustive list of acceleration structures, but it includes some of the most-used options.

comingstorm
  • 25,557
  • 3
  • 43
  • 67
  • Ok, I think I've found a workaround. I can query all the points on x y z fields e.g. "select * from points_table where x < capsule.maxX and x > capsule.minX" etc. This will give me all points within a box around the capsule. I can iterate these and check against capsule.contains. – Arjun Sol Nov 02 '12 at 15:52
  • Since you're accessing these from a database, you should know that some databases provide a spatial index which is designed for this kind of query. Try looking into Postgres, as an open-source example. – comingstorm Nov 02 '12 at 17:16
  • Indeed, I had thought of moving to mongodb, sadly it only supports a 2D index. – Arjun Sol Nov 02 '12 at 18:14