python画球面投影_python - 将图像映射到球体上并绘制3D轨迹 - 堆栈内存溢出

一旦拥有了你的星球,使用mayavi.mlab.plot3d绘制轨迹很容易,所以我将专注于使用mayavi将行星映射到球体的纹理。 (原则上我们可以使用matplotlib执行任务,但与mayavi相比,性能和质量要差得多,请参阅本答案的结尾。)

漂亮的场景:球体上的球体

事实证明,如果你想将一个球形的参数化图像映射到一个球体上,你必须让你的手有点脏,并使用一些裸vtk,但实际上很少有工作要做,结果看起来很棒。 他们的自述文件说这些图像有

地理(PlateCarrée)投影,基于相等的纬度 - 经度网格间距(不是等面积投影!)

在维基百科中查找它,结果证明这也称为equirectangular投影 。 换句话说,沿x像素直接对应于经度,沿y像素直接对应于纬度。 这就是我所说的“球形参数化”。

因此在这种情况下,我们可以使用低级TexturedSphereSource来生成可以映射到纹理的球体。 自己构造一个球体网格可能会导致映射中的工件(稍后会详细介绍)。

对于低级别的vtk工作,我重写了这里发现的官方示例 。 这就是它所需要的一切:

from mayavi import mlab

from tvtk.api import tvtk # python wrappers for the C++ vtk ecosystem

def auto_sphere(image_file):

# create a figure window (and scene)

fig = mlab.figure(size=(600, 600))

# load and map the texture

img = tvtk.JPEGReader()

img.file_name = image_file

texture = tvtk.Texture(input_connection=img.output_port, interpolate=1)

# (interpolate for a less raster appearance when zoomed in)

# use a TexturedSphereSource, a.k.a. getting our hands dirty

R = 1

Nrad = 180

# create the sphere source with a given radius and angular resolution

sphere = tvtk.TexturedSphereSource(radius=R, theta_resolution=Nrad,

phi_resolution=Nrad)

# assemble rest of the pipeline, assign texture

sphere_mapper = tvtk.PolyDataMapper(input_connection=sphere.output_port)

sphere_ac

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值