【问题标题】:How to store and access voxel sphere in array?如何在数组中存储和访问体素球?
【发布时间】:2021-02-19 01:00:36
【问题描述】:

我在下面的代码中生成了一个体素球体(椭球体)。

        struct Volume {
          private int3 r; // radiuses of ellipsoid (3 integers for 3 axes)

          public IEnumerable<int3> Iterate()
          {
            for (var x = -r.x; x <= r.x; x++)
            for (var y = -r.y; y <= r.y; y++)
            for (var z = -r.z; z <= r.z; z++)
                if (x * x + y * y + z * z <= r.x * r.y * r.z)
                    yield return int3(x, y, z);
          }
          // return number/index of a point generated in the method above
          public int IndexOf(int3 point) => ??? 
        }

然后我将所有条目收集到一个列表中

            var sphere = new Volume(3);  // radius of sphere is 3
            var pointsInSphere = sphere.Iterate().ToArray();

有没有办法实现方法IndexOf而不搜索数组中的点? 例如,我们可以轻松地为体素长方体做到这一点:index = point.x*sizeY*sizeZ + point.y*sizeZ + point.z,但我发现对球体做同样的事情太复杂了,甚至不知道这是否可能。

【问题讨论】:

    标签: c# arrays 3d volume voxel


    【解决方案1】:

    这也让我感兴趣。如果你能以某种有序的方式对体素进行排序,那么你可以用数学方法描述它的位置。

    例如,如果您在数组中表示二维数组,您将使用int(width*height) 而不是int(height)(width)

    还可以使用:

    Count = width * height
    Width = count % width
    Height = count / width
    

    因此,我们实质上是在寻找表示球体的数组数组,并且坐标需要映射到这些数组的索引。

    【讨论】:

      猜你喜欢
      • 2010-12-20
      • 1970-01-01
      • 1970-01-01
      • 2019-09-18
      • 2017-05-07
      • 2020-12-03
      • 1970-01-01
      • 2014-12-14
      • 2015-12-01
      相关资源
      最近更新 更多