asny / three-d

2D/3D renderer - makes it simple to draw stuff across platforms (including web)
MIT License
1.33k stars 110 forks source link

fix(examples/fireworks): sample explosion_direction uniformly on 3d sphere #279

Closed rronan closed 2 years ago

rronan commented 2 years ago

In examples/fireworks/main.rs, I believe explosion_direction is not sampled uniformly on the 3d sphere, resulting in non-uniform initial velocities of particles

Here is the result of the current sampling (I increased the number of particles to make it clearer):

before

The code I suggest returns the following:

after

The idea is to sample theta in arcos(unif(-1, 1)) instead of unif(0, pi). More details can be found here: https://stats.stackexchange.com/a/232256

asny commented 2 years ago

Nice, thanks for the contribution 👍