2

I am trying to plot Earth in 3D using python.

I made a script from what I found on the internet and using Mayavi I successfully plotted a mesh but I would like to apply a texture from an image (a blue marble from NASA).

However when I try to do so, the texture only apply on one half of the ellipsoid and si symmetrically duplicated on the other half.

Here pictures of my result: Earth 3D (imgur gallery)

And my code:

import numpy as np
import vtk
from mayavi import mlab

image_file = 'earth_texture.jpg';

erad    = 6371008.7714 # equatorial radius (meters)
prad    = 6371008.7714 # polar radius (meters)
erot    = 7.2921158553e-5 # earth rotation rate (radians/sec)

textureReader = vtk.vtkJPEGReader()
textureReader.SetFileName('earth_texture.jpg')
texture = vtk.vtkTexture()
texture.SetInputConnection(textureReader.GetOutputPort())

u = np.linspace(0, 2 * np.pi, 180)
v = np.linspace(0, np.pi, 180)

x = erad * np.outer(np.cos(u), np.sin(v))
y = erad * np.outer(np.sin(u), np.sin(v))
z = prad * np.outer(np.ones_like(u), np.cos(v))

mlab.figure(size=(800, 800), bgcolor=(0.16, 0.28, 0.46))

mesh = mlab.mesh(x,y,z)
mesh.actor.actor.mapper.scalar_visibility=False
mesh.actor.enable_texture = True
mesh.actor.tcoord_generator_mode = 'plane'
mesh.actor.actor.texture = texture
mlab.show()

I would like the image to fit the ellipsoid perfectly but I did not find a way to do so.

Drakyo
  • 21
  • 1

0 Answers0