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):
print("phase of sig =", a, a*360./(2*math.pi));
p1 =math.cos(a);
abs_p2 = math.cos(a+120/360*2*math.pi);
abs_p3 = math.cos(a+240/360*2*math.pi)
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):
print("phase of sig =", a, a*360./(2*math.pi));
p1 =math.cos(a);
abs_p2 = math.cos(a+120.0/360*2*math.pi);
abs_p3 = math.cos(a+240.0/360*2*math.pi)
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):
plt.subplot(121,polar=True)
plt.plot(theta,val,lw=5)
plt.show()
theta=np.arange(0,2*np.pi+2*np.pi/12,2*np.pi/12)
thevalue=[];
root = []
arg = []
m = 0
for i in theta:
root1,arg1 = cmath.polar(citong_of_engine(i));
root.append(root1*m)
m+=1
arg.append(arg1)
plot_polar(arg, root);