如何在Python中获得半球的坐标

问题描述 投票:-1回答:1

目前,我有一些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")

谢谢您的帮助!

python graph 3d discretization
1个回答
1
投票

最简单的方法:

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 

然后绘制这些点。你会得到一个半球我想

© www.soinside.com 2019 - 2024. All rights reserved.