Skip to content

Commit b17cf88

Browse files
committed
update numpy for fix bug
1 parent aa5de3e commit b17cf88

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ install:
2121
- pip install cvxpy
2222
- conda install -y -c cvxgrp cvxpy
2323
- conda install -y -c anaconda cvxopt
24+
- conda update numpy
2425

2526
script:
2627
- python --version

Mapping/circle_fitting/circle_fitting.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,13 @@ def circle_fitting(x, y):
3737
[-sum([ix ** 2 * iy + iy ** 3 for (ix, iy) in zip(x, y)])],
3838
[-sum([ix ** 2 + iy ** 2 for (ix, iy) in zip(x, y)])]])
3939

40-
# try:
4140
T = np.linalg.inv(F).dot(G)
42-
# except:
43-
# return (0, 0, float("inf"))
4441

4542
cxe = float(T[0] / -2)
4643
cye = float(T[1] / -2)
47-
# print (cxe,cye,T)
48-
# try:
4944
re = math.sqrt(cxe**2 + cye**2 - T[2])
50-
# except:
51-
# return (cxe, cye, float("inf"))
5245

5346
error = sum([np.hypot(cxe - ix, cye - iy) - re for (ix, iy) in zip(x, y)])
54-
# print(error)
5547

5648
return (cxe, cye, re, error)
5749

@@ -60,26 +52,37 @@ def get_sample_points(cx, cy, r, angle_reso):
6052
x, y, angle, ran = [], [], [], []
6153

6254
for theta in np.arange(0.0, 2.0 * math.pi, angle_reso):
63-
rn = r * random.uniform(1.0, 1.0)
64-
nx = cx + rn * math.cos(theta)
65-
ny = cy + rn * math.sin(theta)
66-
nangle = math.atan2(ny, nx)
55+
# rn = r * random.uniform(1.0, 1.0)
56+
nx = cx + r * math.cos(theta)
57+
ny = cy + r * math.sin(theta)
58+
nangle = math.atan(ny / nx)
6759
nr = math.hypot(nx, ny)
6860

69-
occluded = False
70-
for i in range(len(angle)):
71-
if abs(angle[i] - nangle) <= angle_reso:
72-
if nr >= ran[i]:
73-
occluded = True
74-
break
61+
x.append(nx)
62+
y.append(ny)
63+
angle.append(nangle)
64+
ran.append(nr)
7565

76-
if not occluded:
77-
x.append(nx)
78-
y.append(ny)
79-
angle.append(nangle)
80-
ran.append(nr)
66+
# ray casting filter
67+
rx, ry = [], []
68+
rangedb = [float("inf") for _ in range(
69+
int(round((math.pi * 2.0) / angle_reso)) + 1)]
8170

82-
return x, y
71+
for i in range(len(angle)):
72+
angleid = math.floor(angle[i] / angle_reso)
73+
# print(angleid)
74+
75+
if rangedb[angleid] > ran[i]:
76+
rangedb[angleid] = ran[i]
77+
78+
for i in range(len(rangedb)):
79+
if rangedb[i] <= 1000.0:
80+
theta = i * angle_reso
81+
print(theta)
82+
rx.append(rangedb[i] * math.cos(theta))
83+
ry.append(rangedb[i] * math.sin(theta))
84+
85+
return rx, ry
8386

8487

8588
def plot_circle(x, y, size, color="-b"):
@@ -122,7 +125,7 @@ def main():
122125
theta = math.radians(30.0)
123126

124127
cr = 1.0
125-
angle_reso = math.radians(30.0)
128+
angle_reso = math.radians(3.0)
126129

127130
while time <= simtime:
128131
time += dt
@@ -140,7 +143,7 @@ def main():
140143
plt.plot(0.0, 0.0, "*r")
141144
plot_circle(cx, cy, cr)
142145
plt.plot(x, y, "xr")
143-
plot_circle(ex, ey, er, "-r")
146+
# plot_circle(ex, ey, er, "-r")
144147
plt.pause(dt)
145148

146149

0 commit comments

Comments
 (0)