三行代码  ›  专栏  ›  技术社区  ›  MirceaKitsune

围绕原点形成单个立方体的8个立方体的最小/最大角

  •  0
  • MirceaKitsune  · 技术社区  · 1 周前

    const org = Vector3(32, 48, 64)
    const thick = 16
    const mins = Vector3(org.x - thick, org.y - thick, org.z - thick)
    const maxs = Vector3(org.x + thick, org.y + thick, org.z + thick)
    
    for x in range(mins.x, maxs.x, thick):
        for y in range(mins.y, maxs.y, thick):
            for z in range(mins.z, maxs.z, thick):
                var vec = Vector3(x, y, z)
    

    我想把这个立方体细分成8个相互完美接触的立方体。我需要一个 mins_0 / maxs_0 , mins_1 / maxs_1 , ... , mins_7 / maxs_7 每个代表立方体的一部分。

    我被数学难住了:我不知道如何转换原点和厚度偏移,显然要保持顺序,以便任何循环都从正确的位置开始( mins.# < maxs.# 总是)。我只知道两种明显的组合:

    mins_0 = Vector3(org.x - thick, org.y - thick, org.z - thick)
    maxs_0 = Vector3(org.x, org.y, org.z)
    mins_4 = Vector3(org.x, org.y, org.z)
    maxs_4 = Vector3(org.x + thick, org.y + thick, org.z + thick)
    

    如何正确填充其他6个空间以覆盖剩余区域?

    1 回复  |  直到 1 周前
        1
  •  1
  •   Beta    1 周前

    这将是一个巨大的挑战 大量 向量算法更简单,但我们可以使用原始坐标:

    mins_0 = Vector3(org.x - thick, org.y - thick, org.z - thick)
    maxs_0 = Vector3(org.x,         org.y,         org.z)
    
    mins_1 = Vector3(org.x - thick, org.y - thick, org.z)
    maxs_1 = Vector3(org.x,         org.y,         org.z + thick)
    
    mins_2 = Vector3(org.x - thick, org.y,         org.z - thick)
    maxs_2 = Vector3(org.x,         org.y + thick, org.z)
    
    mins_3 = Vector3(org.x - thick, org.y,         org.z)
    maxs_3 = Vector3(org.x,         org.y + thick, org.z + thick)
    
    mins_4 = Vector3(org.x,         org.y - thick, org.z - thick)
    maxs_4 = Vector3(org.x + thick, org.y,         org.z)
    
    mins_5 = Vector3(org.x,         org.y - thick, org.z)
    maxs_5 = Vector3(org.x + thick, org.y,         org.z + thick)
    
    mins_6 = Vector3(org.x,         org.y,         org.z - thick)
    maxs_6 = Vector3(org.x + thick, org.y + thick, org.z)
    
    mins_7 = Vector3(org.x,         org.y,         org.z)
    maxs_7 = Vector3(org.x + thick, org.y + thick, org.z + thick)