forked from freespace/pyAPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spiral_scan.py
123 lines (93 loc) · 2.65 KB
/
spiral_scan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from math import *
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import *
import time
stepAngle = 0.25 * pi
phi = pi
maxSize = 50
step = 0.2 * maxSize
r = step
z = 0
IN = 0
OUT = 1
rDir = OUT
xvector = []
yvector = []
zvector = []
fig = plt.figure()
ax = fig.gca(projection='3d') # to work in 3d
#plt.axes([0, maxSize, 0, maxSize])
ax.set_xlim3d(0, maxSize)
ax.set_ylim3d(0, maxSize)
ax.set_zlim3d(0, maxSize)
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')
plt.ion()
plt.show()
ax.scatter(maxSize / 2, maxSize / 2, z, zdir='z', c= 'red')
plt.draw()
icolor = 0
epsilon = 0.001
while (z <= maxSize):
if r > maxSize / 2:
stepAngle = (stepAngle * r) / (r - step)
# stepAngle = (stepAngle * (r + step)) / r
r -= step
rDir = IN
else:
#stepAngle = (stepAngle * r) / (r + step)
stepAngle = 0.25 * pi
r = step
rDir = OUT
x = y = maxSize / 2
xvector.append(x)
yvector.append(y)
zvector.append(z)
if (icolor % 2 == 0):
ax.scatter(x, y, z, zdir='z', c= 'red')
else:
ax.scatter(x, y, z, zdir='z', c= 'blue')
plt.draw()
while ((r > step or abs(r - step) < epsilon) and (r < maxSize / 2 or abs(r - maxSize / 2) < epsilon)):
while (phi > -pi):
x = r * cos(phi) + maxSize / 2
y = r * sin(phi) + maxSize / 2
xvector.append(x)
yvector.append(y)
zvector.append(z)
if (icolor % 2 == 0):
ax.scatter(x, y, z, zdir='z', c= 'red')
else:
ax.scatter(x, y, z, zdir='z', c= 'blue')
plt.draw()
time.sleep(0.0000001)
phi -= stepAngle
print 'B', icolor, stepAngle, r
if (rDir == IN):
#stepAngle = (stepAngle * (2 * r + 2 * step)) / (2 * r)
if (abs(r - step) > epsilon):
stepAngle = (stepAngle * r) / (r - step)
r -= step
else:
#stepAngle = (stepAngle * 2 * r) / (2 * r + 2 * step)
stepAngle = (stepAngle * r) / (r + step)
r += step
print 'A', icolor, stepAngle, r
phi = pi
if (rDir == IN):
x = y = maxSize / 2
xvector.append(x)
yvector.append(y)
zvector.append(z)
if (icolor % 2 == 0):
ax.scatter(x, y, z, zdir='z', c= 'red')
else:
ax.scatter(x, y, z, zdir='z', c= 'blue')
plt.draw()
z += step
icolor += 1
plt.hold(True)
#plt.plot(xvector, yvector)
#plt.axis([- maxSize / 2, maxSize / 2, - maxSize / 2, maxSize / 2])
plt.show()