立方体上的等距点 [英] Equidistant points across a cube

查看:118
本文介绍了立方体上的等距点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要初始化一些三维点,并且我希望它们在整个立方体中等距分布.有什么创造性的方法可以做到这一点?

I need to initialize some three dimensional points, and I want them to be equally spaced throughout a cube. Are there any creative ways to do this?

我正在使用迭代的期望最大化"算法,希望我的初始向量均匀地跨越"空间.

I am using an iterative Expectation Maximization algorithm and I want my initial vectors to "span" the space evenly.

例如,假设我要在一个大小为1x1x1的立方体中平均分布八个点.我希望边长为0.333的立方体角的点位于较大立方体的中心.

For example, suppose I have eight points that I want to space equally in a cube sized 1x1x1. I would want the points at the corners of a cube with a side length of 0.333, centered within the larger cube.

下面是一个2D示例.请注意,红点彼此之间和边缘等距.我想要3D效果也一样.

A 2D example is below. Notice that the red points are equidistant from eachother and the edges. I want the same for 3D.

在点数没有整数立方根的情况下,可以在安排中留一些空隙".

In cases where the number of points does not have an integer cube root, I am fine with leaving some "gaps" in the arrangement.

目前,我正在计算点数的立方根,并使用它来计算点数和它们之间的期望距离.然后,我遍历这些点并递增X,Y和Z坐标(交错排列,以使Y直到X循环回到0时才递增,对于Z而言,对于Y来说也是一样).

Currently I am taking the cube root of the number of points and using that to calculate the number of points and the desired distance between them. Then I iterate through the points and increment the X, Y and Z coordinates (staggered so that Y doesn't increment until X loops back to 0, same for Z with regard for Y).

如果在MATLAB中有一种简便的方法,我很乐意使用它.

If there's an easy way to do this in MATLAB, I'd gladly use it.

推荐答案

对于点数不是理想立方体的情况,您必须更详细地定义问题.但是,对于点数为立方体的情况,可以使用:

You'll have to define the problem in more detail for the cases where the number of points isn't a perfect cube. Hovever, for the cases where the number of points is a cube, you can use:

l=linspace(0,1,n+2);
x=l(2:n+1); y=x; z=x;
[X, Y, Z] = meshgrid(x, y, z);

然后对于矩阵中的每个位置,该点的坐标由X,Y和Z的相应元素给出.如果要在单个矩阵中列出这些点,使得每一行代表一个点,则x,y和z坐标的三列,那么您可以说:

Then for each position in the matrices, the coordinates of that point are given by the corresponding elements of X, Y, and Z. If you want the points listed in a single matrix, such that each row represents a point, with the three columns for x, y, and z coordinates, then you can say:

points(:,1) = reshape(X, [], 1);
points(:,2) = reshape(Y, [], 1);
points(:,3) = reshape(Z, [], 1);

您现在在整个单位多维数据集中的网格上都有一个n^3点的列表,不包括边界.正如其他人所建议的,如果您希望减少点数,则可以随机删除一些点.通过使用randi([0 n^3], a, 1)生成要删除的点的a索引,这将很容易做到. (不要忘记检查randi()返回的矩阵中是否有重复项,否则您可能不会删除足够的点.)

You now have a list of n^3 points on a grid throughout the unit cube, excluding the boundaries. As others have suggested, you can probably randomly remove some of the points if you want fewer points. This would be easy to do, by using randi([0 n^3], a, 1) to generate a indices of points to remove. (Don't forget to check for duplicates in the matrix returned by randi(), otherwise you might not delete enough points.)

这篇关于立方体上的等距点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆