63f7f6ec创建于 2025年3月25日历史提交
#!/usr/bin/env python
import sys
import math
import cmath
from matplotlib.pylab import PCG64
import numpy as np
import matplotlib.pyplot as plt
import os

# 获取当前脚本文件的绝对路径
script_dir = os.path.dirname(os.path.abspath(__file__))
# 切换当前工作目录到脚本所在目录
os.chdir(script_dir)
 
def citong_of_engine(a,x=1):
    print("phase of sig =", a, a*360./(2*math.pi));
    p1 =math.cos(a);
    abs_p2 = math.cos(a+120/360*2*x*math.pi);
    abs_p3 = math.cos(a+240/360*2*x*math.pi)
 
    #假定A->B90度方向为i方向。
    p2 = complex(abs_p2*math.cos(120/360*2*math.pi), abs_p2*math.sin(120/360*2*math.pi));
    p3 = complex(abs_p3*math.cos(240/360*2*math.pi), abs_p3*math.sin(240/360*2*math.pi));
                 
    k = p1 + p2 + p3;
    r,a1 = cmath.polar(k)
    a1= a*360/(2*math.pi);
 
    print("[p1-p3]=",p1, p2, p3)
    print("sum(root,a)=",r,a1);
    print("\r\n");
    return k;
 
 
def citong_of_engine_2_polar(a,x=1):
    print("phase of sig =", a, a*360./(2*math.pi));
    p1 =math.cos(a);
    abs_p2 = math.cos(a+120.0/360*2*x*math.pi);
    abs_p3 = math.cos(a+240.0/360*2*x*math.pi)
 
    #假定A->B90度方向为i方向。
    p2 = complex(abs_p2*math.cos(120/360*2*math.pi), abs_p3*math.sin(120/360*2*math.pi));
    p3 = complex(abs_p3*math.cos(240/360*2*math.pi), abs_p2*math.sin(240/360*2*math.pi));
 
                 
    k = p1 + p2 + p3 #
    r,a1 = cmath.polar(k)
    a1= a*360/(2*math.pi);
 
    print("[p1-p3]=",p1, p2, p3)
    print("sum(root,a)=",r,a1);
    print("\r\n");
    return k;
 
 
def plot_polar(theta, val, memos):
    plt.subplot(121,polar=True)
    for i in np.arange(len(theta)):
        plt.plot(theta[i],val[i],lw=5, label=memos[i])
    plt.legend() #add legend of data.
    plt.show()
 
 
theta=np.arange(0,2*np.pi+2*np.pi/12,2*np.pi/12)
thevalue=[]
root = []
arg = []
m = 0

arTheta = []
arVal = []
arMemos = []
#1x
for i in theta:
    root1,arg1 = cmath.polar(citong_of_engine(i));
    #root.append(root1)  
    root.append(root1*m) #root1, 乘一个逐渐放大的系数,可以看到在极坐标系看到旋转磁场的旋转过程
    m+=1
    arg.append(arg1)

arTheta.append(arg)
arVal.append(root)
arMemos.append("1x")

#5x
m = 5
theta=np.arange(0,2*np.pi+2*np.pi/12,2*np.pi/12)
thevalue=[]
thevalue=[]
root = []
arg = []
m = 0
for i in theta:
    root1,arg1 = cmath.polar(citong_of_engine(i,2));
    #root.append(root1)  
    root.append(root1*m) #root1, 乘一个逐渐放大的系数,可以看到在极坐标系看到旋转磁场的旋转过程
    m+=1
    arg.append(arg1)
arTheta.append(arg)
arVal.append(root)
arMemos.append("2x")

 
plot_polar(arTheta, arVal, arMemos);