Python代码挂起。C++和工作鳍使用相同的逻辑

2024-09-30 05:14:47 发布

您现在位置:Python中文网/ 问答频道 /正文

<>我使用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: importaspipltmathmpldegreesappend
1条回答
网友
1楼 · 发布于 2024-09-30 05:14:47

嗯,当然,我会回答的。你知道吗

你刚才的压痕不对。最外层的while循环有一个基于variable920的条件,但是variable920在循环中从不改变。这可能是您发布的代码中的缩进问题。将以下行缩进一级:

incpasses = passes
variable920 = variable920 + variable923

variable920的增量移到最外层的while循环体中,从而允许该循环终止。你知道吗


在将来使用非停止循环的情况下,您可能会发现包含sentinel print语句以打印循环条件中变量的值(如果有的话)是很有帮助的,这样您就可以看到变量在循环过程中是如何变化(或不变化)的。你知道吗

相关问题 更多 >

    热门问题