Created
July 13, 2023 11:44
-
-
Save Fewes/7ecdc53f5c449452696baafa75b648bd to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
public static class HaltonSequenceGenerator | |
{ | |
public static void GenerateHaltonSequence(float[] result) | |
{ | |
for (int i = 0; i < result.Length; i++) | |
{ | |
result[i] = Halton(2, i); | |
} | |
} | |
public static void GenerateHaltonSequence(Vector2[] result) | |
{ | |
for (int i = 0; i < result.Length; i++) | |
{ | |
result[i] = new Vector2( | |
Halton(2, i), | |
Halton(3, i) | |
); | |
} | |
} | |
public static void GenerateHaltonSequence(Vector3[] result) | |
{ | |
for (int i = 0; i < result.Length; i++) | |
{ | |
result[i] = new Vector3( | |
Halton(2, i), | |
Halton(3, i), | |
Halton(5, i) | |
); | |
} | |
} | |
private static float Halton(int _base, int index) | |
{ | |
float result = 0; | |
float f = 1; | |
while (index > 0) | |
{ | |
f /= _base; | |
result += f * (index % _base); | |
index /= _base; | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment