我已經在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