Less square variance

main
Bob Mottram 2021-05-10 20:34:22 +01:00
parent ab600800f4
commit 75d1064143
1 changed files with 6 additions and 6 deletions

12
city.py
View File

@ -85,7 +85,7 @@ def spoofGeolocation(baseDir: str,
if not os.path.isfile(locationsFilename): if not os.path.isfile(locationsFilename):
locationsFilename = baseDir + '/locations.txt' locationsFilename = baseDir + '/locations.txt'
cityRadius = 0.1 cityRadius = 0.1
variance = 0.001 varianceAtLocation = 0.0004
default_latitude = 51.8744 default_latitude = 51.8744
default_longitude = 0.368333 default_longitude = 0.368333
default_latdirection = 'N' default_latdirection = 'N'
@ -128,15 +128,15 @@ def spoofGeolocation(baseDir: str,
# Get the position within the city, with some randomness added # Get the position within the city, with some randomness added
latitude += \ latitude += \
distanceFromCityCenter * cityRadius * math.cos(angleRadians) distanceFromCityCenter * cityRadius * math.cos(angleRadians)
# add a small amount of variance around the location
fraction = randint(0, 100000) / 100000
latitude += (fraction * fraction * variance) - (variance / 2.0)
longitude += \ longitude += \
distanceFromCityCenter * cityRadius * math.sin(angleRadians) distanceFromCityCenter * cityRadius * math.sin(angleRadians)
# add a small amount of variance around the location # add a small amount of variance around the location
fraction = randint(0, 100000) / 100000 fraction = randint(0, 100000) / 100000
longitude += (fraction * fraction * variance) - (variance / 2.0) distanceFromLocation = fraction * fraction * varianceAtLocation
fraction = randint(0, 100000) / 100000
angleFromLocation = fraction * 2 * math.pi
latitude += distanceFromLocation * math.cos(angleFromLocation)
longitude += distanceFromLocation * math.sin(angleFromLocation)
# gps locations aren't transcendental, so round to a fixed # gps locations aren't transcendental, so round to a fixed
# number of decimal places # number of decimal places