Author Topic: Poisson Disk Sampling - Bridson Algorithm - Blue Noise  (Read 11649 times)

0 Members and 1 Guest are viewing this topic.

ymg

  • Guest
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #15 on: May 07, 2015, 03:42:13 AM »
qjchen,

Thanks, I am not too familiar with finite element but it could be.

Sampling function and Noise functions are extensively used in
Texture generation and Graphic Filters (Photoshop).

ymg

ribarm

  • Gator
  • Posts: 3268
  • Marko Ribar, architect
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #16 on: May 07, 2015, 04:45:53 AM »
Anyway it seems that the best thing to overcome this intensive waving is actually to code it for waving... Here is my wave version, but put 1 or 2 waves when asked...

Code - Auto/Visual Lisp: [Select]
  1. ;;                                                                            ;
  2. ;; Poisson Disk Sampling per Bridson Algorithm                                ;
  3. ;;                                                                            ;
  4. ;; See: http://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf;
  5. ;;      http://devmag.org.za/2009/05/03/poisson-disk-sampling/                ;
  6. ;;                                                                            ;
  7. ;; Will return a Random Set of points with a minimum distance between them    ;
  8. ;;                                                                            ;
  9.  
  10. (defun bridson (ll    ur    mindist     /     a     al    cells cellsize
  11.                 grid  i     ind   k     p     p1    p2    pl    r
  12.                 tcl   x     y
  13.                )
  14.   (setq k        30
  15.         width    (- (car ur) (car ll))
  16.         height   (- (cadr ur) (cadr ll))
  17.         cellSize (/ mindist (sqrt 2))
  18.         x        (ceil (/ width cellsize))
  19.         y        (ceil (/ height cellsize))
  20.         x0       (car ll)
  21.         y0       (cadr ll)
  22.         grid     (vlax-make-safearray vlax-vbInteger (cons 0 x) (cons 0 y))
  23.         p1       (list (rand width) (rand height))
  24.         pl       (list p1)
  25.         al       (list 0)               ; Initialize Active List with index of First Point;
  26.         ind      (mapcar '(lambda (a) (fix (/ a cellsize))) p1)
  27.  
  28.   )
  29.   (init2d grid x y)                     ; Initialize the grid to all -1, then             ;
  30.  
  31.   (vlax-safearray-put-element grid (car ind) (cadr ind) 0)
  32.  
  33.   (setq i 0)
  34.   (while al
  35.     (setq p  (nth (fix (rand (length al))) al)
  36.           p1 (nth p pl)
  37.           p1 (list (car p1) (cadr p1))
  38.     )
  39.     (repeat k
  40.       (setq a   (rand (+ pi pi))
  41.             r   (* mindist (+ 1.0 (rand 1.0)))
  42.             p2  (polar p1 a r)
  43.             ind (mapcar '(lambda (a) (fix (/ a cellsize))) p2)
  44.       )
  45.       (if (and (<= 0 (car p2) width) (<= 0 (cadr p2) height))
  46.         (progn
  47.           (setq cells (ptsaround grid ind))
  48.           (if cells
  49.             (setq tcl (tooclosep p2 cells pl))
  50.             (setq tcl nil)
  51.           )
  52.           (if (not tcl)
  53.             (progn
  54.               (setq i  (1+ i)
  55.                     al (cons i al)
  56.                     pl (append pl (list p2))
  57.               )
  58.  
  59.               (vlax-safearray-put-element grid (car ind) (cadr ind) i)
  60.             )
  61.           )
  62.         )
  63.       )
  64.     )
  65.     (setq al (vl-remove p al))
  66.  
  67.   )
  68.  
  69.   (mapcar '(lambda (a) (list (+ (car a) x0) (+ (cadr a) y0) 0.0))
  70.           pl
  71.   )
  72. )
  73.  
  74. (defun init2d (grid x y / i j)
  75.   (setq i -1)
  76.   (repeat x
  77.     (setq i (1+ i)
  78.           j -1
  79.     )
  80.     (repeat y
  81.       (setq j (1+ j))
  82.       (vlax-safearray-put-element grid i j -1)
  83.     )
  84.   )
  85. )
  86.  
  87.  
  88. (defun ptsaround (grid ind / i j rtn tmp)
  89.  
  90.   (setq j (- (cadr ind) 2))
  91.   (repeat 5
  92.     (setq i (- (car ind) 2))
  93.     (repeat 5
  94.       (if (and (< -1 i x) (< -1 j y))
  95.         (if
  96.           (not (= (setq tmp (vlax-safearray-get-element grid i j)) -1)
  97.           )
  98.            (setq rtn (cons tmp rtn))
  99.         )
  100.       )
  101.       (setq i (1+ i))
  102.     )
  103.     (setq j (1+ j))
  104.   )
  105.   rtn
  106. )
  107.  
  108. (defun tooclosep (p cells pl / pc rtn)
  109.   (while cells
  110.     (setq pc    (nth (car cells) pl)
  111.           cells (cdr cells)
  112.     )
  113.     (if (< (distance pc p) mindist)
  114.       (setq rtn t
  115.             cells nil
  116.       )
  117.     )
  118.   )
  119.   rtn
  120. )
  121. ;; Random number generator, Seed must remain global.    LeeMac                ;
  122. ;; Will return a real in the range 0...rng                                    ;
  123.  
  124. (defun rand (rng / x)
  125.   (* (/ (setq x    4294967296.0
  126.               seed (rem (1+ (* 1664525.0
  127.                                (cond (seed)
  128.                                      ((getvar 'DATE))
  129.                                )
  130.                             )
  131.                         )
  132.                         x
  133.                    )
  134.         )
  135.         x
  136.      )
  137.      rng
  138.   )
  139. )
  140.  
  141. ;; Floor function, Returns the largest integer not greater than x.            ;
  142. (defun floor (x)
  143.   (if (minusp (rem x 1))
  144.     (- (fix x) 1)
  145.     (fix x)
  146.   )
  147. )
  148. ;; Ceiling function, Returns the smallest integer not less than x.            ;
  149. (defun ceil (x)
  150.   (if (> (rem x 1) 0)
  151.     (+ (fix x) 1)
  152.     (fix x)
  153.   )
  154. )
  155.  
  156. (defun c:test (/ ** p1 p2 bb md zz nw dw kk jj ii z zi zl i dl dr dlst j k e pl pll)
  157.  
  158.  
  159.   (command "_.UCS" "_W")
  160.   (setq p1 (getpoint "\nPick a Window Defining Zone: ")
  161.         p2 (getcorner p1)
  162.         ** (vl-cmdf "_.RECTANGLE" "_non" p1 "_non" p2)
  163.         pl (list p1 p2)
  164.         bb (list (apply 'mapcar (cons 'min pl))
  165.                  (apply 'mapcar (cons 'max pl))
  166.            )
  167.         ** (vl-cmdf "_.UCS" "_M" "_non" (car bb))
  168.         bb (mapcar '(lambda (p) (trans p 0 1)) bb)
  169.         md (getdist
  170.              "\nPick or specify Minimum Distance Between Points : "
  171.            )
  172.         zz (getdist
  173.              "\nPick or specify Maximum Elevation above and below 0.0 : "
  174.            )
  175.         ** (initget 7)
  176.         nw (getint
  177.              "\nSpecify number of waves along X axis : "
  178.            )
  179.         ** (entlast)
  180.         pl (bridson (car bb) (cadr bb) md)
  181.         pl (vl-sort pl '(lambda (a b) (< (car a) (car b))))
  182.         kk -1
  183.   )
  184.  
  185.   (repeat nw
  186.     (setq jj 0)
  187.     (setq kk (1+ kk))
  188.     (repeat 16
  189.       (setq jj (1+ jj))
  190.       (setq ii (+ (* kk 16) jj))
  191.       (cond
  192.         ((= jj 1)
  193.          (repeat 5
  194.            (setq z (* zz (rand 1.0) 0.25))
  195.            (setq zi (cons ii z))
  196.            (setq zl (cons zi zl))
  197.          )
  198.         )
  199.         ((= jj 2)
  200.          (repeat 5
  201.            (setq z (+ (* zz 0.25) (* zz (rand 1.0) 0.25)))
  202.            (setq zi (cons ii z))
  203.            (setq zl (cons zi zl))
  204.          )
  205.         )
  206.         ((= jj 3)
  207.          (repeat 5
  208.            (setq z (+ (* zz 0.5) (* zz (rand 1.0) 0.25)))
  209.            (setq zi (cons ii z))
  210.            (setq zl (cons zi zl))
  211.          )
  212.         )
  213.         ((= jj 4)
  214.          (repeat 5
  215.            (setq z (+ (* zz 0.75) (* zz (rand 1.0) 0.25)))
  216.            (setq zi (cons ii z))
  217.            (setq zl (cons zi zl))
  218.          )
  219.         )
  220.         ((= jj 5)
  221.          (repeat 5
  222.            (setq z (+ (* zz 0.75) (* zz (rand 1.0) 0.25)))
  223.            (setq zi (cons ii z))
  224.            (setq zl (cons zi zl))
  225.          )
  226.         )
  227.         ((= jj 6)
  228.          (repeat 5
  229.            (setq z (+ (* zz 0.5) (* zz (rand 1.0) 0.25)))
  230.            (setq zi (cons ii z))
  231.            (setq zl (cons zi zl))
  232.          )
  233.         )
  234.         ((= jj 7)
  235.          (repeat 5
  236.            (setq z (+ (* zz 0.25) (* zz (rand 1.0) 0.25)))
  237.            (setq zi (cons ii z))
  238.            (setq zl (cons zi zl))
  239.          )
  240.         )
  241.         ((= jj 8)
  242.          (repeat 5
  243.            (setq z (* zz (rand 1.0) 0.25))
  244.            (setq zi (cons ii z))
  245.            (setq zl (cons zi zl))
  246.          )
  247.         )
  248.         ((= jj 9)
  249.          (repeat 5
  250.            (setq z (* (- zz) (rand 1.0) 0.25))
  251.            (setq zi (cons ii z))
  252.            (setq zl (cons zi zl))
  253.          )
  254.         )
  255.         ((= jj 10)
  256.          (repeat 5
  257.            (setq z (+ (* (- zz) 0.25) (* (- zz) (rand 1.0) 0.25)))
  258.            (setq zi (cons ii z))
  259.            (setq zl (cons zi zl))
  260.          )
  261.         )
  262.         ((= jj 11)
  263.          (repeat 5
  264.            (setq z (+ (* (- zz) 0.5) (* (- zz) (rand 1.0) 0.25)))
  265.            (setq zi (cons ii z))
  266.            (setq zl (cons zi zl))
  267.          )
  268.         )
  269.         ((= jj 12)
  270.          (repeat 5
  271.            (setq z (+ (* (- zz) 0.75) (* (- zz) (rand 1.0) 0.25)))
  272.            (setq zi (cons ii z))
  273.            (setq zl (cons zi zl))
  274.          )
  275.         )
  276.         ((= jj 13)
  277.          (repeat 5
  278.            (setq z (+ (* (- zz) 0.75) (* (- zz) (rand 1.0) 0.25)))
  279.            (setq zi (cons ii z))
  280.            (setq zl (cons zi zl))
  281.          )
  282.         )
  283.         ((= jj 14)
  284.          (repeat 5
  285.            (setq z (+ (* (- zz) 0.5) (* (- zz) (rand 1.0) 0.25)))
  286.            (setq zi (cons ii z))
  287.            (setq zl (cons zi zl))
  288.          )
  289.         )
  290.         ((= jj 15)
  291.          (repeat 5
  292.            (setq z (+ (* (- zz) 0.25) (* (- zz) (rand 1.0) 0.25)))
  293.            (setq zi (cons ii z))
  294.            (setq zl (cons zi zl))
  295.          )
  296.         )
  297.         ((= jj 16)
  298.          (repeat 5
  299.            (setq z (* (- zz) (rand 1.0) 0.25))
  300.            (setq zi (cons ii z))
  301.            (setq zl (cons zi zl))
  302.          )
  303.         )
  304.       )
  305.     )
  306.   )
  307.  
  308.   (setq dw (/ (caadr bb) ii))
  309.   (setq i 0)
  310.   (repeat ii
  311.     (setq i (1+ i))
  312.     (setq dl (* (1- i) dw)
  313.           dr (* i dw)
  314.     )
  315.     (setq dlst (cons (cons i (list dl dr)) dlst))
  316.   )
  317.   (setq dlst (reverse dlst))
  318.   (foreach p pl
  319.     (setq j (vl-some '(lambda ( x ) (if (< (cadr x) (car p) (caddr x)) (car x))) dlst))
  320.     (setq k (acet-list-m-assoc j zl))
  321.     (setq e (cdr (nth (fix (rand (length k))) k)))
  322.     (setq p (list (car p) (cadr p) e))
  323.     (setq pll (cons p pll))
  324.   )
  325.  
  326.   (setq pll (reverse pll))
  327.  
  328.   (mapcar '(lambda (a)
  329.              (entmake (list '(0 . "POINT") '(8 . "Point") (cons 10 a)))
  330.            )
  331.           (mapcar '(lambda (b) (trans b 1 0)) pll)
  332.   )
  333.                                         ;(entdel **)
  334.   (princ)
  335. )
  336.  

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ymg

  • Guest
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #17 on: May 07, 2015, 07:01:01 AM »
Marko,

Nice !!!, here generated with your wave proggie.

Possibilities are endless.

ymg

« Last Edit: May 07, 2015, 07:04:21 AM by ymg »

ribarm

  • Gator
  • Posts: 3268
  • Marko Ribar, architect
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #18 on: May 07, 2015, 07:52:34 AM »
Now that I've posted linear X axis version, here is radial one based on the same algorithm... File is little larger, so I'll attach it...

M.R.
« Last Edit: May 07, 2015, 08:39:19 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ymg

  • Guest
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #19 on: May 07, 2015, 04:26:57 PM »
Marko,

I didn't have a chance yet to test your radial wave but I will.

I was on the Net researching some more on "Perlin Noise"
and I stumbled on this to generate a landscape on a sphere.

I know you like to work with them sphere, so have a look
here:   http://freespace.virgin.net/hugo.elias/models/m_landsp.htm

It is again by the same guy Hugo Elias.


ymg


ribarm

  • Gator
  • Posts: 3268
  • Marko Ribar, architect
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #20 on: May 08, 2015, 11:00:48 AM »
I don't know ab spheres, but for a mathematical functions projected on elevations, combination of RND planar distribution and elevations obtained by points 2D data for waves is certainly possible by sinus function... So no need to double RND algorthim - it can be used just for poison 2D distribution... I am curious how no one haven't posted remark ab this... And codes are smaller than I've imagined...

For X axis waving...
Code - Auto/Visual Lisp: [Select]
  1. ;;                                                                            ;
  2. ;; Poisson Disk Sampling per Bridson Algorithm                                ;
  3. ;;                                                                            ;
  4. ;; See: http://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf;
  5. ;;      http://devmag.org.za/2009/05/03/poisson-disk-sampling/                ;
  6. ;;                                                                            ;
  7. ;; Will return a Random Set of points with a minimum distance between them    ;
  8. ;;                                                                            ;
  9.  
  10. (defun bridson (ll    ur    mindist     /     a     al    cells cellsize
  11.                 grid  i     ind   k     p     p1    p2    pl    r
  12.                 tcl   x     y
  13.                )
  14.   (setq k        30
  15.         width    (- (car ur) (car ll))
  16.         height   (- (cadr ur) (cadr ll))
  17.         cellSize (/ mindist (sqrt 2))
  18.         x        (ceil (/ width cellsize))
  19.         y        (ceil (/ height cellsize))
  20.         x0       (car ll)
  21.         y0       (cadr ll)
  22.         grid     (vlax-make-safearray vlax-vbInteger (cons 0 x) (cons 0 y))
  23.         p1       (list (rand width) (rand height))
  24.         pl       (list p1)
  25.         al       (list 0)               ; Initialize Active List with index of First Point;
  26.         ind      (mapcar '(lambda (a) (fix (/ a cellsize))) p1)
  27.  
  28.   )
  29.   (init2d grid x y)                     ; Initialize the grid to all -1, then             ;
  30.  
  31.   (vlax-safearray-put-element grid (car ind) (cadr ind) 0)
  32.  
  33.   (setq i 0)
  34.   (while al
  35.     (setq p  (nth (fix (rand (length al))) al)
  36.           p1 (nth p pl)
  37.           p1 (list (car p1) (cadr p1))
  38.     )
  39.     (repeat k
  40.       (setq a   (rand (+ pi pi))
  41.             r   (* mindist (+ 1.0 (rand 1.0)))
  42.             p2  (polar p1 a r)
  43.             ind (mapcar '(lambda (a) (fix (/ a cellsize))) p2)
  44.       )
  45.       (if (and (<= 0 (car p2) width) (<= 0 (cadr p2) height))
  46.         (progn
  47.           (setq cells (ptsaround grid ind))
  48.           (if cells
  49.             (setq tcl (tooclosep p2 cells pl))
  50.             (setq tcl nil)
  51.           )
  52.           (if (not tcl)
  53.             (progn
  54.               (setq i  (1+ i)
  55.                     al (cons i al)
  56.                     pl (append pl (list p2))
  57.               )
  58.  
  59.               (vlax-safearray-put-element grid (car ind) (cadr ind) i)
  60.             )
  61.           )
  62.         )
  63.       )
  64.     )
  65.     (setq al (vl-remove p al))
  66.  
  67.   )
  68.  
  69.   (mapcar '(lambda (a) (list (+ (car a) x0) (+ (cadr a) y0) 0.0))
  70.           pl
  71.   )
  72. )
  73.  
  74. (defun init2d (grid x y / i j)
  75.   (setq i -1)
  76.   (repeat x
  77.     (setq i (1+ i)
  78.           j -1
  79.     )
  80.     (repeat y
  81.       (setq j (1+ j))
  82.       (vlax-safearray-put-element grid i j -1)
  83.     )
  84.   )
  85. )
  86.  
  87.  
  88. (defun ptsaround (grid ind / i j rtn tmp)
  89.  
  90.   (setq j (- (cadr ind) 2))
  91.   (repeat 5
  92.     (setq i (- (car ind) 2))
  93.     (repeat 5
  94.       (if (and (< -1 i x) (< -1 j y))
  95.         (if
  96.           (not (= (setq tmp (vlax-safearray-get-element grid i j)) -1)
  97.           )
  98.            (setq rtn (cons tmp rtn))
  99.         )
  100.       )
  101.       (setq i (1+ i))
  102.     )
  103.     (setq j (1+ j))
  104.   )
  105.   rtn
  106. )
  107.  
  108. (defun tooclosep (p cells pl / pc rtn)
  109.   (while cells
  110.     (setq pc    (nth (car cells) pl)
  111.           cells (cdr cells)
  112.     )
  113.     (if (< (distance pc p) mindist)
  114.       (setq rtn t
  115.             cells nil
  116.       )
  117.     )
  118.   )
  119.   rtn
  120. )
  121. ;; Random number generator, Seed must remain global.    LeeMac                ;
  122. ;; Will return a real in the range 0...rng                                    ;
  123.  
  124. (defun rand (rng / x)
  125.   (* (/ (setq x    4294967296.0
  126.               seed (rem (1+ (* 1664525.0
  127.                                (cond (seed)
  128.                                      ((getvar 'DATE))
  129.                                )
  130.                             )
  131.                         )
  132.                         x
  133.                    )
  134.         )
  135.         x
  136.      )
  137.      rng
  138.   )
  139. )
  140.  
  141. ;; Floor function, Returns the largest integer not greater than x.            ;
  142. (defun floor (x)
  143.   (if (minusp (rem x 1))
  144.     (- (fix x) 1)
  145.     (fix x)
  146.   )
  147. )
  148. ;; Ceiling function, Returns the smallest integer not less than x.            ;
  149. (defun ceil (x)
  150.   (if (> (rem x 1) 0)
  151.     (+ (fix x) 1)
  152.     (fix x)
  153.   )
  154. )
  155.  
  156. (defun c:test (/ ** p1 p2 bb md zz nw dw e pl pll)
  157.  
  158.  
  159.   (command "_.UCS" "_W")
  160.   (setq p1 (getpoint "\nPick a Window Defining Zone: ")
  161.         p2 (getcorner p1)
  162.         ** (vl-cmdf "_.RECTANGLE" "_non" p1 "_non" p2)
  163.         pl (list p1 p2)
  164.         bb (list (apply 'mapcar (cons 'min pl))
  165.                  (apply 'mapcar (cons 'max pl))
  166.            )
  167.         ** (vl-cmdf "_.UCS" "_M" "_non" (car bb))
  168.         bb (mapcar '(lambda (p) (trans p 0 1)) bb)
  169.         md (getdist
  170.              "\nPick or specify Minimum Distance Between Points : "
  171.            )
  172.         zz (getdist
  173.              "\nPick or specify Maximum Elevation above and below 0.0 : "
  174.            )
  175.         ** (initget 7)
  176.         nw (getint
  177.              "\nSpecify number of waves along X axis : "
  178.            )
  179.         ** (entlast)
  180.         pl (bridson (car bb) (cadr bb) md)
  181.         pl (vl-sort pl '(lambda (a b) (< (car a) (car b))))
  182.   )
  183.  
  184.   (setq dw (/ (caadr bb) nw))
  185.   (foreach p pl
  186.     (setq e (* zz (sin (* (/ (rem (car p) dw) dw) 2.0 pi))))
  187.     (setq p (list (car p) (cadr p) e))
  188.     (setq pll (cons p pll))
  189.   )
  190.  
  191.   (setq pll (reverse pll))
  192.  
  193.   (mapcar '(lambda (a)
  194.              (entmake (list '(0 . "POINT") '(8 . "Point") (cons 10 a)))
  195.            )
  196.           (mapcar '(lambda (b) (trans b 1 0)) pll)
  197.   )
  198.                                         ;(entdel **)
  199.   (princ)
  200. )
  201.  

For radial waving...
Code - Auto/Visual Lisp: [Select]
  1. ;;                                                                            ;
  2. ;; Poisson Disk Sampling per Bridson Algorithm                                ;
  3. ;;                                                                            ;
  4. ;; See: http://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf;
  5. ;;      http://devmag.org.za/2009/05/03/poisson-disk-sampling/                ;
  6. ;;                                                                            ;
  7. ;; Will return a Random Set of points with a minimum distance between them    ;
  8. ;;                                                                            ;
  9.  
  10. (defun bridson (ll    ur    mindist     /     a     al    cells cellsize
  11.                 grid  i     ind   k     p     p1    p2    pl    r
  12.                 tcl   x     y
  13.                )
  14.   (setq k        30
  15.         width    (- (car ur) (car ll))
  16.         height   (- (cadr ur) (cadr ll))
  17.         cellSize (/ mindist (sqrt 2))
  18.         x        (ceil (/ width cellsize))
  19.         y        (ceil (/ height cellsize))
  20.         x0       (car ll)
  21.         y0       (cadr ll)
  22.         grid     (vlax-make-safearray vlax-vbInteger (cons 0 x) (cons 0 y))
  23.         p1       (list (rand width) (rand height))
  24.         pl       (list p1)
  25.         al       (list 0)               ; Initialize Active List with index of First Point;
  26.         ind      (mapcar '(lambda (a) (fix (/ a cellsize))) p1)
  27.  
  28.   )
  29.   (init2d grid x y)                     ; Initialize the grid to all -1, then             ;
  30.  
  31.   (vlax-safearray-put-element grid (car ind) (cadr ind) 0)
  32.  
  33.   (setq i 0)
  34.   (while al
  35.     (setq p  (nth (fix (rand (length al))) al)
  36.           p1 (nth p pl)
  37.           p1 (list (car p1) (cadr p1))
  38.     )
  39.     (repeat k
  40.       (setq a   (rand (+ pi pi))
  41.             r   (* mindist (+ 1.0 (rand 1.0)))
  42.             p2  (polar p1 a r)
  43.             ind (mapcar '(lambda (a) (fix (/ a cellsize))) p2)
  44.       )
  45.       (if (and (<= 0 (car p2) width) (<= 0 (cadr p2) height))
  46.         (progn
  47.           (setq cells (ptsaround grid ind))
  48.           (if cells
  49.             (setq tcl (tooclosep p2 cells pl))
  50.             (setq tcl nil)
  51.           )
  52.           (if (not tcl)
  53.             (progn
  54.               (setq i  (1+ i)
  55.                     al (cons i al)
  56.                     pl (append pl (list p2))
  57.               )
  58.  
  59.               (vlax-safearray-put-element grid (car ind) (cadr ind) i)
  60.             )
  61.           )
  62.         )
  63.       )
  64.     )
  65.     (setq al (vl-remove p al))
  66.  
  67.   )
  68.  
  69.   (mapcar '(lambda (a) (list (+ (car a) x0) (+ (cadr a) y0) 0.0))
  70.           pl
  71.   )
  72. )
  73.  
  74. (defun init2d (grid x y / i j)
  75.   (setq i -1)
  76.   (repeat x
  77.     (setq i (1+ i)
  78.           j -1
  79.     )
  80.     (repeat y
  81.       (setq j (1+ j))
  82.       (vlax-safearray-put-element grid i j -1)
  83.     )
  84.   )
  85. )
  86.  
  87.  
  88. (defun ptsaround (grid ind / i j rtn tmp)
  89.  
  90.   (setq j (- (cadr ind) 2))
  91.   (repeat 5
  92.     (setq i (- (car ind) 2))
  93.     (repeat 5
  94.       (if (and (< -1 i x) (< -1 j y))
  95.         (if
  96.           (not (= (setq tmp (vlax-safearray-get-element grid i j)) -1)
  97.           )
  98.            (setq rtn (cons tmp rtn))
  99.         )
  100.       )
  101.       (setq i (1+ i))
  102.     )
  103.     (setq j (1+ j))
  104.   )
  105.   rtn
  106. )
  107.  
  108. (defun tooclosep (p cells pl / pc rtn)
  109.   (while cells
  110.     (setq pc    (nth (car cells) pl)
  111.           cells (cdr cells)
  112.     )
  113.     (if (< (distance pc p) mindist)
  114.       (setq rtn t
  115.             cells nil
  116.       )
  117.     )
  118.   )
  119.   rtn
  120. )
  121. ;; Random number generator, Seed must remain global.    LeeMac                ;
  122. ;; Will return a real in the range 0...rng                                    ;
  123.  
  124. (defun rand (rng / x)
  125.   (* (/ (setq x    4294967296.0
  126.               seed (rem (1+ (* 1664525.0
  127.                                (cond (seed)
  128.                                      ((getvar 'DATE))
  129.                                )
  130.                             )
  131.                         )
  132.                         x
  133.                    )
  134.         )
  135.         x
  136.      )
  137.      rng
  138.   )
  139. )
  140.  
  141. ;; Floor function, Returns the largest integer not greater than x.            ;
  142. (defun floor (x)
  143.   (if (minusp (rem x 1))
  144.     (- (fix x) 1)
  145.     (fix x)
  146.   )
  147. )
  148. ;; Ceiling function, Returns the smallest integer not less than x.            ;
  149. (defun ceil (x)
  150.   (if (> (rem x 1) 0)
  151.     (+ (fix x) 1)
  152.     (fix x)
  153.   )
  154. )
  155.  
  156. (defun c:test (/ ** p1 p2 bb md zz wl cp dd nw ch f e pl pll)
  157.  
  158.  
  159.   (command "_.UCS" "_W")
  160.   (setq p1 (getpoint "\nPick a Window Defining Zone: ")
  161.         p2 (getcorner p1)
  162.         ** (vl-cmdf "_.RECTANGLE" "_non" p1 "_non" p2)
  163.         pl (list p1 p2)
  164.         bb (list (apply 'mapcar (cons 'min pl))
  165.                  (apply 'mapcar (cons 'max pl))
  166.            )
  167.         ** (vl-cmdf "_.UCS" "_M" "_non" (car bb))
  168.         bb (mapcar '(lambda (p) (trans p 0 1)) bb)
  169.         md (getdist
  170.              "\nPick or specify Minimum Distance Between Points : "
  171.            )
  172.         zz (getdist
  173.              "\nPick or specify Maximum Elevation above and below 0.0 : "
  174.            )
  175.         wl (getdist
  176.              "\nPick or specify Length of wave period : "
  177.            )
  178.         cp (getpoint
  179.              "\nPick or specify center point of radial waving : "
  180.            )
  181.         dd (car (vl-sort (list (distance cp (car bb)) (distance cp (list (caadr bb) (cadar bb))) (distance cp (cadr bb)) (distance cp (list (caar bb) (cadadr bb)))) '>))
  182.         ** (initget 7)
  183.         nw (getint
  184.              (strcat
  185.                "\nSpecify number of waves along radial axis (must be > "
  186.                (itoa (fix (/ dd wl)))
  187.                ") : "
  188.              )
  189.            )
  190.         ** (entlast)
  191.   )
  192.   (while (<= nw (fix (/ dd wl)))
  193.     (initget 7)
  194.     (setq nw (getint
  195.               (strcat
  196.                 "\nSpecify number of waves along radial axis (must be > "
  197.                 (itoa (fix (/ dd wl)))
  198.                 ") : "
  199.               )
  200.             )
  201.     )
  202.   )
  203.  
  204.   (setq
  205.         pl (bridson (car bb) (cadr bb) md)
  206.         pl (vl-sort pl '(lambda (a b) (< (distance cp a) (distance cp b))))
  207.   )
  208.  
  209.   (initget 1 "Up Down Top Bottom")
  210.   (setq ch (getkword "\nSpecify starting waving option [Up/Down/Top/Bottom] : "))
  211.   (cond
  212.     ( (eq ch "Up")
  213.       (defun f ( x ) (sin x))
  214.     )
  215.     ( (eq ch "Down")
  216.       (defun f ( x ) (- (sin x)))
  217.     )
  218.     ( (eq ch "Top")
  219.       (defun f ( x ) (sin (+ x (* 0.5 pi))))
  220.     )
  221.     ( (eq ch "Bottom")
  222.       (defun f ( x ) (sin (- x (* 0.5 pi))))
  223.     )
  224.   )
  225.  
  226.   (foreach p pl
  227.     (setq e (* zz (f (* (/ (rem (distance cp p) wl) wl) 2.0 pi))))
  228.     (setq p (list (car p) (cadr p) e))
  229.     (setq pll (cons p pll))
  230.   )
  231.  
  232.   (setq pll (reverse pll))
  233.  
  234.   (mapcar '(lambda (a)
  235.              (entmake (list '(0 . "POINT") '(8 . "Point") (cons 10 a)))
  236.            )
  237.           (mapcar '(lambda (b) (trans b 1 0)) pll)
  238.   )
  239.                                         ;(entdel **)
  240.   (princ)
  241. )
  242.  

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ymg

  • Guest
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #21 on: May 08, 2015, 12:12:15 PM »
Quote
... I am curious how no one haven't posted remark ab this...

Marko,

I posted Bridson in 2013, never generated any interest.

Seems to be changing.  :-)

ymg

danallen

  • Guest
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #22 on: May 08, 2015, 12:32:16 PM »
for me this post caught my attention showing how an algorithm can differentiate two kinds of random (with a picture!)
http://www.theswamp.org/index.php?topic=45379.msg544989#msg544989

Quote
I posted Bridson in 2013, never generated any interest.

ymg

  • Guest
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #23 on: May 08, 2015, 01:01:31 PM »
for me this post caught my attention showing how an algorithm can differentiate two kinds of random (with a picture!)
http://www.theswamp.org/index.php?topic=45379.msg544989#msg544989


Dan,

Guess the saying "A Picture is Worth a Thousand Words" holds.

ymg

ribarm

  • Gator
  • Posts: 3268
  • Marko Ribar, architect
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #24 on: May 08, 2015, 01:05:40 PM »
I am curious how no one haven't posted remark ab this...

What I mean, I've used RND twice in my previous versions and I thought that someone will notice that I could use sine function instead of imitating waves with RND for elevations...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ymg

  • Guest
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #25 on: May 08, 2015, 01:25:55 PM »
Marko,

You can apply just about any function.

Random is interesting to get variety.

ymg

ribarm

  • Gator
  • Posts: 3268
  • Marko Ribar, architect
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #26 on: May 09, 2015, 05:07:21 AM »
Here is my attempt to implement any function... I didn't know how to separate trigonometric func like sinus from other non-trigonometric, so I've constructed strange (if (or ... ) trigonometric non-trigonometric) statement... I've tested it for only (sin x) and (expt x 2) and it worked... If someone sees something that should be different or have strange results, please post remark...

For X axis elevation distribution :
Code - Auto/Visual Lisp: [Select]
  1. ;;                                                                            ;
  2. ;; Poisson Disk Sampling per Bridson Algorithm                                ;
  3. ;;                                                                            ;
  4. ;; See: http://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf;
  5. ;;      http://devmag.org.za/2009/05/03/poisson-disk-sampling/                ;
  6. ;;                                                                            ;
  7. ;; Will return a Random Set of points with a minimum distance between them    ;
  8. ;;                                                                            ;
  9.  
  10. (defun bridson (ll    ur    mindist     /     a     al    cells cellsize
  11.                 grid  i     ind   k     p     p1    p2    pl    r
  12.                 tcl   x     y
  13.                )
  14.   (setq k        30
  15.         width    (- (car ur) (car ll))
  16.         height   (- (cadr ur) (cadr ll))
  17.         cellSize (/ mindist (sqrt 2))
  18.         x        (ceil (/ width cellsize))
  19.         y        (ceil (/ height cellsize))
  20.         x0       (car ll)
  21.         y0       (cadr ll)
  22.         grid     (vlax-make-safearray vlax-vbInteger (cons 0 x) (cons 0 y))
  23.         p1       (list (rand width) (rand height))
  24.         pl       (list p1)
  25.         al       (list 0)               ; Initialize Active List with index of First Point;
  26.         ind      (mapcar '(lambda (a) (fix (/ a cellsize))) p1)
  27.  
  28.   )
  29.   (init2d grid x y)                     ; Initialize the grid to all -1, then             ;
  30.  
  31.   (vlax-safearray-put-element grid (car ind) (cadr ind) 0)
  32.  
  33.   (setq i 0)
  34.   (while al
  35.     (setq p  (nth (fix (rand (length al))) al)
  36.           p1 (nth p pl)
  37.           p1 (list (car p1) (cadr p1))
  38.     )
  39.     (repeat k
  40.       (setq a   (rand (+ pi pi))
  41.             r   (* mindist (+ 1.0 (rand 1.0)))
  42.             p2  (polar p1 a r)
  43.             ind (mapcar '(lambda (a) (fix (/ a cellsize))) p2)
  44.       )
  45.       (if (and (<= 0 (car p2) width) (<= 0 (cadr p2) height))
  46.         (progn
  47.           (setq cells (ptsaround grid ind))
  48.           (if cells
  49.             (setq tcl (tooclosep p2 cells pl))
  50.             (setq tcl nil)
  51.           )
  52.           (if (not tcl)
  53.             (progn
  54.               (setq i  (1+ i)
  55.                     al (cons i al)
  56.                     pl (append pl (list p2))
  57.               )
  58.  
  59.               (vlax-safearray-put-element grid (car ind) (cadr ind) i)
  60.             )
  61.           )
  62.         )
  63.       )
  64.     )
  65.     (setq al (vl-remove p al))
  66.  
  67.   )
  68.  
  69.   (mapcar '(lambda (a) (list (+ (car a) x0) (+ (cadr a) y0) 0.0))
  70.           pl
  71.   )
  72. )
  73.  
  74. (defun init2d (grid x y / i j)
  75.   (setq i -1)
  76.   (repeat x
  77.     (setq i (1+ i)
  78.           j -1
  79.     )
  80.     (repeat y
  81.       (setq j (1+ j))
  82.       (vlax-safearray-put-element grid i j -1)
  83.     )
  84.   )
  85. )
  86.  
  87.  
  88. (defun ptsaround (grid ind / i j rtn tmp)
  89.  
  90.   (setq j (- (cadr ind) 2))
  91.   (repeat 5
  92.     (setq i (- (car ind) 2))
  93.     (repeat 5
  94.       (if (and (< -1 i x) (< -1 j y))
  95.         (if
  96.           (not (= (setq tmp (vlax-safearray-get-element grid i j)) -1)
  97.           )
  98.            (setq rtn (cons tmp rtn))
  99.         )
  100.       )
  101.       (setq i (1+ i))
  102.     )
  103.     (setq j (1+ j))
  104.   )
  105.   rtn
  106. )
  107.  
  108. (defun tooclosep (p cells pl / pc rtn)
  109.   (while cells
  110.     (setq pc    (nth (car cells) pl)
  111.           cells (cdr cells)
  112.     )
  113.     (if (< (distance pc p) mindist)
  114.       (setq rtn t
  115.             cells nil
  116.       )
  117.     )
  118.   )
  119.   rtn
  120. )
  121. ;; Random number generator, Seed must remain global.    LeeMac                ;
  122. ;; Will return a real in the range 0...rng                                    ;
  123.  
  124. (defun rand (rng / x)
  125.   (* (/ (setq x    4294967296.0
  126.               seed (rem (1+ (* 1664525.0
  127.                                (cond (seed)
  128.                                      ((getvar 'DATE))
  129.                                )
  130.                             )
  131.                         )
  132.                         x
  133.                    )
  134.         )
  135.         x
  136.      )
  137.      rng
  138.   )
  139. )
  140.  
  141. ;; Floor function, Returns the largest integer not greater than x.            ;
  142. (defun floor (x)
  143.   (if (minusp (rem x 1))
  144.     (- (fix x) 1)
  145.     (fix x)
  146.   )
  147. )
  148. ;; Ceiling function, Returns the smallest integer not less than x.            ;
  149. (defun ceil (x)
  150.   (if (> (rem x 1) 0)
  151.     (+ (fix x) 1)
  152.     (fix x)
  153.   )
  154. )
  155.  
  156. (defun c:test (/ ** p1 p2 bb md zz nw f fun dw r h e pl pll)
  157.  
  158.  
  159.   (command "_.UCS" "_W")
  160.   (setq p1 (getpoint "\nPick a Window Defining Zone: ")
  161.         p2 (getcorner p1)
  162.         ** (vl-cmdf "_.RECTANGLE" "_non" p1 "_non" p2)
  163.         pl (list p1 p2)
  164.         bb (list (apply 'mapcar (cons 'min pl))
  165.                  (apply 'mapcar (cons 'max pl))
  166.            )
  167.         ** (vl-cmdf "_.UCS" "_M" "_non" (car bb))
  168.         bb (mapcar '(lambda (p) (trans p 0 1)) bb)
  169.         md (getdist
  170.              "\nPick or specify Minimum Distance Between Points : "
  171.            )
  172.         zz (getdist
  173.              "\nPick or specify Maximum Elevation above and below 0.0 : "
  174.            )
  175.         ** (initget 7)
  176.         nw (getint
  177.              "\nSpecify number of Periods along X axis : "
  178.            )
  179.         ** (entlast)
  180.         pl (bridson (car bb) (cadr bb) md)
  181.         pl (vl-sort pl '(lambda (a b) (< (car a) (car b))))
  182.   )
  183.  
  184.   (setq f (getstring t "\nSpecify function in ALISP notation with \"x\" as parameter...\nSpecification must have starting open and ending close brackets : "))
  185.   (defun fun ( x ) (eval (read f)))
  186.   (setq dw (/ (caadr bb) nw))
  187.   (mapcar '(lambda ( x / k )
  188.       (setq k 0)
  189.       (repeat x
  190.         (setq k (1+ k))
  191.         (if (or
  192.               (equal (fun (* k (/ (* 2.0 pi) x))) 0.0 1e-8)
  193.               (equal (fun (* k (/ (* 2.0 pi) x))) -1.0 1e-8)
  194.               (equal (fun (* k (/ (* 2.0 pi) x))) 1.0 1e-8)
  195.             )
  196.           (setq r (cons t r))
  197.           (setq r (cons nil r))
  198.         )
  199.       )
  200.     )
  201.     '(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 32 33 34 35 36)
  202.   )
  203.   (if (apply 'or r)
  204.       (foreach p pl
  205.         (setq e (* zz (/ (if (< 0.0 (rem (car p) (* 2.0 dw)) dw) (fun (* (/ (rem (car p) dw) dw) 2.0 pi)) (fun (- (* (/ (rem (car p) dw) dw) 2.0 pi) (* 2.0 pi)))))))
  206.         (setq p (list (car p) (cadr p) e))
  207.         (setq pll (cons p pll))
  208.       )
  209.     (progn
  210.       (setq h (max (abs (fun dw)) (abs (fun 0.0))))
  211.       (foreach p pl
  212.         (setq e (* zz (/ (if (< 0.0 (rem (car p) (* 2.0 dw)) dw) (fun (rem (car p) dw)) (fun (- (rem (car p) dw) dw))) h)))
  213.         (setq p (list (car p) (cadr p) e))
  214.         (setq pll (cons p pll))
  215.       )
  216.     )
  217.   )
  218.  
  219.   (setq pll (reverse pll))
  220.  
  221.   (mapcar '(lambda (a)
  222.              (entmake (list '(0 . "POINT") '(8 . "Point") (cons 10 a)))
  223.            )
  224.           (mapcar '(lambda (b) (trans b 1 0)) pll)
  225.   )
  226.                                         ;(entdel **)
  227.   (princ)
  228. )
  229.  

For radial elevation distribution :
Code - Auto/Visual Lisp: [Select]
  1. ;;                                                                            ;
  2. ;; Poisson Disk Sampling per Bridson Algorithm                                ;
  3. ;;                                                                            ;
  4. ;; See: http://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf;
  5. ;;      http://devmag.org.za/2009/05/03/poisson-disk-sampling/                ;
  6. ;;                                                                            ;
  7. ;; Will return a Random Set of points with a minimum distance between them    ;
  8. ;;                                                                            ;
  9.  
  10. (defun bridson (ll    ur    mindist     /     a     al    cells cellsize
  11.                 grid  i     ind   k     p     p1    p2    pl    r
  12.                 tcl   x     y
  13.                )
  14.   (setq k        30
  15.         width    (- (car ur) (car ll))
  16.         height   (- (cadr ur) (cadr ll))
  17.         cellSize (/ mindist (sqrt 2))
  18.         x        (ceil (/ width cellsize))
  19.         y        (ceil (/ height cellsize))
  20.         x0       (car ll)
  21.         y0       (cadr ll)
  22.         grid     (vlax-make-safearray vlax-vbInteger (cons 0 x) (cons 0 y))
  23.         p1       (list (rand width) (rand height))
  24.         pl       (list p1)
  25.         al       (list 0)               ; Initialize Active List with index of First Point;
  26.         ind      (mapcar '(lambda (a) (fix (/ a cellsize))) p1)
  27.  
  28.   )
  29.   (init2d grid x y)                     ; Initialize the grid to all -1, then             ;
  30.  
  31.   (vlax-safearray-put-element grid (car ind) (cadr ind) 0)
  32.  
  33.   (setq i 0)
  34.   (while al
  35.     (setq p  (nth (fix (rand (length al))) al)
  36.           p1 (nth p pl)
  37.           p1 (list (car p1) (cadr p1))
  38.     )
  39.     (repeat k
  40.       (setq a   (rand (+ pi pi))
  41.             r   (* mindist (+ 1.0 (rand 1.0)))
  42.             p2  (polar p1 a r)
  43.             ind (mapcar '(lambda (a) (fix (/ a cellsize))) p2)
  44.       )
  45.       (if (and (<= 0 (car p2) width) (<= 0 (cadr p2) height))
  46.         (progn
  47.           (setq cells (ptsaround grid ind))
  48.           (if cells
  49.             (setq tcl (tooclosep p2 cells pl))
  50.             (setq tcl nil)
  51.           )
  52.           (if (not tcl)
  53.             (progn
  54.               (setq i  (1+ i)
  55.                     al (cons i al)
  56.                     pl (append pl (list p2))
  57.               )
  58.  
  59.               (vlax-safearray-put-element grid (car ind) (cadr ind) i)
  60.             )
  61.           )
  62.         )
  63.       )
  64.     )
  65.     (setq al (vl-remove p al))
  66.  
  67.   )
  68.  
  69.   (mapcar '(lambda (a) (list (+ (car a) x0) (+ (cadr a) y0) 0.0))
  70.           pl
  71.   )
  72. )
  73.  
  74. (defun init2d (grid x y / i j)
  75.   (setq i -1)
  76.   (repeat x
  77.     (setq i (1+ i)
  78.           j -1
  79.     )
  80.     (repeat y
  81.       (setq j (1+ j))
  82.       (vlax-safearray-put-element grid i j -1)
  83.     )
  84.   )
  85. )
  86.  
  87.  
  88. (defun ptsaround (grid ind / i j rtn tmp)
  89.  
  90.   (setq j (- (cadr ind) 2))
  91.   (repeat 5
  92.     (setq i (- (car ind) 2))
  93.     (repeat 5
  94.       (if (and (< -1 i x) (< -1 j y))
  95.         (if
  96.           (not (= (setq tmp (vlax-safearray-get-element grid i j)) -1)
  97.           )
  98.            (setq rtn (cons tmp rtn))
  99.         )
  100.       )
  101.       (setq i (1+ i))
  102.     )
  103.     (setq j (1+ j))
  104.   )
  105.   rtn
  106. )
  107.  
  108. (defun tooclosep (p cells pl / pc rtn)
  109.   (while cells
  110.     (setq pc    (nth (car cells) pl)
  111.           cells (cdr cells)
  112.     )
  113.     (if (< (distance pc p) mindist)
  114.       (setq rtn t
  115.             cells nil
  116.       )
  117.     )
  118.   )
  119.   rtn
  120. )
  121. ;; Random number generator, Seed must remain global.    LeeMac                ;
  122. ;; Will return a real in the range 0...rng                                    ;
  123.  
  124. (defun rand (rng / x)
  125.   (* (/ (setq x    4294967296.0
  126.               seed (rem (1+ (* 1664525.0
  127.                                (cond (seed)
  128.                                      ((getvar 'DATE))
  129.                                )
  130.                             )
  131.                         )
  132.                         x
  133.                    )
  134.         )
  135.         x
  136.      )
  137.      rng
  138.   )
  139. )
  140.  
  141. ;; Floor function, Returns the largest integer not greater than x.            ;
  142. (defun floor (x)
  143.   (if (minusp (rem x 1))
  144.     (- (fix x) 1)
  145.     (fix x)
  146.   )
  147. )
  148. ;; Ceiling function, Returns the smallest integer not less than x.            ;
  149. (defun ceil (x)
  150.   (if (> (rem x 1) 0)
  151.     (+ (fix x) 1)
  152.     (fix x)
  153.   )
  154. )
  155.  
  156. (defun c:test (/ ** p1 p2 bb md zz wl cp dd nw f fun r h e pl pll)
  157.  
  158.  
  159.   (command "_.UCS" "_W")
  160.   (setq p1 (getpoint "\nPick a Window Defining Zone: ")
  161.         p2 (getcorner p1)
  162.         ** (vl-cmdf "_.RECTANGLE" "_non" p1 "_non" p2)
  163.         pl (list p1 p2)
  164.         bb (list (apply 'mapcar (cons 'min pl))
  165.                  (apply 'mapcar (cons 'max pl))
  166.            )
  167.         ** (vl-cmdf "_.UCS" "_M" "_non" (car bb))
  168.         bb (mapcar '(lambda (p) (trans p 0 1)) bb)
  169.         md (getdist
  170.              "\nPick or specify Minimum Distance Between Points : "
  171.            )
  172.         zz (getdist
  173.              "\nPick or specify Maximum Elevation above and below 0.0 : "
  174.            )
  175.         wl (getdist
  176.              "\nPick or specify Length of wave period : "
  177.            )
  178.         cp (getpoint
  179.              "\nPick or specify center point of radial waving : "
  180.            )
  181.         dd (car (vl-sort (list (distance cp (car bb)) (distance cp (list (caadr bb) (cadar bb))) (distance cp (cadr bb)) (distance cp (list (caar bb) (cadadr bb)))) '>))
  182.         ** (initget 7)
  183.         nw (getint
  184.              (strcat
  185.                "\nSpecify number of waves along radial axis (must be > "
  186.                (itoa (fix (/ dd wl)))
  187.                ") : "
  188.              )
  189.            )
  190.         ** (entlast)
  191.   )
  192.   (while (<= nw (fix (/ dd wl)))
  193.     (initget 7)
  194.     (setq nw (getint
  195.               (strcat
  196.                 "\nSpecify number of waves along radial axis (must be > "
  197.                 (itoa (fix (/ dd wl)))
  198.                 ") : "
  199.               )
  200.             )
  201.     )
  202.   )
  203.  
  204.   (setq
  205.         pl (bridson (car bb) (cadr bb) md)
  206.         pl (vl-sort pl '(lambda (a b) (< (distance cp a) (distance cp b))))
  207.   )
  208.  
  209.   (setq f (getstring t "\nSpecify function in ALISP notation with \"x\" as parameter...\nSpecification must have starting open and ending close brackets : "))
  210.   (defun fun ( x ) (eval (read f)))
  211.   (mapcar '(lambda ( x / k )
  212.       (setq k 0)
  213.       (repeat x
  214.         (setq k (1+ k))
  215.         (if (or
  216.               (equal (fun (* k (/ (* 2.0 pi) x))) 0.0 1e-8)
  217.               (equal (fun (* k (/ (* 2.0 pi) x))) -1.0 1e-8)
  218.               (equal (fun (* k (/ (* 2.0 pi) x))) 1.0 1e-8)
  219.             )
  220.           (setq r (cons t r))
  221.           (setq r (cons nil r))
  222.         )
  223.       )
  224.     )
  225.     '(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 32 33 34 35 36)
  226.   )
  227.   (if (apply 'or r)
  228.       (foreach p pl
  229.         (setq e (* zz (/ (if (< 0.0 (rem (distance cp p) (* 2.0 wl)) wl) (fun (* (/ (rem (distance cp p) wl) wl) 2.0 pi)) (fun (- (* (/ (rem (distance cp p) wl) wl) 2.0 pi) (* 2.0 pi)))))))
  230.         (setq p (list (car p) (cadr p) e))
  231.         (setq pll (cons p pll))
  232.       )
  233.     (progn
  234.       (setq h (max (abs (fun wl)) (abs (fun 0.0))))
  235.       (foreach p pl
  236.         (setq e (* zz (/ (if (< 0.0 (rem (distance cp p) (* 2.0 wl)) wl) (fun (rem (distance cp p) wl)) (fun (- (rem (distance cp p) wl) wl))) h)))
  237.         (setq p (list (car p) (cadr p) e))
  238.         (setq pll (cons p pll))
  239.       )
  240.     )
  241.   )
  242.  
  243.   (setq pll (reverse pll))
  244.  
  245.   (mapcar '(lambda (a)
  246.              (entmake (list '(0 . "POINT") '(8 . "Point") (cons 10 a)))
  247.            )
  248.           (mapcar '(lambda (b) (trans b 1 0)) pll)
  249.   )
  250.                                         ;(entdel **)
  251.   (princ)
  252. )
  253.  

Thanks, M.R.
« Last Edit: May 10, 2015, 07:04:18 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3268
  • Marko Ribar, architect
Re: Poisson Disk Sampling - Bridson Algorithm - Blue Noise
« Reply #27 on: May 10, 2015, 07:21:40 AM »
It seems that no one doesn't check 2 last posted lisps... There was a problem with circle/sphere function and no one reported... It should work now... You should have checked with function (+- (sqrt (abs (- (expt r 2) (expt x 2))))) where r is radius (period length or elevation above and below 0.0)... How disappointing... :-(
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube