制作空心体素锥 - c#

我正在尝试在C#中创建体素样式的圆锥形状。我已经使用多维数据集构建了圆锥体,但是无法弄清楚如何仅构建外层(使其空心),而不是构建如图所示的实心圆锥体。

制作空心体素锥 - c#
到目前为止的代码(由其他人的脚本编辑)

// Create a cone made of cubes. Can be called at runtime
public void MakeVoxelCone()
{
    for (int currentLength = 0; currentLength < maxLength; currentLength++)
        MakeNewLayer(currentLength);
}

// Make a new layer of cubes on the cone
private void MakeNewLayer(int currentLength)
{
    center = new Vector3(0, currentLength, 0);
    for (int x = -currentLength; x < currentLength; x++)
    {
        for (int z = -currentLength; z < currentLength; z++)
        {
            // Set position to spawn cube
            Vector3 pos = new Vector3(x, currentLength, z);

            // The distance to the center of the cone at currentLength point
            float distanceToMiddle = Vector3.Distance(pos, center);

            // Create another layer of the hollow cone
            if (distanceToMiddle < currentLength)
            {
                // Add all cubes to a List array
                Cubes.Add(MakeCube(pos));
            }
        }
    }
}

// Create the cube and set its properties
private GameObject MakeCube(Vector3 position)
{
    GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
    cube.GetComponent<Renderer>().material.color = Color.blue;
    if (!AddCollider)
        Destroy(cube.GetComponent<BoxCollider>());
    cube.transform.position = position;
    cube.transform.parent = transform;
    cube.name = "cube [" + position.y + "-" + position.x + "," + position.z + "]";

    return cube;
}

我认为它可能很简单,但无法弄清楚。
也许与if (distanceToMiddle < currentLength)部分有关,但是将<替换为==会破坏整体形状。

@ Jax297 >= (currentLength-1)更接近,但目前还不正确。现在,它的金字塔被切掉了。
制作空心体素锥 - c#

参考方案

假设您当前的长度是外径,则必须引入一个可变厚度并与currentleght(厚度)进行比较,因此需要保持一个内径

(currentLength - thickness) < distanceToMiddle && distanceToMiddle < currentLength 

Java中的“ <<”运算符 - java

最喜欢的语句来自Java的Character类:(1 << Character.PARAGRAPH_SEPARATOR)) >> type PARAGRAPH_SEPARATOR是字节,type是整数。这句话中的操作员,他们做什么?如何以及在哪里可以使用这些运算符?这是oracles java.lang.Character文档。该类中…

当我运行python代码时,它说“ <<目前是意外情况” - python

基本上,这是我们合作者的python代码,用于生成网格,该网格是在Linux环境下开发的。我使用Cygwin在Windows上运行此代码。麻烦部分如下。 BiV_temp.geo也是一个python脚本。因此,命令是用预定义的数字和文件名替换脚本BiV_temp.geo中的字符串。os.system('cp BiV_fiber.geo BiV_te…

LeetCode题解拼凑硬币

小Q十分富有,拥有非常多的硬币,小Q拥有的硬币是有规律的,对于所有的非负整数K,小Q恰好各有两个面值为2^k的硬币,所有小Q拥有的硬币就是1,1,2,2,4,4,8,8.....小Q有一天去商店购买东西需要支付n元钱,小Q想知道有多少种方案从他拥有的硬币中选取一些拼凑起来恰好是n元(如果两种方案某个面值的硬币选取的个数不一样就考虑为不一样的方案)输入:输入包…

Python lmfit约束:a <b <c - python

我在Python中使用lmfit来拟合一些数据,其中包括拟合变量a,b和c。我需要确保a <b <c。我发现http://cars9.uchicago.edu/software/python/lmfit_MinimizerResult/constraints.html谈到需要定义为不等式和设置虚拟变量的约束。例如,如果我想要a + b <=…

将谓词<T>转换为Func <T,bool> - c#

我有一个包含成员Predicate的类,希望在Linq表达式中使用该类:using System.Linq; class MyClass { public bool DoAllHaveSomeProperty() { return m_instrumentList.All(m_filterExpression); } private IEnumerable&…