Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Uniform feature points  (Read 4243 times)
0 Members and 1 Guest are viewing this topic.
Offline Wiki Duke

?





« Posted 2012-12-05 15:27:32 »

Note: you are watching revision 1 of this wiki entry. ( view plain diff )
Main/Procedural content

STUB (YEAH, I'M MAKING LOTS OF THESE) TO REMIND MYSELF TO DO A WRITE-UP.

Uniform Feature Points


Let us imagine that we have a 100x100 meter field and in this field we what there to be, on average, two flowers per meter squared.  So we could create an array with 100x100x2 = 20,000 elements to explicitly store the positions of each flower.  Using a seeded uniform random number generator we could then fill the array with repeatable coordinates for each.  If we were to examine the placement of flowers we would notice that there would be regions with none and areas where they are clummped up.

1  
2  
3  
4  
5  
6  
7  
rng.setSeed(someValue);

for(int i=0; i<100*100*2; i++) {
  float x = 100*rng.nextFloat();
  float y = 100*rng.nextFloat();
  doMyFlower(x,y);
}

Now if were to examine each square meter (or some other regular chunk) and count the number of flowers it contains, then the "distribution" of the counts matches the Poisson distribution.

So instead of precomputing a explicit list of "features", the space in question can be broken down into parts. For each part one computes a poisson random number to determine the number of features inside it.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
// From Knuth, reasonable on modern machines for smallish
// means.  There are many ways this can be computed.
// eMean = exp(-mean)
public static final int poisson(float eMean)
{
  int   r = 1;
  float t = rng.nextFloat();
 
  while (t > eMean) {
    r++;
    t *= rng.nextFloat();
  }
  return r-1;
}

// Sketch below this point
private static final float FLOWER_POWER = (float)Math.exp(-2);

private void doSomeCellFlowerThing(...)
{
  rng.setSeed(hashOfThisCell);

  int num = poisson(FLOWER_POWER);

  for(int i=0; i<num; i++) {
    // coordinates local to the square meter in this example
    float x = rng.nextFloat();
    float y = rng.nextFloat();
    ...
  }
}

This wiki entry has had 2 revisions with contributions from 1 members. (more info)
Offline Danny02
« Reply #1 - Posted 2012-12-05 17:33:14 »

for things like this I really like the halton sequence

maxis did some nice things in spore with this(point 3 (http://www.cs.cmu.edu/~ajw/s2007/)

I did an implementation of this here: https://github.com/Danny02/DarwinsBox/tree/master/Util/src/main/java/darwin/util/math/halton
Online Roquen
« Reply #2 - Posted 2012-12-05 17:51:56 »

quasi-random numbers do work pretty well...the complexity tends to be higher...unless I'm missing something.  The effect is different, but as long as it looks good...that's all that matters.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Danny02
« Reply #3 - Posted 2012-12-05 17:55:51 »

the halton sequence has some very nice deterministic properties which are explained very well in the linked presentation

i.e
while creating new elements of the sequence, the distribution is always "uniform"
Online Roquen
« Reply #4 - Posted 2012-12-06 05:42:25 »

Basically the difference is that quasi-random will give better coverage, which is more regular...less clumps & empty areas.  Actually the wikipedia picture gives pretty good idea: http://en.wikipedia.org/wiki/Halton_sequence

Offline Best Username Ever

Junior Devvie





« Reply #5 - Posted 2012-12-06 18:24:51 »

Quote
So instead of precomputing a explict list of "features", the space in question can be broken down into parts. For each part one computes a poisson random number to determine the number of features inside it.

Then what? Once you know how many flowers are in a certain grid location, how do you distribute them within it? What do you do about edges and corners?
Online Roquen
« Reply #6 - Posted 2012-12-06 18:34:54 »

They are uniformly distributed inside...I'm going to add some pseudo code for the example.  This is the technique that point-noise based functions (like cellular noise) is based on...for instance.
Online Roquen
« Reply #7 - Posted 2012-12-06 20:56:43 »

Updated the text...does that answer you're question?
Offline Best Username Ever

Junior Devvie





« Reply #8 - Posted 2012-12-06 23:48:03 »

According to that code they are randomly distributed within a cell, not uniformly distributed inside of it. A group of four cells could potentially could have a greater density of flowers around their shared corner and much lower density everywhere else. The same could apply to edges with two cells. Within one cell, multiple flowers could clump together.

They need to be uniformly distributed with respect to other objects in the same cell as well as to those in neighboring cells.
Online Roquen
« Reply #9 - Posted 2012-12-07 13:27:35 »

while creating new elements of the sequence, the distribution is always "uniform"

According to that code they are randomly distributed within a cell, not uniformly distributed inside of it.
...
They need to be uniformly distributed with respect to other objects in the same cell as well as to those in neighboring cells.

BUE & Danny02: you're both using a non-probability based notion of uniform or more specifically a uniform random process.  Added some text to deal with the notion of "uniform".

A group of four cells could potentially could have a greater density of flowers around their shared corner and much lower density everywhere else. The same could apply to edges with two cells. Within one cell, multiple flowers could clump together.
All these examples and opposite versions of them are likely and desirable.  It's exactly what's suppose to happen.  If you were to create two images with points, one globally and the other by breaking into parts and using poission and randomly choose to display one on the right and left...you shouldn't be able to identify which is which.  If you can, then the hashing isn't working.

The various test-suites of PRNG quality will perform many operations in the opposite direction from this.  Create a bunch of points in 'n' dimensions, then break that space up into various sized parts..count the number of contents inside each part and if the values don't approach the Poisson distribution, then it fails the test...the PRNG is not creating uniform random numbers in that number of dimensions.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Best Username Ever

Junior Devvie





« Reply #10 - Posted 2012-12-07 21:26:34 »

I see. You're talking about emulating a process where each point's location coordinates are selected at random with uniform probability. Not that the generated graphics look uniformly distributed. You had me confused when you were talking about the Halton sequence.

Or in other words, uniform like rolling a fair dice twice and plotting the values as x-y coordinates - but not uniform like a uniform distribution of points.
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (75 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (113 views)
2014-11-26 15:22:04

toopeicgaming1999 (100 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!