I'm trying to interpolate and visualize a function on the surface of a sphere. For this, I need a meshgrid with the coordinates of interpolation points on the sphere.
Initially, I tried to generate my sphere using
phi, theta = np.mgrid[0:pi:n, 0:2 * pi:n]
which generates a mesh of points like this:
def make_coor(n):
phi, theta = np.mgrid[0:pi-0:n, 0:2 * pi:n]
Coor = namedtuple('Coor', 'r phi theta x y z')
r = 1
x = r * sin(phi) * cos(theta)
y = r * sin(phi) * sin(theta)
z = r * cos(phi)
return Coor(r, phi, theta, x, y, z)
pts=make_coor(15j)
mlab.figure()
mlab.points3d(pts.x,pts.y,pts.z, scale_factor=0.1)
mlab.mesh(pts.x,pts.y,pts.z)
mlab.savefig('spheretest.png')
mlab.show()
This was great because it let me generate my interpolation points and plot the sphere mesh all in one go. However, notice the point at the top of the sphere? Well, in the mgrid the north and south poles are actually represented many times. (Hopefully it's apparent why this would occur)
This is a problem because when I try to do my interpolation, I can't have multiple interpolation points representing the same point on the sphere. This means that I need a way to generate my interpolation points and my meshgrid in such a way that I do not have duplicate points anywhere (especially at the poles). (The meshgrid is so that I can send the interpolation points to mlab.mesh()
and have the sphere mesh drawn)
Does anyone know of a way I can do this?