【问题标题】:How to Obtain Coordinates for a Hemisphere in Python如何在 Python 中获取半球的坐标
【发布时间】:2018-09-03 02:41:37
【问题描述】:

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

感谢您的帮助!

【问题讨论】:

  • 您认为球体和半球之间的主要区别是什么?
  • z 坐标总是正的,所以我可以消除所有具有负 z 分量的点。但是,我不知道这是否会使点保持等距。
  • 所有点与最近的邻居的距离都是等距的,前提是它们在您限制 z>0 之前是这样的

标签: python graph 3d discretization


【解决方案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 

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

【讨论】:

  • 您认为这些坐标通过进行此更改会等距吗?我不熟悉面具操作,但它在图形上看起来像鸡蛋的上半部分。
  • 掩码只是在不使用循环的情况下消除 z
  • 如果在此更改之前,这些点将保持等距。他们没有改变。只删除了一半
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-20
  • 2014-09-02
  • 1970-01-01
  • 2019-07-07
  • 1970-01-01
  • 2021-09-23
  • 1970-01-01
相关资源
最近更新 更多