Creating a random scatter with constraints (trying to plot a forest)

Status
Not open for further replies.

morkus64

Diamond Member
Nov 7, 2004
3,302
1
81
Help!

I'm trying to figure out a way to generate a random scatter of points. The points would represent tree trunks, so i'd need something where I can say the minimum distance is maybe 25' apart and the max is 45'. Eventually I want to get this into autocad.

Anyone know of a way to do this?

TIA!
 

morkus64

Diamond Member
Nov 7, 2004
3,302
1
81
Or the other option would be something that can properly tell me where the individual trees in a forest are. :-/
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
1) Rent a tractor
2) Buy some seedlings
3) Get a GPS
4) Profit
 
Last edited:

vshah

Lifer
Sep 20, 2003
19,003
24
81
you need a random x,y coordinate generator that can look at previously generated points and not generate any new ones within 25' of those. Would be pretty simple to code in any language
 

dullard

Elite Member
May 21, 2001
25,742
4,266
126
It wouldn't take more than a few minutes to write code to do that.

1) Assume x and y are in feet (use 1 decimal point as that is all that would really be needed).
2) Randomly generate an x,y location for a hypothetical tree.
2b) Check to see if x,y lies in the forest area that you are conserned with. If not, delete this point and go to step 2.
3) Loop over all previous trees and see if the distance is within 25', if that is true, delete those points. If the distance is farther than 25', keep those points as a new tree.
4) Repeat steps 2 and 3 until you can't get any more trees after a set number of failures.
 
Oct 27, 2007
17,009
1
0
In C#, easily ported to any imperative language.

Code:
final int MAX_TREES = 100;
final int FOREST_DIAMETER = 1000;
final int MAX_DISTANCE = 45;
final int MIN_DISTANCE = 25;

Random r = new Random();
int num = 0;
List<Tree> trees = new List<Tree>();

while (num < MAX_TREES) {
	int x = r.next(FOREST_DIAMETER);
	int y = r.next(FOREST_DIAMETER);
	foreach (Tree t in trees) {
		float distance = Math.sqrt((t.x-x) + (t.y-y));
		if (distance > MAX_DISTANCE || distance < MIN_DISTANCE) {
			continue;
		}
	}
	trees.add(new Tree(x,y));
	num++;
}

You should put some constraints on the density (ratio of forest diameter to max trees) so you don't get stuck in an infinite loop.
 
Last edited:

Gibson486

Lifer
Aug 9, 2000
18,378
1
0
In C#, easily ported to any imperative language.

Code:
final int MAX_TREES = 100;
final int FORREST_DIAMETER = 1000;
final int MAX_DISTANCE = 45;
final int MIN_DISTANCE = 25;

Random r = new Random();
int num = 0;
List<Tree> trees = new List<Tree>();

while (num < MAX_TREES) {
    int x = r.next(FORREST_DIAMETER);
    int y = r.next(FORREST_DIAMETER);
    foreach (Tree t in trees) {
        float distance = Math.sqrt((t.x-x) + (t.y-y));
        if (distance > MAX_DISTANCE && distance < MIN_DISTANCE) {
            continue;
        }
    }
    trees.add(new Tree(x,y));
    num++;
}



or you could just do it the EE way. Just open autocad, make a dot, select dot, right click, select copy selection, move mouse and click like crazy.
 

morkus64

Diamond Member
Nov 7, 2004
3,302
1
81
or you could just do it the EE way. Just open autocad, make a dot, select dot, right click, select copy selection, move mouse and click like crazy.

I actually would do that, except it's about 8 acres of forest I'm trying to plot. But this programming stuff is beyond me. Hrm...
 

Hacp

Lifer
Jun 8, 2005
13,923
2
81
Its too hard. Pay me to do it. I won't swipe GA's code and present it as my own. I promise.
 
Status
Not open for further replies.