4 ms·
Why can't you simply generate two random numbers with one between 0 and 2pi, and the second between the min and max of distance? Now you've got polar coordinate
by MRD85 8y ago
Why can't you simply generate two random numbers with one between 0 and 2pi, and the second between the min and max of distance? Now you've got polar coordinates. I'm not sure if I'm missing something or if this is overengineered.
If people are interested I've included a link on how Tinder keeps your location private. It's really interesting.
https://robertheaton.com/2018/07/09/how-tinder-keeps-your-location-a-bit-private/ https://robertheaton.com/2018/07/09/how-tinder-keeps-your-lo...
- alanbernstein 8y agoThat might work if you then apply a translation to the center point in pixel-space. But what if you need to send latitude and longitude to your front-end, or other display system? How do you translate your 2d polar coordinates to a change in spherical polar coordinates (lat+lon)? For small distances near the equator, it may not matter. Otherwise, it might. The article could have helped answer your question by providing some images to illustrate the flaws with other solutions that the author tried.
- apcragg 8y agoThat doesn't create a uniform distribution over a disk. Heres a quick image (https://imgur.com/a/xHEpVB9 https://imgur.com/a/xHEpVB9) I generated using that method.
- Misdicorl 8y agoThis will give you a random distribution, but not a uniform one. Concrete description why: you're just as likely to end up 3 units from the center as 6 units from the center. However, there is twice as much space that is 6 units from the center than 3 units from the center.
- MRD85 8y agoThanks, makes perfect sense and should have been obvious.
- MRD85 8y agoI thought about this for a little bit, I might actually code up a demo. If you take a random number between the square of min and the square of max, then you make your polar r equal to square root of your random number.
- Misdicorl 8y agoYup, this works in 2d.
- maxander 8y agoAs others have noted, this doesn’t result in a uniform distribution. But what you can do, instead, is generate a uniform distribution over a square centered on the point of interest, and simply re-do points that land outside of the circle. For most software engineers, this is probably simpler to understand and harder to screw up than implementing the Haversine formula. :)
- MaxBarraclough 8y agoWhich has the unfortunate property that it isn't assured to terminate. Although I believe that discard-and-reattempt strategy is used in real-life RNG libraries if you ask for a random integer in an awkward interval.