簡體   English   中英

球體體積中點的規則分布

[英]Regular Distribution of Points in the Volume of a Sphere

我正在嘗試在球體的體積內生成規則的n個點。 我發現這個類似的答案( https://scicomp.stackexchange.com/questions/29959/uniform-dots-distribution-in-a-sphere )在球體表面上生成均勻的規則n個點,與以下代碼:

import numpy as np 

n = 5000
r = 1
z = []
y = []
x = []
alpha = 4.0*np.pi*r*r/n 
d = np.sqrt(alpha) 
m_nu = int(np.round(np.pi/d))
d_nu = np.pi/m_nu
d_phi = alpha/d_nu
count = 0
for m in range (0,m_nu):
    nu = np.pi*(m+0.5)/m_nu
    m_phi = int(np.round(2*np.pi*np.sin(nu)/d_phi))
    for n in range (0,m_phi):
        phi = 2*np.pi*n/m_phi
        xp = r*np.sin(nu)*np.cos(phi)
        yp = r*np.sin(nu)*np.sin(phi)
        zp = r*np.cos(nu)
        x.append(xp)
        y.append(yp)
        z.append(zp)
        count = count +1

按預期工作:

在此處輸入圖像描述

如何修改它以在球體體積中生成一組常規的n點?

另一種方法來做到這一點,產生體積均勻:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

dim_len = 30
spacing = 2 / dim_len
point_cloud = np.mgrid[-1:1:spacing, -1:1:spacing, -1:1:spacing].reshape(3, -1).T

point_radius = np.linalg.norm(point_cloud, axis=1)
sphere_radius = 0.5
in_points = point_radius < sphere_radius

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(point_cloud[in_points, 0], point_cloud[in_points, 1], point_cloud[in_points, 2], )
plt.show()

Output(matplotlib 混淆了視圖,但它是一個均勻采樣的球體(體積))

在此處輸入圖像描述


均勻采樣,然后通過半徑檢查點是否在球體中。

統一抽樣參考[請參閱此答案的編輯歷史以了解天真抽樣]。


這種方法的缺點是會生成冗余點,然后將其丟棄。
它具有矢量化的優點,這可能彌補了缺點。 我沒有檢查。

通過花哨的索引,可以生成與此方法相同的點而不會生成冗余點,但我懷疑它是否可以輕松(或根本不)矢量化。

沿 X 均勻采樣。對於每個 X 值,您從 X²+Y²=1 繪制兩個 Y。 在這兩個 Y 之間均勻采樣。然后對於每個 (X, Y) 對,從 X²+Y²+Z²=1 中繪制兩個 Z。 在這兩個 Z 之間均勻采樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM