poisson

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 2 Imported by: 0

README

Poisson Disk Sampling

An implementation of Bridson's algorithm for Poisson sampling.

This generates points with a minimum distance between them. This can give an organic feel to the resulting distribution.

Based on code and information from https://sighack.com/post/poisson-disk-sampling-bridsons-algorithm.

Usage

package main

import (
	"github.com/derekmu/poisson"
	"log"
	"math/rand/v2"
	"time"
)

func main() {
	points := poisson.Sample2D(10.0, 10, &poisson.Bounds{
		MinX: 0,
		MinY: 0,
		MaxX: 100,
		MaxY: 100,
	}, rand.NewPCG(uint64(time.Now().UnixNano()), uint64(time.Now().UnixNano()>>1)))

	for i, point := range points {
		log.Printf("Point #%d: %+v", i+1, point)
	}
}

Example

Here's an example of a Voronoi diagram used to generate a texture with points generated from this library:

img.png

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	MinX float64
	MinY float64
	MaxX float64
	MaxY float64
}

func (*Bounds) Dx

func (b *Bounds) Dx() float64

func (*Bounds) Dy

func (b *Bounds) Dy() float64

type Point2D

type Point2D struct {
	X float64
	Y float64
}

func Sample2D

func Sample2D(d float64, k int, b *Bounds, s rand.Source) []Point2D

Sample2D generates points with a minimum distance d between points and within bounds b. At each iteration, it will try k random points around a previous point, per Bridson's algorithm. The algorithm will use the given random source for repeatability.

Jump to

Keyboard shortcuts

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