Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient represention for growing circles in 2D space?

Imagines there's a 2D space and in this space there are circles that grow at different constant rates. What's an efficient data structure for storing theses circles, such that I can query "Which circles intersect point p at time t?".

EDIT: I do realize that I could store the initial state of the circles in a spatial data structure and do a query where I intersect a circle at point p with a radius of fastest_growth * t, but this isn't efficient when there are a few circles that grow extremely quickly whereas most grow slowly.

Additional Edit: I could further augment the above approach by splitting up the circles and grouping them by there growth rate, then applying the above approach to each group, but this requires a bounded time to be efficient.

like image 264
dan_waterworth Avatar asked Jan 27 '12 10:01

dan_waterworth


2 Answers

Represent the circles as cones in 3d, where the third dimension is time. Then use a BSP tree to partition them the best you can.

In general, I think the worst-case for testing for intersection is always O(n), where n is the number of circles. Most spacial data structures work by partitioning the space cleverly so that a fraction of the objects (hopefully close to half) are in each half. However, if the objects overlap then the partitioning cannot be perfect; there will always be cases where more than one object is in a partition. If you just think about the case of two circles overlapping, there is no way to draw a line such that one circle is entirely on one side and the other circle is entirely on the other side. Taken to the logical extreme, assuming arbitrary positioning of the circles and arbitrary radiuses, there is no way to partition them such that testing for intersection takes O(log(n)).

This doesn't mean that, in practice, you won't get a big advantage from using a tree, but the advantage you get will depend on the configuration of the circles and the distribution of the queries.

like image 72
Sam Avatar answered Oct 18 '22 02:10

Sam


This is a simplified version of another problem I have posted about a week ago: How to find first intersection of a ray with moving circles

I still haven't had the time to describe the solution that was expected there, but I will try to outline it here(for this simplar case).

The approach to solve this problem is to use a kinetic KD-tree. If you are not familiar with KD trees it is better to first read about them. You also need to add the time as additional coordinate(you make the space 3d instead of 2d). I have not implemented this idea yet, but I believe this is the correct approach.

like image 1
Ivaylo Strandjev Avatar answered Oct 18 '22 03:10

Ivaylo Strandjev