|
@@ -99,13 +99,19 @@ def urban_coord(max_retries=100, max_dist_km=25):
|
|
|
|
|
|
for _ in range(max_retries):
|
|
|
(city_lat, city_lng) = random.choice(urban_centers)
|
|
|
+ # start in a city, turn a random direction, and go random distance
|
|
|
dist_km = random.random() * max_dist_km
|
|
|
angle_rad = random.random() * 2 * math.pi
|
|
|
# logic adapted from https://stackoverflow.com/a/7835325
|
|
|
+ d_over_radius = dist_km / mean_earth_radius_km
|
|
|
+ sin_dor = math.sin(d_over_radius)
|
|
|
+ cos_dor = math.cos(d_over_radius)
|
|
|
city_lat_rad = math.radians(city_lat)
|
|
|
+ sin_lat = math.sin(city_lat_rad)
|
|
|
+ cos_lat = math.cos(city_lat_rad)
|
|
|
city_lng_rad = math.radians(city_lng)
|
|
|
- pt_lat_rad = math.asin(math.sin(city_lat_rad) * math.cos(dist_km / mean_earth_radius_km) + math.cos(city_lat_rad) * math.sin(dist_km / mean_earth_radius_km) * math.cos(angle_rad))
|
|
|
- pt_lng_rad = city_lng_rad + math.atan2(math.sin(angle_rad) * math.sin(dist_km / mean_earth_radius_km) * math.cos(city_lat_rad), math.cos(dist_km / mean_earth_radius_km) - math.sin(city_lat_rad) * math.sin(pt_lat_rad))
|
|
|
+ pt_lat_rad = math.asin(sin_lat * cos_dor + cos_lat * sin_dor * math.cos(angle_rad))
|
|
|
+ pt_lng_rad = city_lng_rad + math.atan2(math.sin(angle_rad) * sin_dor * cos_lat, cos_dor - sin_lat * math.sin(pt_lat_rad))
|
|
|
pt_lat = math.degrees(pt_lat_rad)
|
|
|
pt_lng = math.degrees(pt_lng_rad)
|
|
|
if point_has_streetview(pt_lat, pt_lng):
|