Friday, May 17, 2019

Exists a dedicated non-O(n²) Algorithm for avoiding to have overlapping elements?


I am generating positions in a random fashion.


In the game world, instantiated elements have a radius, and shouldn't overlap.


The problem is that they will overlap because I use a usual random number generator combined with other fanciness. I can't use other random number generation algorithms where I can guarantee that the elements will never overlap.


A way to solve this is to use a spatial data structure and search for the nearest neighbors in that tree. When I insert an element into that tree, I update it accordingly.


This solution would do the work and it would be fast but my question is:


Is there a dedicated algorithm without that Tree implementation complexity which is faster than O(n²)?




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...