📜  使用 VPython 制作圆柱体

📅  最后修改于: 2022-05-13 01:55:37.484000             🧑  作者: Mango

使用 VPython 制作圆柱体

VPython可以轻松创建可导航的 3D 显示和动画,即使对于那些编程经验有限的人来说也是如此。因为它是基于Python的,所以它也为有经验的程序员和研究人员提供了很多东西。 VPython允许用户在 3D 空间中创建球体和圆锥体等对象,并将这些对象显示在窗口中。这使得创建简单的可视化变得容易,使程序员可以更多地关注他们程序的计算方面。 VPython的简单性使其成为说明简单物理的工具,尤其是在教育环境中。

安装 :

pip install vpython

圆柱体是三维空间中的几何对象,具有平行的直边和圆形或椭圆形横截面。我们可以使用cylinder()方法在VPython中生成一个圆锥体。

圆筒()

示例 1:没有参数的圆柱体,所有参数都将具有默认值。

# import the module
from vpython import * cylinder()

输出 :

示例 2:使用参数颜色、不透明度、光泽度和发射率的圆柱体。

# import the module
from vpython import * cone(color = vector(0, 1, 1), 
     opacity = 0.5, 
     shininess = 1, 
     emissive = False)

输出 :

示例 3:显示 2 个圆柱体以可视化属性 pos、length 和 radius。

# import the module
from vpython import *
  
# the first cylinder
cylinder(pos = vector(-2, 2, 0),
          length = 3,
          radius = 1,
          color = vector(0.5, 0, 0))
   
# the second cylinder
cylinder(pos = vector(1, -1, 5), 
          color = vector(0, 1, 0))

输出 :

示例 4:使用参数纹理、轴和向上的圆柱体。

# import the module
from vpython import * cylinder(texture = textures.stucco,
         axis = vector(-1, 4, 0),
         up = vector(1, 2, 2))

输出 :