2D Point Poisson Distribution

edited April 2016 in How To...

Hi all,

Within my 400*400 screen, I'm trying to uniformly distribute x number of points using Poisson distribution.

Can anyone help out, I'm struggling to translate the formula into code.

Thanks in advance, Charles

Tagged:

Answers

  • edited April 2016

    http://StackOverflow.com/questions/1241555/algorithm-to-generate-poisson-and-binomial-random-numbers

    /**
     * Poisson Distribution (v1.0)
     * mod GoToLoop (2016-Apr-17)
     *
     * forum.Processing.org/two/discussion/16058/
     * 2d-point-poisson-distribution
     *
     * StackOverflow.com/questions/1241555/
     * algorithm-to-generate-poisson-and-binomial-random-numbers
     */
    
    void draw() {
      noLoop();
      println();
    
      for (float l = 1; l < 10; l += QUARTER_PI)
        println(l, TAB, poisson(l));
    
      background((color) random(#000000));
    }
    
    void mousePressed() {
      redraw();
    }
    
    void keyPressed() {
      redraw();
    }
    
    static final int poisson(final double lambda) {
      final double L = Math.exp(-lambda);
    
      double p = 1;
      int k = -1;
    
      do ++k; 
      while ((p *= Math.random()) > L);
    
      return k;
    }
    
  • Thanks, however without comments I find it just as hard to understand. Would you mind clarifying what's going on, how would I get the x and y? Also, I'm not familiar with final and static.

    Thanks again

  • edited April 2016

    As I've linked above I've grabbed it from http://StackOverflow.com and adapted it to Processing.
    I dunno what's behind the algorithm & never heard about it either! X_X
    It only accepts a parameter called lambda. Maybe try out passing your coordinates as such? :-/

  • Also, I'm not familiar with final and static.

    You can remove both if you wish. It doesn't change anything after all. :P

    1. https://Processing.org/reference/final.html
    2. https://Processing.org/reference/static.html
Sign In or Register to comment.