From bd273d95da926223a3a84bba1cdd481d38ea801b Mon Sep 17 00:00:00 2001 From: Xevion Date: Wed, 6 May 2020 03:05:08 -0500 Subject: [PATCH] fix optimized poisson sampling (thanks to @TechSparx) https://twitter.com/TechSparx/status/1257943563335200768 --- procedural-placement/Assets/PointGeneration.cs | 2 +- procedural-placement/Assets/Scenes/SampleScene.unity | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/procedural-placement/Assets/PointGeneration.cs b/procedural-placement/Assets/PointGeneration.cs index b76fce3..7da71bb 100644 --- a/procedural-placement/Assets/PointGeneration.cs +++ b/procedural-placement/Assets/PointGeneration.cs @@ -108,7 +108,7 @@ public static class PointGeneration { // Vector2 dir = new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)); // Vector2 candidate = spawnCenter + dir * Random.Range(radius, radius * 2); - float theta = 2 * Mathf.PI * (seed + i / attempts); + float theta = 2 * Mathf.PI * (seed + i / (float) attempts); Vector2 candidate = spawnCenter + (radius + epsilon) * new Vector2(Mathf.Sin(theta), Mathf.Cos(theta)); // Check that the point is valid, make the corresponding changes diff --git a/procedural-placement/Assets/Scenes/SampleScene.unity b/procedural-placement/Assets/Scenes/SampleScene.unity index c78d27b..d999b48 100644 --- a/procedural-placement/Assets/Scenes/SampleScene.unity +++ b/procedural-placement/Assets/Scenes/SampleScene.unity @@ -150,9 +150,12 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: samplingMethod: 1 - numPoints: 428 - sphereSize: 0.18 - regionSize: {x: 180, y: 100} + numPoints: 23 + sphereSize: 4.3 + regionSize: {x: 1945, y: 1000} + radius: 266.86 + retryAttempts: 1503 + drawSphere: 0 --- !u!4 &2048189740 Transform: m_ObjectHideFlags: 0