Last active
May 7, 2024 09:39
-
-
Save rlaplaza/6515b687d099d8e79e6629ef9fbd3ebc 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
def shift_bit_length(n): | |
return 1 << (n - 1).bit_length() | |
def sample_one_sphere(coords, radius, n, sobol=True): | |
if sobol: | |
m = int(np.log2(shift_bit_length(n))) | |
x = norm.ppf(qmc.Sobol(d=3, scramble=True).random_base2(m)) | |
else: | |
x = np.random.normal(size=(n, 3)) | |
ssq = np.sum(x**2, axis=1) | |
fr = radius * gammainc(3 / 2, ssq / 2) ** (1 / 3) / np.sqrt(ssq) | |
frtiled = np.tile(fr.reshape(n, 1), (1, 3)) | |
p = coords + np.multiply(x, frtiled) | |
return p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment