我已经在python中编写了一些代码,其中将创建圆柱体形状的土地。半径值将来自用户输入。但是,我想要从半径计算圆柱体的高度。我已经想出了一个可以这样做的提议,但我不知道如何将它放入代码中。它不断给我h没有定义的错误。在Python中计算用户输入半径的圆柱体高度
def createLand(landRadius):
'''Creates flat land, circle-shaped for city to be built on.
Extruded tunnels for rivers.
landHeight(h) : the height/thickness of the Land
landRadius(r) : the size/radius of the land
zsubdivisions(sz) : the number of subdivisions along z axis for tunnel extrusion
'''
#Creates circle-shaped land, moves edges and faces around for tunnels
land = cmds.polyCylinder(name='Land', sx=0, sy=0, sz=5, h=landRadius*0.2/4, r=landRadius);
cmds.polyMoveEdge('Land.e[160:179]', s=(0.57, 0.57, 0.57));
cmds.polyMoveEdge('Land.e[120:139]', s=(1.08, 1.08, 1.08));
cmds.polyMoveEdge('Land.e[140:159]', s=(1.32, 1.32, 1.32));
cmds.rotate(0, '15deg', 0, 'Land');
#Tunnels extrusion
cmds.polyExtrudeFacet('Land.f[120:139]', 'Land.f[160:179]', 'Land.f[105:106]', 'Land.f[115:116]', 'Land.f[100:101]', 'Land.f[110:111]', 'Land.f[145:146]', 'Land.f[155:156]', 'Land.f[140:141]', 'Land.f[150:151]', kft=True, ty=-h/2);
cmds.polyMoveEdge('Land.e[110:111]', 'Land.e[115:116]', 'Land.e[100:101]', 'Land.e[105:106]', ty=-h/2);
cmds.move(0, -h/2, 0, 'Land');
这是不明确。圆柱体的高度与基座的半径无关。 'h is not defined'意味着你正在使用一个名为'h'的变量没有被赋值。实际上,你的函数'createLand'不带'h'参数,尽管它在它的主体中使用。 – JulienD
你在哪里调用这个函数?你可以发布你的代码吗? – Dadep