Skip to content

Instantly share code, notes, and snippets.

@Fewes
Created July 13, 2023 11:44
Show Gist options
  • Save Fewes/7ecdc53f5c449452696baafa75b648bd to your computer and use it in GitHub Desktop.
Save Fewes/7ecdc53f5c449452696baafa75b648bd to your computer and use it in GitHub Desktop.
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