Ger
Ger

Reputation: 9756

Is it a tools in numpy or scipy in order to build a spherical grid?

All is in the title, I would like to build a grid a the surface of a sphere. It is not so hard to do but I don't know if it already exist ?

For example I did that :

import scipy as sp
from scipy import pi, cos, sin

d = 1.0

for theta in sp.linspace(0, pi, 20, endpoint = False):
    for phi in sp.linspace(0, 2. * pi, 20, endpoint = False):
        x = d * sin(theta) * cos(phi)
        y = d * sin(theta) * sin(phi)
        z = d * cos(theta)

Thanks

Upvotes: 0

Views: 816

Answers (1)

Sven Marnach
Sven Marnach

Reputation: 602155

I don't think there is anything available to do this. You can get rid of the Python loops, though, which will probably speed things up quite a bit for a higher number of points.

theta = numpy.linspace(0, numpy.pi, 20, endpoint=False)
phi = numpy.linspace(0, 2 * numpy.pi, 20, endpoint=False)
theta, phi = numpy.meshgrid(theta, phi)
d = 1.0
x = d * numpy.sin(theta) * numpy.cos(phi)
y = d * numpy.sin(theta) * numpy.sin(phi)
z = d * numpy.cos(theta)

Upvotes: 1

Related Questions