如何绘制球形shell?

How to draw a spherical shell?

我正在尝试在 C# 中排列球形 shell 中的点。我有代码在半径为 double earthRadius 的球形图案中排列一堆点(我正在进行有限元分析)。我不知道如何为球形 shell like the type pictured here 做同样的事情。想法?

for (double x = -earthRadius; x < earthRadius; x += pointIncrement) //taken from  and slightly altered to make more efficient
        {
            for (double y = -earthRadius; y < earthRadius; y += pointIncrement)
            {
                for (double z = -earthRadius; z < earthRadius; z += pointIncrement)
                {
                    if ((x * x) + (y * y) + (z * z) <= earthRadius * earthRadius)
                    {
                        earth.AddPoint(new Vector(x, y, z), 0); 
                        totalPoints++;
                    }
                }
            }
        }

我只使用笛卡尔坐标就解决了这个问题。我选择不使用球坐标,因为它是一个次优的解决方案:它使代码不那么优雅并且使用 Math.Sin()Math.Cos() 会减慢它的速度。这是我得到的最终解决方案:

  for (double x = -earthRadius; x < earthRadius; x += pointIncrement) //taken from  and slightly altered to make more efficient
        {
            for (double y = -earthRadius; y < earthRadius; y += pointIncrement)
            {
                for (double z = -earthRadius; z < earthRadius; z += pointIncrement)
                {
                    if ((x * x) + (y * y) + (z * z) <= earthRadius * earthRadius)
                    {

                        if ((x * x) + (y * y) + (z * z) >= (earthRadius - shellThickness) * (earthRadius - shellThickness))
                        {

                            earth.AddPoint(new Vector(x, y, z), 0); // need to figure out how to calculate masspoint
                            totalPoints++;
                        }

                    }
                }
            }
        }

请注意,我只是添加了另一个 if 语句。我(愚蠢地)没有使用 && 运算符,因为我认为它会降低可读性。