Você está na página 1de 6

import matplotlib.

pyplot as plt
import numpy as np
from mpl_toolkits import mplot3d
from mpl_toolkits.mplot3d import Axes3D
import math
from matplotlib.widgets import Slider
from numpy import exp,arange
from pylab import meshgrid, cm, imshow, contour, clabel, colorbar, axis, title, show
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
from matplotlib import style
style.use('seaborn-dark')

lim = 10; step = 0.1; w=2.0; t= np.arange(-lim,lim,step)


#FASES INICIALES
alpha_1x = 3
d_alphax = np.pi
alpha_2x = alpha_1x + d_alphax
alpha1 = 3
alpha2 = 1
alpha_1y = alpha_1x + alpha1
alpha_2y = alpha_1x + d_alphax + alpha2
sigma1 = np.pi / 4
sigma2 = np.pi / 4
S01 = 5
S02 = 3

X01 = S01 * np.cos(sigma1)


Y01 = S01 * np.sin(sigma1)
X02 = S02 * np.cos(sigma2)
Y02 = S02 * np.sin(sigma2)

def S0_(S01, S02):


S0 = np.sqrt(
S01 ** 2 + S02 ** 2 + 2 * S01 * S02 * (
np.cos(sigma1) * np.cos(sigma2) * np.cos(d_alphax) +
np.sin(sigma1) * np.sin(sigma2) * np.cos(alpha2 + d_alphax - alpha1)
))
return S0

def sigma0_(S01, S02):


sigma0 = np.arctan2(np.sqrt(Y01 ** 2 + Y02 ** 2 + 2 * Y01 * Y02 * np.cos(alpha2 + d_alphax -
np.sqrt(X01 ** 2 + X02 ** 2 + 2 * X01 * X02 * np.cos(d_alphax))
)

1
return sigma0

def alphax_(S01, S02):


alphax = np.arctan2(
X01 * np.sin(alpha_1x) + X02 * np.sin(d_alphax + alpha_1x),
X01 * np.cos(alpha_1x) + X02 * np.cos(d_alphax + alpha_1x)
)
return alphax

def alphay_(S01, S02):


alphay = np.arctan2(
Y01 * np.sin(alpha1 + alpha_1x) + Y02 * np.sin(alpha2 + alpha_1x + d_alphax),
Y01 * np.cos(alpha1 + alpha_1x) + Y02 * np.cos(alpha2 + alpha_1x + d_alphax)
)
return alphay

k1 = S0_(S01, S02) * np.cos(sigma0_(S01, S02)) * np.cos(w * t + alphax_(S01, S02)+alpha_1x)


k2 = S0_(S01, S02) * np.sin(sigma0_(S01, S02)) * np.cos(w * t + alphay_(S01, S02)+alpha_1x)

S1x = X01 * np.cos(w * t + alpha_1x)


S1y = Y01 * np.cos(w * t + alpha_1x + alpha1)
S2x = X02 * np.cos(w * t + alpha_2x)
S2y = Y02 * np.cos(w * t + alpha_2x + alpha2)

Sx = S1x + S2x
Sy = S1y + S2y

plt.subplot(131)
plt.plot(S1x, S1y)
plt.grid()
plt.xlim(-9, 9)
plt.ylim(-6, 6)
plt.subplot(132)
plt.plot(S2x, S2y)
plt.xlim(-9, 9)
plt.ylim(-6,6)
plt.grid()
plt.subplot(133)
plt.xlim(-9, 9)
plt.ylim(-6, 6)
plt.plot(k1, k2)
plt.grid()
plt.show()

2
plt.subplot(121)
plt.plot(Sx, Sy)
plt.grid()
plt.subplot(122)
plt.title('Directas')
plt.plot(k1, k2)
plt.grid()
plt.show()

#Elipse 1
def S1x(S01):
S1x = S01 * np.cos(sigma1) * np.cos(w * t + alpha_1x)
return S1x
def S1y(S01):
S1y = S01 * np.sin(sigma1) * np.cos(w * t + alpha_1x + alpha1)
return S1y
#Elipse 2
def S2x(S02):
S2x = S02 * np.cos(sigma2) * np.cos(w * t + alpha_2x)
return S2x
def S2y(S02):
S2y = S02 * np.sin(sigma2) * np.cos(w * t + alpha_2x + alpha2)
return S2y

# ELIPSE RESULTANTE
def Sx(S01, S02):
X01 = S01 * np.cos(sigma1)
Y01 = S01 * np.sin(sigma1)
X02 = S02 * np.cos(sigma2)
Y02 = S02 * np.sin(sigma2)

#CALCULO DE PARAMETROS
S0 = np.arctan2(np.sqrt(Y01 ** 2 + Y02 ** 2 + 2 * Y01 * Y02 * np.cos(alpha2 + d_alphax - alp
np.sqrt(X01 ** 2 + X02 ** 2 + 2 * X01 * X02 * np.cos(d_alphax))
)

sigma0 = np.arctan2(np.sqrt(Y01 ** 2 + Y02 ** 2 + 2 * Y01 * Y02 * np.cos(alpha2 + d_alphax -


np.sqrt(X01 ** 2 + X02 ** 2 + 2 * X01 * X02 * np.cos(d_alphax))
)

alphax = np.arctan2(
X01 * np.sin(alpha_1x) + X02 * np.sin(d_alphax + alpha_1x),
X01 * np.cos(alpha_1x) + X02 * np.cos(d_alphax + alpha_1x)
)
Sx = S0 * np.cos(sigma0) * np.cos(w * t + alphax+alpha_1x)

3
return Sx
def Sy(S01, S02):
X01 = S01 * np.cos(sigma1)
Y01 = S01 * np.sin(sigma1)
X02 = S02 * np.cos(sigma2)
Y02 = S02 * np.sin(sigma2)

#CALCULO DE PARAMETROS
S0 = np.arctan2(np.sqrt(Y01 ** 2 + Y02 ** 2 + 2 * Y01 * Y02 * np.cos(alpha2 + d_alphax - alp
np.sqrt(X01 ** 2 + X02 ** 2 + 2 * X01 * X02 * np.cos(d_alphax))
)

sigma0 = np.arctan2(np.sqrt(Y01 ** 2 + Y02 ** 2 + 2 * Y01 * Y02 * np.cos(alpha2 + d_alphax -


np.sqrt(X01 ** 2 + X02 ** 2 + 2 * X01 * X02 * np.cos(d_alphax))
)

alphay = np.arctan2(
Y01 * np.sin(alpha1 + alpha_1x) + Y02 * np.sin(alpha2 + alpha_1x + d_alphax),
Y01 * np.cos(alpha1 + alpha_1x) + Y02 * np.cos(alpha2 + alpha_1x + d_alphax)
)
Sy = S0 * np.sin(sigma0) * np.cos(w * t + alphay+alpha_1x)
return Sy

fig = plt.figure(figsize=plt.figaspect(1.2))

# Primera Elipse
ax=fig.add_subplot(1, 3, 1)
p0=0.1
plt.subplots_adjust(left=0.25, bottom=0.25)
l, = plt.plot(S1x(p0), S1y(p0), lw=1, color='red')
plt.title('ELIPSE 1',fontsize=20)
plt.grid()
plt.axis([-20, 20, -20, 20])

axcolor = 'lightgoldenrodyellow'
S01 = plt.axes([0.25, 0.16, 0.65, 0.03], facecolor=axcolor)
S_S01 = Slider(S01, r'$S_{01}$', 0.001, 15.0, valinit=0.1)

def update(val):
S01 = S_S01.val
l.set_xdata(S1x(S01))
l.set_ydata(S1y(S01))
fig.canvas.draw_idle()

4
S_S01.on_changed(update)

#Segunda Elipse
ax = fig.add_subplot(1, 3, 2)

plt.subplots_adjust(left=0.25, bottom=0.25)

k, = plt.plot(S2x(p0), S2y(p0), lw=1, color='b')


plt.title('ELIPSE 2', fontsize=20)
plt.grid()
plt.axis([-20, 20, -20, 20])

axcolor = 'lightgoldenrodyellow'
S02= plt.axes([0.25, 0.06, 0.65, 0.03], facecolor=axcolor)
S_S02 = Slider(S02, r'$S_{02}$', 0.001, 15, valinit=0.1)

def update2(val):
S02 = S_S02.val
k.set_xdata(S2x(S02))
k.set_ydata(S2y(S02))
fig.canvas.draw_idle()

S_S02.on_changed(update2)

# Resultante
ax = fig.add_subplot(1, 3, 3)

plt.subplots_adjust(left=0.25, bottom=0.25)
h, = plt.plot(Sx(p0,p0), Sy(p0,p0), lw=1, color='c')
plt.title('RESULTANTE', fontsize=20)
plt.grid()
plt.axis([-5, 5, -5, 5])

axcolor = 'lightgoldenrodyellow'
S01 = plt.axes([0.25, 0.16, 0.65, 0.03], facecolor=axcolor)
#Sigma1 = plt.axes([0.25, 0.11, 0.65, 0.03], facecolor=axcolor)
S02= plt.axes([0.25, 0.06, 0.65, 0.03], facecolor=axcolor)
#Sigma2 = plt.axes([0.25, 0.01, 0.65, 0.03], facecolor=axcolor)

def update3(val):
S01 = S_S01.val
# Sigma1 = S_Sigma1.val
S02 = S_S02.val
# Sigma2 = S_Sigma2.val
#L1(S01,sigma1,S02,sigma2)

5
h.set_xdata(Sx(S01,S02))
h.set_ydata(Sy(S01,S02))
fig.canvas.draw_idle()

S_S01.on_changed(update3)
#S_Sigma1.on_changed(update3)
S_S02.on_changed(update3)
#S_Sigma2.on_changed(update3)

plt.show()

Você também pode gostar