Skip to content

Commit 7872b41

Browse files
author
Geniucker
committed
to #4
1 parent 6856896 commit 7872b41

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

tools/run.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# get the ditance according to the latitude and longitude
12
def geodistance(p1, p2):
23
lat1, lng1 = p1["lat"], p1["lng"]
34
lat2, lng2 = p2["lat"], p2["lng"]
@@ -9,6 +10,11 @@ def geodistance(p1, p2):
910
distance=2*asin(sqrt(a))*6371*1000 # 地球平均半径,6371km
1011
return distance
1112

13+
def smooth(start, i, n):
14+
import math
15+
i = (i-start)/n*math.pi
16+
return math.sin(i)**2
17+
1218
def randLoc(loc: list, d=0.000025, n=7):
1319
import random
1420
import time
@@ -26,24 +32,28 @@ def randLoc(loc: list, d=0.000025, n=7):
2632
center["lng"] /= len(result)
2733
random.seed(time.time())
2834
for i in range(n):
29-
for j in range(int(i*len(result)/n), int((i+1)*len(result)/n)):
35+
start = int(i*len(result)/n)
36+
end = int((i+1)*len(result)/n)
37+
for j in range(start, end):
3038
offset = (2*random.random()-1) * d
3139
distance = math.sqrt(
3240
(result[j]["lat"]-center["lat"])**2 + (result[j]["lng"]-center["lng"])**2
3341
)
3442
if 0 == distance:
3543
continue
36-
result[j]["lat"] += (result[j]["lat"]-center["lat"])/distance*offset
37-
result[j]["lng"] += (result[j]["lng"]-center["lng"])/distance*offset
38-
for j in range(int(i*len(result)/n), len(result)):
44+
result[j]["lat"] += (result[j]["lat"]-center["lat"])/distance*offset*smooth(start, j, n)
45+
result[j]["lng"] += (result[j]["lng"]-center["lng"])/distance*offset*smooth(start, j, n)
46+
start = int(i*len(result)/n)
47+
end = len(result)
48+
for j in range(start, end):
3949
offset = (2*random.random()-1) * d
4050
distance = math.sqrt(
4151
(result[j]["lat"]-center["lat"])**2 + (result[j]["lng"]-center["lng"])**2
4252
)
4353
if 0 == distance:
4454
continue
45-
result[j]["lat"] += (result[j]["lat"]-center["lat"])/distance*offset
46-
result[j]["lng"] += (result[j]["lng"]-center["lng"])/distance*offset
55+
result[j]["lat"] += (result[j]["lat"]-center["lat"])/distance*offset*smooth(start, j, n)
56+
result[j]["lng"] += (result[j]["lng"]-center["lng"])/distance*offset*smooth(start, j, n)
4757
return result
4858

4959
def fixLockT(loc: list, v, dt):
@@ -90,7 +100,7 @@ def run(loc: list, v, d=15):
90100
import time
91101
random.seed(time.time())
92102
while True:
93-
nList = (5, 7, 9)
103+
nList = (5, 6, 7)
94104
n = nList[random.randint(0, len(nList)-1)]
95105
newLoc = randLoc(loc, n=n) # a path will be divided into n parts for random route
96106
vRand = 1000/(1000/v-(2*random.random()-1)*d)

0 commit comments

Comments
 (0)