## 2 replies

Last post Sep 08, 2012 12:45 AM by Paul Linton

Member

216 Points

298 Posts

### Populate List of Coordinates Evenly

Hi, I'm trying to write a program which has a list of village objects. Each object contains a set of x and y coordinates. I then go through up to the max set coordinates and every coordinate check to see if an oject exists there, if one does, I show it to the user as being there.

My question is, how can I can populate this grid with these villages one at a time so that they're not too far from eachother and preferably sprout from the center out. One solution I had was to have a list of every coordinate randomly ordered and move from the un-populated list to the village list which meant there couldn't be any overlapping, but it was completely random and obviously not the best way to go about it. I need some kind of pattern to it and a push in the right direction would be of great help!

Thanks.

-Joseph Sawyer
I hope my post helps.

Star

14297 Points

5882 Posts

### Re: Populate List of Coordinates Evenly

Hi ... this forum is for "Questions about using C# for ASP.NET development", so, FWIW, it's usually a good idea to specify how your question relates to ASP.NET development when that's unclear from the context of your subject and O.P.

example:  http://www.purplemath.com/modules/distform.htm "The Distance Formula"

g.

B-)  Gerry Lowry, Chief Training Architect, Paradigm Mentors Learning never ends... +1 705-999-9195 wasaga beach, ontario canada TIMTOWTDI =.there is more than one way to do it

Star

9555 Points

2785 Posts

### Re: Populate List of Coordinates Evenly

Sep 08, 2012 12:45 AM|Paul Linton|LINK

Just a thought

Call the centre (0,0) assume that the x-coord goes from -100 to +100 and same for y-coord.  Now generate one random number in the range from 0 to 2, call it d.  Calculate 10^d, this will give you a number between 1 and 100 but half of the numbers will be between 1 and 10.  Generate another random number between 0 and 260 and call it a.  Now plot a village at a distance of 10D from the origin at an angle of a from the x axis.  This will make the villages cluter around the centre point.

If the clustering is too tight (or loose) then don't calculate 10^d but instead calculate M*(10^(N*d)) where M and N are constants that you can fine tune to get the sort of spread that you want.

Got a c# problem? Try .NET Book Zero from Charles Petzold, it's a free pdf.