使用 VPython 制作椭圆体
VPython可以轻松创建可导航的 3D 显示和动画,即使对于那些编程经验有限的人来说也是如此。因为它是基于Python的,所以它也为有经验的程序员和研究人员提供了很多东西。 VPython 允许用户在 3D 空间中创建球体和圆锥体等对象,并将这些对象显示在窗口中。这使得创建简单的可视化变得容易,使程序员可以更多地关注他们程序的计算方面。 VPython 的简单性使其成为说明简单物理的工具,尤其是在教育环境中。
安装 :
pip install vpython
椭圆体是三维空间中的几何对象,其中所有平面横截面都是椭圆或圆形,形成一个封闭的表面。我们可以使用 ellipsoid() 方法在 VPython 中生成一个椭圆体。
椭圆体()
Syntax : ellipsoid(parameters)
Parameters :
- pos : It is the position of the center of the ellipsoid. Assign a vector containing 3 values, example pos = vector(0, 0, 0)
- axis : It is the axis of alignment of the ellipsoid. Assign a vector containing 3 values, example axis = vector(1, 2, 1)
- up : It is the orientation of the ellipsoid. Assign a vector containing 3 values, example up = vector(0, 1, 0)
- color : It is the color of the ellipsoid. Assign a vector containing 3 values, example color = vector(1, 1, 1) will give the color white
- opacity : It is the opacity of the ellipsoid. Assign a floating value in which 1 is the most opaque and 0 the least opaque, example opacity = 0.5
- shininess : It is the shininess of the ellipsoid. Assign a floating value in which 1 is the most shiny and 0 the least shiny, example shininess = 0.6
- emissive : It is the emissivity of the ellipsoid. Assign a boolean value in which True is emissive and False is not emissive, example emissivity = False
- texture : It is the texture of the ellipsoid. Assign the required texture from the textures class, example texture = textures.stucco
- length : It is the length of the ellipsoid in x direction. Assign a floating value, the default length is 1, example length = 10
- height : It is the height of the ellipsoid in y direction. Assign a floating value, the default height is 1, example height = 8
- width : It is the width of the ellipsoid in z direction. Assign a floating value, the default width is 1, example width = 5
- size : It is the size of the ellipsoid. Assign a vector containing 3 values representing the length, height and width respectively, example size = vector(1, 1, 1)
All the parameters are optional.
示例 1:一个没有参数的椭球,所有参数都将具有默认值。
Python3
# import the module
from vpython import * ellipsoid()
Python3
# import the module
from vpython import * ellipsoid(color = vector(0.4, 0.2, 0.6),
opacity = 0.5,
shininess = 1,
emissive = False)
Python3
# import the module
from vpython import *
# the first ellipsoid
ellipsoid(pos = vector(-2, 2, 0),
length = 3,
height = 2,
width = 2,
color = vector(1, 0.6, 0))
# the second ellipsoid
ellipsoid(pos = vector(1, -1, 5),
width = 3,
color = vector(0, 1, 0))
Python3
# import the module
from vpython import * ellipsoid(texture = textures.stucco,
axis = vector(-1, 4, 0),
up = vector(1, 2, 2),
length = 3)
输出 :
示例 2:使用参数颜色、不透明度、光泽度和发射率的椭圆体。
Python3
# import the module
from vpython import * ellipsoid(color = vector(0.4, 0.2, 0.6),
opacity = 0.5,
shininess = 1,
emissive = False)
输出 :
示例 3:显示 2 个椭圆体以可视化属性 pos、length、height 和 width。
Python3
# import the module
from vpython import *
# the first ellipsoid
ellipsoid(pos = vector(-2, 2, 0),
length = 3,
height = 2,
width = 2,
color = vector(1, 0.6, 0))
# the second ellipsoid
ellipsoid(pos = vector(1, -1, 5),
width = 3,
color = vector(0, 1, 0))
输出 :
示例 4:使用参数纹理、轴和向上的椭圆体。
Python3
# import the module
from vpython import * ellipsoid(texture = textures.stucco,
axis = vector(-1, 4, 0),
up = vector(1, 2, 2),
length = 3)
输出 :