Closed mweatherley closed 2 weeks ago
Over at bevy we've had several users be confused when they encounter the current nonuniform version. We can't really fix this in our side, and to me this seems like a better default.
You need to use math::sin_cos
which wraps libm and std implementations.
I don't have a strong feeling about performance characteristics of this. It's something I added at the very beginning of glam to generate some data to run benchmarks on, it's not something I put any thought into at the time. It seems like there's still a bit of discussion happening on bevy discord, let me know what you settle on.
Cool. I ended up switching to axis-angle randomization since I think it's simple to grok and its performance seems pretty good.
Thanks for the PR!
Previously, randomly sampled
Quat
s had bias because they were constructed using Euler rotation sequences. This PR makes them follow a uniform distribution. The algorithm used is the one described here.This is essentially a follow-up from this bevy_math PR, which affords users the ability to ergonomically obtain random directions and quaternions.
I believe that this implementation also conforms more closely with the philosophy of Standard: since the space of quaternions is compact, it is quite natural for the "default" distribution over them to be uniform.
Furthermore, if a user wants the old distribution, it is easily implemented using just
Rng::gen_range
andQuat
's constructors; the present implementation actually bundles relatively specialized knowledge into an interface, which abstracts difficulties away from users.