poissondisc

package module
v0.0.0-...-9b82984 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2019 License: MIT Imports: 3 Imported by: 12 modules, 8 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

poissondisc

Poisson Disc sampling in Go.

Installation

$ go get -u github.com/fogleman/poissondisc

Documentation

https://godoc.org/github.com/fogleman/poissondisc

Learn more about Poisson-disc sampling:

https://www.jasondavies.com/poisson-disc/

https://bl.ocks.org/mbostock/dbb02448b0f93e4c82c3

Usage

var x0, y0, x1, y1, r float64
x0 = 0    // bbox min
y0 = 0    // bbox min
x1 = 1000 // bbox max
y1 = 1000 // bbox max
r = 10    // min distance between points
k := 30   // max attempts to add neighboring point

points := poissondisc.Sample(x0, y0, x1, y1, r, k, nil)

for _, p := range points {
	fmt.Println(p.X, p.Y)
}

Example

$ go run examples/example.go

Example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Point

type Point struct {
	X, Y float64
}

func Sample

func Sample(x0, y0, x1, y1, r float64, k int, rnd *rand.Rand) []Point

Sample produces points via Poisson-disc sampling. The points will all be within the box defined by `x0`, `y0`, `x1`, `y1`. No two points will be closer than the defined radius `r`. For each point, the algorithm will make `k` attempts to place a neighboring point. Increase this value for a better sampling or decrease it to reduce algorithm runtime. You may provide your own `*rand.Rand` instance or `nil` to have one created for you. Learn more about Poisson-disc sampling from the links below: https://www.jasondavies.com/poisson-disc/ https://bl.ocks.org/mbostock/dbb02448b0f93e4c82c3

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址