Как получить координаты для полушария в Python - PullRequest
0 голосов
/ 03 сентября 2018

В настоящее время у меня есть некоторый код Python для получения равноотстоящих точек на поверхности сферы. Теперь я хочу отредактировать этот код, чтобы получить равноотстоящие точки на поверхности полушария. Я предполагаю, что есть какой-то простой параметр, который мне нужно изменить, но я все еще новичок в Python.

Мой код:

from numpy import pi, cos, sin, arccos, arange
import mpl_toolkits.mplot3d
import matplotlib.pyplot as plt

num_pts = 10000
indices = arange(0, num_pts, dtype=float) + 0.5

phi = arccos(1 - 2*indices/num_pts)
theta = pi * (1 + 5**0.5) * indices

x, y, z = cos(theta) * sin(phi), sin(theta) * sin(phi), cos(phi);

fig_size = plt.rcParams["figure.figsize"]
fig_size[0] = 75
fig_size[1] = 75
plt.rcParams["figure.figsize"] = fig_size
             
plt.figure().add_subplot(111, projection='3d').scatter(x, y, z, s=1);
plt.show()

#saves the coordinates
import numpy as np
import sys
points = np.transpose(np.array([x,y,z]))
#np.savetxt(sys.stdout, points, fmt="%.6f")
np.savetxt('data.txt', points, fmt="%.6f")

Спасибо за вашу помощь!

1 Ответ

0 голосов
/ 03 сентября 2018

Самый простой способ из того, что у вас есть:

X = np.stack((x,y,z)) # stack up all coordinates 
mask = X[-1]>=0 # mask of elements where z coordinate larger than 0 
x,y,z = X.T[mask].T # mask out the elements where z coordinate < 0 

Тогда постройте эти точки. Вы получите полушарие, я думаю,

...