python - 蟒蛇 | 我期待的情节没有出现
问题描述
我想的图像是这个。
但是..我每次尝试都只得到这个空的。
我不知道为什么这条线不见了..以及我缺少什么..
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];
解决方案
你是这个意思吗?(每个点都有循环内的情节。您需要将其移到循环外并累积所有 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];
输出:
推荐阅读
- python - 如何检查“已设置”和“为空”?
- java - 如何修复 javax.servlet.ServletException:无法实例化 WebApplicationInitializer 类
- python - create_stack error 没有这样的文件或目录
- c++ - 如何将用户下载的头文件添加到系统默认存在的头文件列表中?
- swiftui - 在 SwiftUI 中使用 aspectRatio 的方形文本
- scala - 如何让 scala 编译器找到使用错误参数的案例类
- css - 网格垂直滚动
- javascript - 发送电子邮件时出错:Error Cannot POST /assets/php/form.php
- ios - NSArray 包含两个元素,但 myArray[0] 为零?
- angular - NullInjectorError:RouterStateSerializer 没有提供程序