Created
May 21, 2017 11:45
-
-
Save grifdail/3205ff185d214c596d39079c61ee0a8d to your computer and use it in GitHub Desktop.
Poisson disk distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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