-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhieu.py
More file actions
55 lines (44 loc) · 1.69 KB
/
hieu.py
File metadata and controls
55 lines (44 loc) · 1.69 KB
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
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# Cài đặt tham số
f = 50 # tần số (Hz)
omega = 2 * np.pi * f # tần số góc
t = np.linspace(0, 1/f, 100) # một chu kỳ
A = 1 # biên độ
# Góc lệch pha
phi_a = 0
phi_b = -2*np.pi/3 # -120 độ
phi_c = 2*np.pi/3 # +120 độ
# Thiết lập đồ họa
fig, ax = plt.subplots()
ax.set_xlim(-1.5, 1.5)
ax.set_ylim(-1.5, 1.5)
ax.set_aspect('equal')
ax.grid(True)
ax.set_title("Mô phỏng trường quay động cơ 3 pha")
# Mũi tên cho từng pha
arrow_a = ax.arrow(0, 0, 0, 0, head_width=0.1, color='r', label='Pha A')
arrow_b = ax.arrow(0, 0, 0, 0, head_width=0.1, color='g', label='Pha B')
arrow_c = ax.arrow(0, 0, 0, 0, head_width=0.1, color='b', label='Pha C')
resultant = ax.arrow(0, 0, 0, 0, head_width=0.1, color='k', linestyle='dashed', label='Tổng')
ax.legend()
def update(i):
ax.patches.clear()
# Giá trị tức thời của từng pha
a = A * np.sin(omega * t[i] + phi_a)
b = A * np.sin(omega * t[i] + phi_b)
c = A * np.sin(omega * t[i] + phi_c)
# Vector đơn vị theo 3 hướng lệch nhau 120 độ
va = np.array([a, 0])
vb = np.array([-b/2, b * np.sqrt(3)/2])
vc = np.array([-c/2, -c * np.sqrt(3)/2])
# Vectơ tổng hợp
total = va + vb + vc
# Vẽ lại các mũi tên
ax.arrow(0, 0, va[0], va[1], head_width=0.05, color='r')
ax.arrow(0, 0, vb[0], vb[1], head_width=0.05, color='g')
ax.arrow(0, 0, vc[0], vc[1], head_width=0.05, color='b')
ax.arrow(0, 0, total[0], total[1], head_width=0.05, color='k', linestyle='dashed')
ani = animation.FuncAnimation(fig, update, frames=len(t), interval=50)
plt.show()