Python | Сюжет, которого я ожидал, не появляется - PullRequest
0 голосов
/ 09 мая 2020

Я думал, что это изображение.

enter image description here

Но ... Я получаю только это пустое изображение каждый раз, когда пытаюсь.

enter image description here

Я не знаю, почему строка отсутствует .. и что мне не хватает ..

import math
from matplotlib import pyplot as plt
import numpy as np

dx=42; dy=-17; ab=10.5;  bc=42;  cd=24; be=65; ef=5;
ml = np.arange(0, 2*math.pi, math.pi/180)

for theta in ml:
    alpha = -90*math.pi/180
    P=2*cd*(dx-ab+math.cos(theta))
    Q=2*cd*(dy-ab+math.sin(theta))
    R=(dx**2)+(dy**2)+(ab**2)+(cd**2)-(bc**2)-(2*ab+(math.cos(theta))+dy+(math.sin(theta)))

    math_cos_phi=((-P*R)-(Q*math.sqrt((P**2)+(Q**2)-(R**2))))/((P**2)+(Q**2));
    math_sin_phi=((-Q*R)+(P*math.sqrt((P**2)+(Q**2)-(R**2))))/((P**2)+(Q**2));
    a = math_cos_phi;  b = math_sin_phi
    phi=math.atan2(a,b);

    math.cos_psi=((dx+cd+(math_cos_phi))-(ab+math.cos(theta)))/bc;
    math.sin_psi=((dy+cd+(math_sin_phi))-(ab+math.sin(theta)))/bc;
    c = math.cos_psi;  d = math.sin_psi;

    psi=math.atan2(c,d); 
    Fx=ab*math.cos(theta)+be*math.cos(psi)+ef*math.cos(psi+alpha);
    Fy=ab*math.sin(theta)+be*math.sin(psi)+ef*math.sin(psi+alpha);
    plt.plot(Fx,Fy, c = 'g', linewidth=2);
plt.show()

Data=[theta*180/math.pi,Fx,Fy];

1 Ответ

1 голос
/ 09 мая 2020

Вы это имели в виду? (у вас есть график внутри l oop для каждой точки. Вам нужно переместить его за пределы l oop и собрать все Fx и Fy ):

import math
from matplotlib import pyplot as plt
import numpy as np

dx=42; dy=-17; ab=10.5;  bc=42;  cd=24; be=65; ef=5;
ml = np.arange(0, 2*math.pi, math.pi/180)
Fx, Fy = [], []

for theta in ml:
    alpha = -90*math.pi/180
    P=2*cd*(dx-ab+math.cos(theta))
    Q=2*cd*(dy-ab+math.sin(theta))
    R=(dx**2)+(dy**2)+(ab**2)+(cd**2)-(bc**2)-(2*ab+(math.cos(theta))+dy+(math.sin(theta)))

    math_cos_phi=((-P*R)-(Q*math.sqrt((P**2)+(Q**2)-(R**2))))/((P**2)+(Q**2));
    math_sin_phi=((-Q*R)+(P*math.sqrt((P**2)+(Q**2)-(R**2))))/((P**2)+(Q**2));
    a = math_cos_phi;  b = math_sin_phi
    phi=math.atan2(a,b);

    math.cos_psi=((dx+cd+(math_cos_phi))-(ab+math.cos(theta)))/bc;
    math.sin_psi=((dy+cd+(math_sin_phi))-(ab+math.sin(theta)))/bc;
    c = math.cos_psi;  d = math.sin_psi;

    psi=math.atan2(c,d); 
    Fx.append(ab*math.cos(theta)+be*math.cos(psi)+ef*math.cos(psi+alpha))
    Fy.append(ab*math.sin(theta)+be*math.sin(psi)+ef*math.sin(psi+alpha))
plt.plot(Fx,Fy, c = 'g', linewidth=2);
plt.show()

Data=[theta*180/math.pi,Fx,Fy];

вывод:

enter image description here

...