Last post Sep 08, 2012 12:45 AM by Paul Linton
Sep 07, 2012 01:57 PM|bohunt|LINK
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!
Sep 07, 2012 02:39 PM|gerryLowry|LINK
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.
from reading your question, it appears that your creating some form of game.
bohunt, basic arithmetic will help you:
example: http://www.purplemath.com/modules/distform.htm "The Distance Formula"
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.