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

r isn't uniformly distributed over the annulus #1

Open
TuurDutoit opened this issue Sep 30, 2016 · 3 comments
Open

r isn't uniformly distributed over the annulus #1

TuurDutoit opened this issue Sep 30, 2016 · 3 comments
Labels

Comments

@TuurDutoit
Copy link
Owner

I got this email from someone:

I just felt I should mention that your implementation of bridson has a bug.
You select the candidate from the annulus using a simple polar coordinate.
Sadly, 'r' isn't uniformly distributed over the annulus. Fortunately, r^2 is.
Selecting with
r = sqrt(random(r*r, r2*r2));
will fix the bug.
If you plot an annulus with your existing samples, it'll have a lot of points near 'r'.
if you plot with the fix, the annulus is properly uniformly distributed.

Figure out what he means and fix the problem.

@TuurDutoit TuurDutoit added the bug label Sep 30, 2016
@fenwick67
Copy link

When you have a circle or ring that you sample in polar coordinates (that is, you pick a random angle and random radius), the points are more bunched together toward the center.

codepen example:

http://codepen.io/fenwick/pen/qqQzLm?editors=1010

example

This is the line you need to change:

https://github.com/TuurDutoit/bridson/blob/master/index.js#L105

@TuurDutoit
Copy link
Owner Author

Yeah, that's what I thought, just haven't found the time to fix it yet. I'll do it as soon as possible.
Thanks for the example, though!

@TuurDutoit
Copy link
Owner Author

Implemented a fix in a new branch better-distribution. Can you check if that's correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants