3 ms·
In practice, would it be easier to just randomly generate points within the bounding box of the radius, and then throw out any points that fall outside of the c
by GhostVII 8y ago
In practice, would it be easier to just randomly generate points within the bounding box of the radius, and then throw out any points that fall outside of the circle? Wouldn't work too well for the cases where you want points from some radius away, to some radius away, but would probably work well when you just want a random point inside of a given radius since only 1/4 of the points will have to be thrown out.
- NamTaf 8y agoAs far as I can tell, all the complexity comes about from the Haversine formula, which maps a circle to a spherical surface. If you were to treat that as a flat plane, I don't see why you couldn't just generate a radial angle and radial distance, then convert to an offset from your centre. That's trivial to perform. rand(0,2*pi) for angle, rand(d1,d2) for distance, and then convert from polar coordinates to Cartesian. Maybe I'm missing something fundamental but it seems more complex than need be, especially for small areas where the distortion of showing a sphere on a Mercator projection is minimal. edit: Never mind, another comment answered why: This generates a random but not uniform (in area) distribution, because there's a larger circumference (and thus more swept area for a given radial angle) the larger the radius moves out.
- MaxBarraclough 8y agoA couple of us (marcinzm got there first) stumbled onto what might be a much simpler solution, where we just counterbalance that bias. Perhaps we're missing something, but if so... well, then I missed it :-P https://news.ycombinator.com/item?id=19193622 https://news.ycombinator.com/item?id=19193622
- NamTaf 8y agoThat’s an elegant way to balance the issue, I like it. I guess it all really depends if you want an even distribution on area or in radial distance from the centre, so I can think of valid reasons to use both.
- MaxBarraclough 8y agoGlad you like it. I really think we're on the right track with it - I was surprised the linked article didn't come up with the same idea. I don't see much point in an even distribution in radial distance from the centre. If you want to model something like the distance from the bullseye to an archer's arrows, you're presumably going to want a normal distribution on radial distance from centre, which is of course very different (though at a glance they might look similar).