计算长方体网格上的点

ckocjqey  于 2021-07-06  发布在  Java
关注(0)|答案(2)|浏览(353)

我的数学能力有问题。所以我需要计算每个aix中特定数量点的位置(x,y,z)。以这张图片为例

final double gapX = lengthX / dotsPerXAxis;
final double gapY = lengthY / dotsPerYAxis;
final double gapZ = lengthZ / dotsPerZAxis;

for (BlockFace blockFace : BlockHandler.DIRECT_RELATIVES) {
    final DecimalVector3D minCorner = new DecimalVector3D(
        blockFace.getModX(),
        blockFace.getModY(),
        blockFace.getModZ()
    );

for (int x = 0; x < dotsPerXAxis || x == 0; x++) {
    for (int y = 0; y < dotsPerYAxis; y++) {
        for (int z = 0; z < dotsPerZAxis; z++) {

        }
    }
}

我现在的问题是:我如何迭代所有的点,除了那些在长方体内部的点,然后计算它们的位置并将它们放入一个不可变的列表中?

2wnc66cl

2wnc66cl1#

在mbo的帮助下,我发现了这一点

for (BlockFace blockFace : BlockHandler.DIRECT_RELATIVES) {
        for (int x = 0; x < dotsPerXAxis || x == 0 || x == dotsPerXAxis - 1; x++) {
            for (int y = 0; y < dotsPerXAxis || y == 0 || y == dotsPerYAxis - 1; y++) {
                for (int z = 0; z < dotsPerXAxis || z == 0;
                     z += (y == 0 || y == dotsPerYAxis - 1) || (x == 0 || x == dotsPerXAxis - 1) ? 1 :
                         dotsPerZAxis - 1) {

                    results.add(new DecimalVector3D(
                        x,
                        y,
                        z
                    ));
                }
            }
        }
    }
wz8daaqr

wz8daaqr2#

如果点的至少一个坐标为零或零,则需要处理该点 dotsPerZAxis .
所以设置标志-如果x坐标在面上,如果y坐标在面上。如果两个标志都没有设置-只获取第一个和最后一个z坐标,否则遍历所有z坐标。
未经检查的java:

for (int x = 0; x < dotsPerXAxis; x++) {
    bool atX = (x == 0) || (x == dotsPerXAxis - 1);
    for (int y = 0; y < dotsPerYAxis; y++) {
        bool atY = (y == 0) || (y == dotsPerYAxis - 1);

        int zstep = (atX || atY)? 1: dotsPerZAxis - 1;

        for (int z = 0; z < dotsPerZAxis; z+=zstep) {
           treat(x,y,z)
        }
    }
}

ideone python工作代码作为概念证明 n^3 - (n-2)^3 点(n=3为26个曲面点,n=4为56个,n=5为98个)

相关问题