@@ -37,21 +37,13 @@ def circle_fitting(x, y):
37
37
[- sum ([ix ** 2 * iy + iy ** 3 for (ix , iy ) in zip (x , y )])],
38
38
[- sum ([ix ** 2 + iy ** 2 for (ix , iy ) in zip (x , y )])]])
39
39
40
- # try:
41
40
T = np .linalg .inv (F ).dot (G )
42
- # except:
43
- # return (0, 0, float("inf"))
44
41
45
42
cxe = float (T [0 ] / - 2 )
46
43
cye = float (T [1 ] / - 2 )
47
- # print (cxe,cye,T)
48
- # try:
49
44
re = math .sqrt (cxe ** 2 + cye ** 2 - T [2 ])
50
- # except:
51
- # return (cxe, cye, float("inf"))
52
45
53
46
error = sum ([np .hypot (cxe - ix , cye - iy ) - re for (ix , iy ) in zip (x , y )])
54
- # print(error)
55
47
56
48
return (cxe , cye , re , error )
57
49
@@ -60,26 +52,37 @@ def get_sample_points(cx, cy, r, angle_reso):
60
52
x , y , angle , ran = [], [], [], []
61
53
62
54
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 )
67
59
nr = math .hypot (nx , ny )
68
60
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 )
75
65
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 )]
81
70
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
83
86
84
87
85
88
def plot_circle (x , y , size , color = "-b" ):
@@ -122,7 +125,7 @@ def main():
122
125
theta = math .radians (30.0 )
123
126
124
127
cr = 1.0
125
- angle_reso = math .radians (30 .0 )
128
+ angle_reso = math .radians (3 .0 )
126
129
127
130
while time <= simtime :
128
131
time += dt
@@ -140,7 +143,7 @@ def main():
140
143
plt .plot (0.0 , 0.0 , "*r" )
141
144
plot_circle (cx , cy , cr )
142
145
plt .plot (x , y , "xr" )
143
- plot_circle (ex , ey , er , "-r" )
146
+ # plot_circle(ex, ey, er, "-r")
144
147
plt .pause (dt )
145
148
146
149
0 commit comments