<>我使用C++中的while循环(没有MatpTLIB)来实现相同的逻辑,并完美地输出了我的坐标。当我使用python时,它只是挂起。我以前从没见过这种事。我有点不知所措,因为没有错误可以避免。我通常在C++中做我的逻辑,所以我可能在Python中出错了吗?不确定。有什么想法吗?你知道吗
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
import math
variable924 = 0.0
variable921 = .0025
variable922 = .0450
variable923 = 5.0 + variable924
variable920 = 0
variable925 = 0
variable926 = 0
passes = 1
incpasses = passes
r = 0
degrees = 0
z = []
x = []
y = []
while (variable920 < 65):
variable925 = (1.0010-math.cos(variable920*(math.pi/180.00)))*variable922
variable926 = (math.sin(variable920*(math.pi/180.00))-variable922)
r = variable925 + variable921
while (incpasses >= 1):
xSet = (-variable926/passes)
while (degrees <= 360):
ySet = (math.sin(degrees * (math.pi / 180.00)))*r
zSet = (math.cos(degrees * (math.pi / 180.00)))*r
degrees = degrees + 30
x.append(xSet)
y.append(ySet)
z.append(zSet)
incpasses = incpasses - 1
degrees = 0
incpasses = passes
variable920 = variable920 + variable923
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot(x, y, z, label='parametric curve')
ax.legend()
plt.show()
Tags:
嗯,当然,我会回答的。你知道吗
你刚才的压痕不对。最外层的
while
循环有一个基于variable920
的条件,但是variable920
在循环中从不改变。这可能是您发布的代码中的缩进问题。将以下行缩进一级:将
variable920
的增量移到最外层的while
循环体中,从而允许该循环终止。你知道吗在将来使用非停止循环的情况下,您可能会发现包含sentinel
print
语句以打印循环条件中变量的值(如果有的话)是很有帮助的,这样您就可以看到变量在循环过程中是如何变化(或不变化)的。你知道吗相关问题 更多 >
编程相关推荐