-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdemo_UI_ver1.py
474 lines (404 loc) · 19.5 KB
/
demo_UI_ver1.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.widgets import Slider, Button, RadioButtons
fig, ax = plt.subplots(figsize=(6,6))
plt.subplots_adjust(left=0.15, bottom=0.35)
ax.set_aspect('equal')
plt.xlim(-1.4*40,1.4*40)
plt.ylim(-1.4*40,1.4*40)
#plt.grid()
t = np.linspace(0, 2*np.pi, 4096)
delta = 1
mode_fig = 0
pin_fig = 0
cycloid_fig = 1
## draw pin
num_pins = 61
pins = [ax.plot([], [], 'k-')[0] for n in range(num_pins)]
def draw_pin_init():
for p in pins:
p.set_data([0], [0])
def pin_update(n,d,D,phi):
global mode_fig
for i in range(int(n)):
if mode_fig == 1:
x = (d/2*np.sin(t)+ D/2*np.cos(2*i*np.pi/n))
y = (d/2*np.cos(t) + D/2*np.sin(2*i*np.pi/n))
if mode_fig == 0:
x = (d/2*np.sin(t)+ D/2*np.cos(2*i*np.pi/n))*np.cos(phi/(n)) - (d/2*np.cos(t) + D/2*np.sin(2*i*np.pi/n))*np.sin(phi/(n))
y = (d/2*np.sin(t)+ D/2*np.cos(2*i*np.pi/n))*np.sin(phi/(n)) + (d/2*np.cos(t) + D/2*np.sin(2*i*np.pi/n))*np.cos(phi/(n))
pins[i].set_data(x,y)
## draw inner_pin
num_inner_pins = 10
inner_pins = [ax.plot([], [], 'g-')[0] for n in range(num_inner_pins)]
def draw_inner_pin_init():
for p in inner_pins:
p.set_data([0], [0])
def inner_pin_update(n,N,rd,Rd,phi):
global mode_fig
for i in range(int(n)):
if mode_fig == 1:
x = (rd*np.sin(t)+ Rd*np.cos(2*i*np.pi/n))*np.cos(-phi/(N-1)+ 3*np.pi/(N-1)-np.pi/3) - (rd*np.cos(t) + Rd*np.sin(2*i*np.pi/n))*np.sin(-phi/(N-1)+ 3*np.pi/(N-1)-np.pi/3)
y = (rd*np.sin(t)+ Rd*np.cos(2*i*np.pi/n))*np.sin(-phi/(N-1)+ 3*np.pi/(N-1)-np.pi/3) + (rd*np.cos(t) + Rd*np.sin(2*i*np.pi/n))*np.cos(-phi/(N-1)+ 3*np.pi/(N-1)-np.pi/3)
if mode_fig == 0:
x = (rd*np.sin(t)+ Rd*np.cos(2*i*np.pi/n))*np.cos( 3*np.pi/(N-1)-np.pi/3) - (rd*np.cos(t) + Rd*np.sin(2*i*np.pi/n))*np.sin( 3*np.pi/(N-1)-np.pi/3)
y = (rd*np.sin(t)+ Rd*np.cos(2*i*np.pi/n))*np.sin( 3*np.pi/(N-1)-np.pi/3) + (rd*np.cos(t) + Rd*np.sin(2*i*np.pi/n))*np.cos( 3*np.pi/(N-1)-np.pi/3)
inner_pins[i].set_data(x,y)
## draw drive_pin
d0, = ax.plot([0], [0],'k-', lw=2)
def drive_pin_update(r):
x = r*np.sin(t)
y = r*np.cos(t)
d0.set_data(x,y)
#inner circleA:
num_inner_circlesA = 10
inner_circlesA = [ax.plot([], [], 'r-')[0] for n in range(num_inner_circlesA)]
def draw_inner_circleA_init():
for p in inner_circlesA:
p.set_data([0], [0])
def update_inner_circleA(e,n,N,rd,Rd, phi):
global mode_fig
for i in range(int(n)):
if mode_fig == 1:
x = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.cos(-phi/(N-1)+ 3*np.pi/(N-1)-np.pi/3) - ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.sin(-phi/(N-1)+ 3*np.pi/(N-1)-np.pi/3) + e*np.cos(phi)
y = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.sin(-phi/(N-1)+ 3*np.pi/(N-1)-np.pi/3) + ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.cos(-phi/(N-1)+ 3*np.pi/(N-1)-np.pi/3) + e*np.sin(phi)
if mode_fig == 0:
x = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.cos( 3*np.pi/(N-1)-np.pi/3) - ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.sin( 3*np.pi/(N-1)-np.pi/3) + e*np.cos(phi)
y = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.sin( 3*np.pi/(N-1)-np.pi/3) + ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.cos( 3*np.pi/(N-1)-np.pi/3) + e*np.sin(phi)
inner_circlesA[i].set_data(x,y)
#inner circleB:
num_inner_circlesB = 10
inner_circlesB = [ax.plot([], [], 'b-')[0] for n in range(num_inner_circlesB)]
def draw_inner_circleB_init():
for p in inner_circlesB:
p.set_data([0], [0])
def update_inner_circleB(e,n,N,rd,Rd, phi):
global mode_fig
global cycloid_fig
for i in range(int(n)):
if mode_fig == 1:
if cycloid_fig == 3:
x = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.cos(-phi/(N-1)+ 3*np.pi/(N-1) - np.pi/(3)) - ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.sin(-phi/(N-1)+ 3*np.pi/(N-1)- np.pi/(3)) - e*np.cos(phi-np.pi/3)
y = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.sin(-phi/(N-1)+ 3*np.pi/(N-1)- np.pi/(3)) + ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.cos(-phi/(N-1)+ 3*np.pi/(N-1)- np.pi/(3)) - e*np.sin(phi-np.pi/3)
if cycloid_fig == 2:
x = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.cos(-phi/(N-1) + 3*np.pi/(N-1) - np.pi/(3)) - ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.sin(-phi/(N-1) + 3*np.pi/(N-1) - np.pi/(3)) - e*np.cos(phi)
y = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.sin(-phi/(N-1) + 3*np.pi/(N-1) - np.pi/(3)) + ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.cos(-phi/(N-1) + 3*np.pi/(N-1) - np.pi/(3)) - e*np.sin(phi)
if mode_fig == 0:
if cycloid_fig == 3:
x = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.cos( 3*np.pi/(N-1) - np.pi/(3)) - ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.sin( 3*np.pi/(N-1)- np.pi/(3)) - e*np.cos(phi-np.pi/3)
y = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.sin( 3*np.pi/(N-1) - np.pi/(3)) + ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.cos( 3*np.pi/(N-1)- np.pi/(3)) - e*np.sin(phi-np.pi/3)
if cycloid_fig == 2:
x = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.cos( 3*np.pi/(N-1) - np.pi/(3)) - ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.sin( 3*np.pi/(N-1) - np.pi/(3)) - e*np.cos(phi)
y = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.sin( 3*np.pi/(N-1) - np.pi/(3)) + ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.cos( 3*np.pi/(N-1) - np.pi/(3)) - e*np.sin(phi)
inner_circlesB[i].set_data(x,y)
#inner circleC:
num_inner_circlesC = 10
inner_circlesC = [ax.plot([], [], 'g-')[0] for n in range(num_inner_circlesC)]
def draw_inner_circleC_init():
for p in inner_circlesC:
p.set_data([0], [0])
def update_inner_circleC(e,n,N,rd,Rd, phi):
global mode_fig
for i in range(int(n)):
if mode_fig == 1:
x = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.cos(-phi/(N-1) + 3*np.pi/(N-1) - np.pi/(3)) - ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.sin(-phi/(N-1) + 3*np.pi/(N-1)- np.pi/(3)) - e*np.cos(phi+np.pi/3)
y = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.sin(-phi/(N-1) + 3*np.pi/(N-1)- np.pi/(3)) + ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.cos(-phi/(N-1) + 3*np.pi/(N-1)- np.pi/(3)) - e*np.sin(phi+np.pi/3)
if mode_fig == 0:
x = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.cos( 3*np.pi/(N-1) - np.pi/(3)) - ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.sin( 3*np.pi/(N-1)- np.pi/(3)) - e*np.cos(phi+np.pi/3)
y = ((rd+e)*np.cos(t)+Rd*np.cos(2*i*np.pi/n))*np.sin( 3*np.pi/(N-1) - np.pi/(3)) + ((rd+e)*np.sin(t)+Rd*np.sin(2*i*np.pi/n))*np.cos( 3*np.pi/(N-1)- np.pi/(3)) - e*np.sin(phi+np.pi/3)
inner_circlesC[i].set_data(x,y)
##inner pinA:
inner_pinA, = ax.plot([0],[0],'r-')
dotA, = ax.plot([0],[0], 'ro', ms=5)
def update_inner_pinA(e,Rm, phi):
x = (Rm+e)*np.cos(t)+e*np.cos(phi)
y = (Rm+e)*np.sin(t)+e*np.sin(phi)
inner_pinA.set_data(x,y)
x1 = (Rm+e)*np.cos(phi)+e*np.cos(phi)
y1 = (Rm+e)*np.sin(phi)+e*np.sin(phi)
dotA.set_data(x1, y1)
##inner pinB:
inner_pinB, = ax.plot([0],[0],'b-')
dotB, = ax.plot([0],[0], 'bo', ms=5)
def update_inner_pinB(e,Rm, phi):
global cycloid_fig
if cycloid_fig==3:
x = (Rm+e)*np.cos(t)-e*np.cos(phi-np.pi/3)
y = (Rm+e)*np.sin(t)-e*np.sin(phi-np.pi/3)
if cycloid_fig==2:
x = (Rm+e)*np.cos(t)-e*np.cos(phi)
y = (Rm+e)*np.sin(t)-e*np.sin(phi)
inner_pinB.set_data(x,y)
if cycloid_fig==3:
x1 = (Rm+e)*np.cos(phi+2*np.pi/3)-e*np.cos(phi-np.pi/3)
y1 = (Rm+e)*np.sin(phi+2*np.pi/3)-e*np.sin(phi-np.pi/3)
if cycloid_fig==2:
x1 = (Rm+e)*np.cos(phi+np.pi)-e*np.cos(phi)
y1 = (Rm+e)*np.sin(phi+np.pi)-e*np.sin(phi)
dotB.set_data(x1, y1)
##inner pinC:
inner_pinC, = ax.plot([0],[0],'g-')
dotC, = ax.plot([0],[0], 'go', ms=5)
def update_inner_pinC(e,Rm, phi):
x = (Rm+e)*np.cos(t)-e*np.cos(phi+np.pi/3)
y = (Rm+e)*np.sin(t)-e*np.sin(phi+np.pi/3)
inner_pinC.set_data(x,y)
x1 = (Rm+e)*np.cos(phi-2*np.pi/3)-e*np.cos(phi+np.pi/3)
y1 = (Rm+e)*np.sin(phi-2*np.pi/3)-e*np.sin(phi+np.pi/3)
dotC.set_data(x1, y1)
##ehypocycloidA:
ehypocycloidA, = ax.plot([0], [0],'r-')
edotA, = ax.plot([0],[0], 'ro', ms=5)
def update_ehypocycloidA(e,n,D,d, phis):
global mode_fig
RD=D/2
rd=d/2
rc = (n-1)*(RD/n)
rm = (RD/n)
xa = (rc+rm)*np.cos(t)-e*np.cos((rc+rm)/rm*t)
ya = (rc+rm)*np.sin(t)-e*np.sin((rc+rm)/rm*t)
dxa = (rc+rm)*(-np.sin(t)+(e/rm)*np.sin((rc+rm)/rm*t))
dya = (rc+rm)*(np.cos(t)-(e/rm)*np.cos((rc+rm)/rm*t))
if mode_fig == 1:
x = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.cos(-phis/(n-1))-(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.sin(-phis/(n-1)) + e*np.cos(phis)
y = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.sin(-phis/(n-1))+(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.cos(-phis/(n-1)) + e*np.sin(phis)
if mode_fig == 0:
x = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya)) + e*np.cos(phis)
y = (ya + rd/np.sqrt(dxa**2 + dya**2)*dxa) + e*np.sin(phis)
ehypocycloidA.set_data(x,y)
edotA.set_data(x[0], y[0])
##ehypocycloidB:
ehypocycloidB, = ax.plot([0],[0],'b-')
edotB, = ax.plot([0],[0], 'bo', ms=5)
def update_ehypocycloidB(e,n,D,d, phis):
global mode_fig
global cycloid_fig
RD=D/2
rd=d/2
rc = (n-1)*(RD/n)
rm = (RD/n)
xa = (rc+rm)*np.cos(t)+e*np.cos((rc+rm)/rm*t)
ya = (rc+rm)*np.sin(t)+e*np.sin((rc+rm)/rm*t)
dxa = (rc+rm)*(-np.sin(t)-(e/rm)*np.sin((rc+rm)/rm*t))
dya = (rc+rm)*(np.cos(t)+(e/rm)*np.cos((rc+rm)/rm*t))
if mode_fig == 1:
if cycloid_fig == 3:
x = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.cos(-phis/(n-1) + np.pi/3/(n-1))-(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.sin(-phis/(n-1) + np.pi/3/(n-1)) - e*np.cos(phis-np.pi/3)
y = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.sin(-phis/(n-1) + np.pi/3/(n-1))+(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.cos(-phis/(n-1) + np.pi/3/(n-1)) - e*np.sin(phis-np.pi/3)
if cycloid_fig == 2:
x = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.cos(-phis/(n-1) )-(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.sin(-phis/(n-1)) - e*np.cos(phis)
y = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.sin(-phis/(n-1) )+(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.cos(-phis/(n-1)) - e*np.sin(phis)
if mode_fig == 0:
if cycloid_fig == 3:
x = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.cos( np.pi/3/(n-1))-(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.sin( np.pi/3/(n-1)) - e*np.cos(phis-np.pi/3)
y = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.sin( np.pi/3/(n-1))+(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.cos( np.pi/3/(n-1)) - e*np.sin(phis-np.pi/3)
if cycloid_fig == 2:
x = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya)) - e*np.cos(phis)
y = (ya + rd/np.sqrt(dxa**2 + dya**2)*dxa) - e*np.sin(phis)
ehypocycloidB.set_data(x,y)
edotB.set_data(x[0], y[0])
##ehypocycloidC:
ehypocycloidC, = ax.plot([0],[0],'g-')
edotC, = ax.plot([0],[0], 'go', ms=5)
def update_ehypocycloidC(e,n,D,d, phis):
global mode_fig
RD=D/2
rd=d/2
rc = (n-1)*(RD/n)
rm = (RD/n)
xa = (rc+rm)*np.cos(t)+e*np.cos((rc+rm)/rm*t)
ya = (rc+rm)*np.sin(t)+e*np.sin((rc+rm)/rm*t)
dxa = (rc+rm)*(-np.sin(t)-(e/rm)*np.sin((rc+rm)/rm*t))
dya = (rc+rm)*(np.cos(t)+(e/rm)*np.cos((rc+rm)/rm*t))
if mode_fig == 1:
x = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.cos(-phis/(n-1) - np.pi/3/(n-1))-(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.sin(-phis/(n-1) - np.pi/3/(n-1)) - e*np.cos(phis+np.pi/3)
y = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.sin(-phis/(n-1) - np.pi/3/(n-1))+(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.cos(-phis/(n-1) - np.pi/3/(n-1)) - e*np.sin(phis+np.pi/3)
if mode_fig == 0:
x = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.cos( - np.pi/3/(n-1))-(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.sin( - np.pi/3/(n-1)) - e*np.cos(phis+np.pi/3)
y = (xa + rd/np.sqrt(dxa**2 + dya**2)*(-dya))*np.sin( - np.pi/3/(n-1))+(ya + rd/np.sqrt(dxa**2 + dya**2)*dxa)*np.cos( - np.pi/3/(n-1)) - e*np.sin(phis+np.pi/3)
ehypocycloidC.set_data(x,y)
edotC.set_data(x[0], y[0])
##ehypocycloid_Pin:
ehypocycloid_Pin, = ax.plot([0],[0],'k-')
edot_Pin, = ax.plot([0],[0], 'ko', ms=5)
def update_ehypocycloid_Pin(e,n,D,d, phis):
global mode_fig
RD=D/2
rd=d/2
rc = (n)*(RD/(n+1))
rm = (RD/(n+1))
xa = (rc+rm)*np.cos(t)+e*np.cos((rc+rm)/rm*t)
ya = (rc+rm)*np.sin(t)+e*np.sin((rc+rm)/rm*t)
dxa = (rc+rm)*(-np.sin(t)-(e/rm)*np.sin((rc+rm)/rm*t))
dya = (rc+rm)*(np.cos(t)+(e/rm)*np.cos((rc+rm)/rm*t))
if mode_fig == 1:
x = (xa + (rd-e)/np.sqrt(dxa**2 + dya**2)*(-dya))*np.cos( np.pi/(n)) - (ya + (rd-e)/np.sqrt(dxa**2 + dya**2)*dxa)*np.sin( np.pi/(n))
y = (xa + (rd-e)/np.sqrt(dxa**2 + dya**2)*(-dya))*np.sin( np.pi/(n)) + (ya + (rd-e)/np.sqrt(dxa**2 + dya**2)*dxa)*np.cos( np.pi/(n))
if mode_fig == 0:
x = (xa + (rd-e)/np.sqrt(dxa**2 + dya**2)*(-dya))*np.cos(phis/(n) + np.pi/(n))-(ya + (rd-e)/np.sqrt(dxa**2 + dya**2)*dxa)*np.sin(phis/(n) + np.pi/(n))
y = (xa + (rd-e)/np.sqrt(dxa**2 + dya**2)*(-dya))*np.sin(phis/(n) + np.pi/(n))+(ya + (rd-e)/np.sqrt(dxa**2 + dya**2)*dxa)*np.cos(phis/(n) + np.pi/(n))
ehypocycloid_Pin.set_data(x,y)
edot_Pin.set_data(x[0], y[0])
axcolor = 'lightgoldenrodyellow'
ax_fm = plt.axes([0.25, 0.27, 0.5, 0.02], facecolor=axcolor)
ax_Rm = plt.axes([0.25, 0.24, 0.5, 0.02], facecolor=axcolor)
ax_n = plt.axes([0.25, 0.21, 0.5, 0.02], facecolor=axcolor)
ax_Rd = plt.axes([0.25, 0.18, 0.5, 0.02], facecolor=axcolor)
ax_rd = plt.axes([0.25, 0.15, 0.5, 0.02], facecolor=axcolor)
ax_e = plt.axes([0.25, 0.12, 0.5, 0.02], facecolor=axcolor)
ax_N = plt.axes([0.25, 0.09, 0.5, 0.02], facecolor=axcolor)
ax_d = plt.axes([0.25, 0.06, 0.5, 0.02], facecolor=axcolor)
ax_D = plt.axes([0.25, 0.03, 0.5, 0.02], facecolor=axcolor)
sli_fm = Slider(ax_fm, 'fm', -100, 100, valinit=100, valstep=delta*20)
sli_Rm = Slider(ax_Rm, 'Rm', 1, 10, valinit=5, valstep=delta)
sli_n = Slider(ax_n, 'n', 2, 10, valinit=6, valstep=delta)
sli_Rd = Slider(ax_Rd, 'Rd', 1, 40, valinit=20, valstep=delta)
sli_rd = Slider(ax_rd, 'rd', 1, 10, valinit=5, valstep=delta)
sli_e = Slider(ax_e, 'e', 0.1, 10, valinit=2, valstep=delta/10)
sli_N = Slider(ax_N, 'N', 2, 40, valinit=10, valstep=delta)
sli_d = Slider(ax_d, 'd', 2, 20, valinit=10,valstep=delta)
sli_D = Slider(ax_D, 'D', 5, 150, valinit=80,valstep=delta)
def update(val):
sfm = sli_Rm.val
sRm = sli_Rm.val
sRd = sli_Rd.val
sn = sli_n.val
srd = sli_rd.val
se = sli_e.val
sN = sli_N.val
sd = sli_d.val
sD = sli_D.val
ax.set_xlim(-1.4*0.5*sD,1.4*0.5*sD)
ax.set_ylim(-1.4*0.5*sD,1.4*0.5*sD)
sli_fm.on_changed(update)
sli_Rm.on_changed(update)
sli_Rd.on_changed(update)
sli_n.on_changed(update)
sli_rd.on_changed(update)
sli_e.on_changed(update)
sli_N.on_changed(update)
sli_d.on_changed(update)
sli_D.on_changed(update)
resetax = plt.axes([0.85, 0.001, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
rax = plt.axes([0.025, 0.65, 0.15, 0.15], facecolor=axcolor)
radio = RadioButtons(rax, ('Mode 1', 'Mode 2'), active=0)
rax_1 = plt.axes([0.025, 0.45, 0.15, 0.15], facecolor=axcolor)
radio_1 = RadioButtons(rax_1, ('Pin', 'NonePin'), active=0)
rax_2 = plt.axes([0.025, 0.25, 0.15, 0.15], facecolor=axcolor)
radio_2 = RadioButtons(rax_2, ('Single', 'Dual', 'Triple'), active=0)
def reset(event):
sli_fm.reset()
sli_Rm.reset()
sli_n.reset()
sli_rd.reset()
sli_Rd.reset()
sli_e.reset()
sli_N.reset()
sli_d.reset()
sli_D.reset()
button.on_clicked(reset)
def modefunc(label):
global mode_fig
if label == 'Mode 1':
mode_fig = 0
if label == 'Mode 2':
mode_fig = 1
radio.on_clicked(modefunc)
def pin_modefunc(label):
global pin_fig
if label == 'Pin':
pin_fig = 0
if label == 'NonePin':
pin_fig = 1
radio_1.on_clicked(pin_modefunc)
def cycloid_modefunc(label):
global cycloid_fig
if label == 'Single':
cycloid_fig = 1
if label == 'Dual':
cycloid_fig = 2
if label == 'Triple':
cycloid_fig = 3
radio_2.on_clicked(cycloid_modefunc)
def animate(frame):
global pin_fig
global cycloid_fig
sfm = sli_fm.val
sRm = sli_Rm.val
sRd = sli_Rd.val
sn = sli_n.val
srd = sli_rd.val
se = sli_e.val
sN = sli_N.val
sd = sli_d.val
sD = sli_D.val
frame = frame+1
if sfm == 0:
phi = 0
if sfm != 0:
phi = 2*np.pi*frame/sfm
draw_pin_init()
draw_inner_pin_init()
draw_inner_circleA_init()
draw_inner_circleB_init()
draw_inner_circleC_init()
#ehypocycloid_Pin_init()
if pin_fig == 0:
pin_update(sN,sd,sD,phi)
ehypocycloid_Pin.set_visible(0)
edot_Pin.set_visible(0)
if pin_fig == 1:
ehypocycloid_Pin.set_visible(1)
edot_Pin.set_visible(1)
update_ehypocycloid_Pin(se,sN,sD,sd, phi)
inner_pin_update(sn,sN,srd,sRd,phi)
#inner_pin_update(sn,sN,srd,sRd,0)
drive_pin_update(sRm)
inner_pinB.set_visible(1)
dotB.set_visible(1)
inner_pinC.set_visible(1)
dotC.set_visible(1)
ehypocycloidB.set_visible(1)
ehypocycloidC.set_visible(1)
edotB.set_visible(1)
edotC.set_visible(1)
if cycloid_fig == 3:
update_inner_pinA(se,sRm, phi)
update_inner_pinB(se,sRm, phi)
update_inner_pinC(se,sRm, phi)
update_inner_circleA(se,sn,sN,srd,sRd, phi)
update_inner_circleB(se,sn,sN,srd,sRd, phi)
update_inner_circleC(se,sn,sN,srd,sRd, phi)
update_ehypocycloidA(se,sN,sD,sd, phi)
update_ehypocycloidB(se,sN,sD,sd, phi)
update_ehypocycloidC(se,sN,sD,sd, phi)
if cycloid_fig == 2:
update_inner_pinA(se,sRm, phi)
update_inner_pinB(se,sRm, phi)
update_inner_circleA(se,sn,sN,srd,sRd, phi)
update_inner_circleB(se,sn,sN,srd,sRd, phi)
update_ehypocycloidA(se,sN,sD,sd, phi)
update_ehypocycloidB(se,sN,sD,sd, phi)
edotC.set_visible(0)
inner_pinC.set_visible(0)
dotC.set_visible(0)
ehypocycloidC.set_visible(0)
edotC.set_visible(0)
if cycloid_fig == 1:
update_inner_pinA(se,sRm, phi)
update_inner_circleA(se,sn,sN,srd,sRd, phi)
update_ehypocycloidA(se,sN,sD,sd, phi)
inner_pinB.set_visible(0)
dotB.set_visible(0)
inner_pinC.set_visible(0)
dotC.set_visible(0)
ehypocycloidB.set_visible(0)
ehypocycloidC.set_visible(0)
edotB.set_visible(0)
edotC.set_visible(0)
fig.canvas.draw_idle()
ani = animation.FuncAnimation(fig, animate,frames=sli_fm.val*(sli_N.val-1), interval=150)
dpi=100
plt.show()