Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve random_unit_vector() #1616

Merged
merged 1 commit into from
Aug 23, 2024
Merged

Improve random_unit_vector() #1616

merged 1 commit into from
Aug 23, 2024

Conversation

hollasch
Copy link
Collaborator

The old method had a floating-point weakness in which all three vector components, when small enough, can yield a vector length that underflows to zero, leading to a bogus [+/- infinity, +/- infinity, +/- infinity] result.

This change also eliminates the random_in_unit_sphere() function, and does everything inside the random_unit_vector() function, which allows us to compute the vector length only once and then re-use it for normalization.

Resolves #1606

The old method had a floating-point weakness in which all three vector
components, when small enough, can yield a vector length that underflows
to zero, leading to a bogus [+/- infinity, +/- infinity, +/- infinity]
result.

This change also eliminates the `random_in_unit_sphere()` function, and
does everything inside the `random_unit_vector()` function, which allows
us to compute the vector length only once and then re-use it for
normalization.

Resolves #1606
@hollasch hollasch added this to the v4.0.1 milestone Aug 21, 2024
@hollasch hollasch requested review from whydoubt and a team August 21, 2024 21:19
@hollasch hollasch self-assigned this Aug 21, 2024
@hollasch hollasch merged commit c6f803f into dev-patch Aug 23, 2024
@hollasch hollasch deleted the update/random-unit-vector branch August 23, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant