用Python绘制长方体的适用教程
绘制长方体有哪些实用教程?
是一种强大的编程语言,可以用来绘制各种图形,包括长方体。下面是
的turtle库
自带的一个库,可以用来绘制各种图形。以下是使用turtle库绘制长方体的代码示例
port turtle
定义长方体的各边长
width = 100
height = 50
depth = 30
创建画布和画笔() = turtle.Turtle()
绘制长方体的前面up().goto(-width/2, height/2)down().goto(width/2, height/2).goto(width/2, -height/2).goto(-width/2, -height/2).goto(-width/2, height/2)
绘制长方体的后面up().goto(-width/2 + depth, height/2 - depth)down().goto(width/2 + depth, height/2 - depth).goto(width/2 + depth, -height/2 - depth).goto(-width/2 + depth, -height/2 - depth).goto(-width/2 + depth, height/2 - depth)
绘制长方体的侧面up().goto(width/2, height/2)down().goto(width/2 + depth, height/2 - depth).goto(width/2 + depth, -height/2 - depth).goto(width/2, -height/2)
隐藏画笔并保持窗口不关闭.hideturtle()ainloop()
的Matplotlib库
中常用的绘图库,可以用来绘制各种图形,包括长方体。以下是使用Matplotlib库绘制长方体的代码示例
plplot3dportportatplotlib.pyplot as pltportumpyp
定义长方体的各边长
width = 100
height = 50
depth = 30
创建画布和画笔
fig = plt.figure()='3d')
定义长方体的各个顶点坐标p.array([[ [ [ [ depth]])
定义长方体的各个面p.array([[1,2,3], [4,5,6,7], [1,5,4], [1,2,6,5], [2,3,7,6], [3,4,7]])
绘制长方体ge', edgecolors='black'))
设置坐标轴范围([ width])([ height])([ depth])
显示画布
plt.show()
以上就是使,希望对大家有所帮助。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 用Python绘制长方体的适用教程
本文地址: https://pptw.com/jishu/54566.html
