Skip to content

Instantly share code, notes, and snippets.

@grifdail
Created May 21, 2017 11:45
Show Gist options
  • Save grifdail/3205ff185d214c596d39079c61ee0a8d to your computer and use it in GitHub Desktop.
Save grifdail/3205ff185d214c596d39079c61ee0a8d to your computer and use it in GitHub Desktop.
Poisson disk distribution
//very inneficient
PVector[] PoissonDiskGenerate(int count, PVector range, int sample) {
PVector[] list = new PVector[count];
for(int i =0; i<count; i++) {
PVector[] samples = new PVector[sample];
float[] distances = new float[sample];
for(int j = 0; j<sample; j++) {
PVector newPoint = new PVector(random(range.x), random(range.y));
samples[j] = newPoint;
//Get the distance to the nearest point
float minDistance = range.magSq();
for(int k =0; k<i; k++) {
float distance = PVector.dist(newPoint, list[k]);
if (distance<minDistance) {
minDistance = distance;
}
//
}
distances[j] = minDistance;
}
//Now we determine the index of the fartest point;
float maxDistance = 0;
int fartestPointIndex = 0;
for(int j = 0; j<sample; j++) {
if (distances[j] > maxDistance) {
maxDistance = distances[j];
fartestPointIndex = j;
}
}
//
list[i] = samples[fartestPointIndex];
}
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment