News for hackers. Stuff that matters.
Re:How to generate random geo-coordinates within a given radius by iknowordidthat on Monday February 18, 2019 @01:27PM (#19192870)
Over engineered much?

> On a previous project we needed to show markers on a map to indicate there was a property, but for privacy reasons we wanted to show the marker on the map close to the property but not at the exact location of the property. So we needed to generate random points within a fixed distance of the original point location.

At those distances, you can treat the surface as a plane and calculate points on a circle. Sure, it won’t be accurate for large distances but that is not a requirement. Nor is accuracy for that matter since the whole point is to obfuscate the original point.

Re:How to generate random geo-coordinates within a given radius by X6S1x6Okd1st on Monday February 18, 2019 @03:32PM (#19194138)
Seems like another option is to generate points inside a bounding square and throw them away if they are outside of the circle.
Re:How to generate random geo-coordinates within a given radius by ummonk on Monday February 18, 2019 @02:42PM (#19193655)
Yeah, and it doesn't even need to be within a certain radius - just make it within a certain latitude / longitude.
Re:How to generate random geo-coordinates within a given radius by marcinzm on Monday February 18, 2019 @02:39PM (#19193622)
I was thinking the same thing. Just generate two random numbers in polar coordinates and then map back to a cartesian offset. Only trickiness is taking the square root of one of the numbers to generate the radius rather than the random number itself.
Re:How to generate random geo-coordinates within a given radius by MaxBarraclough on Tuesday February 19, 2019 @04:17PM (#19202890)
This is the solution I arrived at, too: explicitly balance out the bias, which seems to be as simple as just taking the square root. Surprised the whole thread isn't full of that idea.

Long rambling version:

The bias in the naive 'solution' is demonstrated in that if we consider a circle of radius 0.5, it has an area of 1/4 that of a circle with radius 1, not half. Which means that as we span our random parameter between 0 and 1, we 'spend too much time' in that small 'inner circle'.

(It's easiest to assume a circle of radius 1, centred about the origin. Nothing interesting arises from additional generality.)

So we don't want the displacement from the origin to rise linearly with the uniform-random parameter. Instead we want the area of our 'inner circle' to rise linearly. Which means that the displacement from the origin should be the square root of the random parameter. (The random parameter's interval will have to be adjusted appropriately of course.)

Our 'theta' has no bias trouble. Transforming from number (angle) into vector/coordinate form, is just routine trig. Nothing interesting to worry about there.

All that's left is to be careful that our theta span the interval [0, 2 * pi) (carefully excluding 2pi), whereas our area should span [0, pi * r^2] (inclusive, assuming that our 'circle' is meant to be an 'open ball' rather than a closed one).

Either we're missing something, or this Haversine business is a needlessly complex answer here.

I considered that another approach might be to define a spiral that 'winds through' all points in the circle, but I'm pretty sure that's not possible. If it were possible, it would give an injective space-filling curve, which is known not to exist. (If it were not injective, it would presumably be biased and so be a non-answer to our question.) Put another way, if your answer involves accepting just one random number, and not two, then your answer is necessarily wrong. (I think I'm getting all this right.) [0]

Another thought: the naive solution is biased despite being injective. Interesting. That seems to be the root of the failure of intuition that leads us to the naive (biased) 'solution'.

[0] https://en.wikipedia.org/w/index.php?title=Space-filling_cur...

Re:How to generate random geo-coordinates within a given radius by MaxBarraclough on Saturday February 23, 2019 @04:56PM (#19235708)
Ah. I now see the blog post is about spheres, not 2D space. It could have been more clear about what problem it was setting out to solve.
Re:How to generate random geo-coordinates within a given radius by chaoticmass on Monday February 18, 2019 @01:55PM (#19193178)
I wrote an app where we needed to get a list of properties within a radius of a given property, using lat/long coordinates. Given the search radius would be at most 5 miles, and didn't need to be 100% precise, I just treated the surface as a plane. A trivial solution to a trivial problem-- but it is neat to know the details of the formula for doing it precisely should I ever need it.
Re:How to generate random geo-coordinates within a given radius by MertsA on Monday February 18, 2019 @07:53PM (#19195856)
>calculate points on a circle

This is a bad idea. If you don't randomly distribute points within the entire radius then you've just narrowed the search space for the real location from the entire area in the radius to just a circle around the point you give back.