【问题标题】:How to create a uniform-in-volume point cloud in numpy? [duplicate]如何在 numpy 中创建体积均匀的点云? [复制]
【发布时间】:2021-05-03 06:42:12
【问题描述】:

这实际上是一个点云形式的网格网格 (n, 3)。

这段代码做到了,剩下的就是矢量化,我正在努力解决这个问题。
也许这里需要一些跨步技巧+重复?

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


dim_len = 5

x = np.linspace(0., 1., dim_len)
y = np.linspace(0., 1., dim_len)
z = np.linspace(0., 1., dim_len)

n_points = dim_len ** 3
point_cloud = np.zeros((n_points, 3))
# TODO vectorize
point_ind = 0
for i in range(dim_len):
    for j in range(dim_len):
        for k in range(dim_len):
            point_cloud[point_ind, 0] = x[i]
            point_cloud[point_ind, 1] = y[j]
            point_cloud[point_ind, 2] = z[k]
            point_ind += 1

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

【问题讨论】:

    标签: python numpy vectorization


    【解决方案1】:

    Following from here,

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

    我没有删除这个问题,因为它是谷歌可搜索的。我花了一段时间才找到这方面的参考资料。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-21
      • 2020-03-19
      • 1970-01-01
      • 2011-07-21
      • 2016-04-09
      • 1970-01-01
      • 2016-08-12
      • 1970-01-01
      相关资源
      最近更新 更多