Generate Random Position 2D Grid? (No Overlapping)

Blitz3D Forums/Blitz3D Programming/Generate Random Position 2D Grid? (No Overlapping)

videz(Posted 2015) [#1]
I'm looking for a quick solution for a 2D grid to randomly generate X,Y position on a number of items without overlapping.

Maybe someone has done this already or posted a code resource somewhere here before.

Thanks


Matty(Posted 2015) [#2]
Keep an array of the same size as the map and store a boolean in each location indicating if youve placed something there already. ..


videz(Posted 2015) [#3]
Yes thanks Matty. that was easy per pixel or location but I'm dealing with meshes or squares top down 2D with a random range defined scale.

Sorry if I was not being specific.


Matty(Posted 2015) [#4]
Well then simply write an "overlapping" function that returns a 1/0 and loop through all previous items that have been placed before placing a new one down checking the result of the function.

function overlapping(a,b)
{
   if(a.x>=b.x and a.y>=b.y and a.x<b.x+b.w and a.y<b.y+b.h) return true;
   if(a.x+a.w>=b.x and a.y+a.h>=b.y and a.x<b.x+b.w and a.y<b.y+b.h) return true;
  return false;
}




videz(Posted 2015) [#5]
thanks again Matty, I'll check this one out.