Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何画一个球壳?_C#_Vector_Geometry_Drawing - Fatal编程技术网

C# 如何画一个球壳?

C# 如何画一个球壳?,c#,vector,geometry,drawing,C#,Vector,Geometry,Drawing,我试图在C#中安排一个球壳中的点。我有代码将一堆点(我正在做有限元分析)排列成一个球形,半径为双地球半径。我不知道如何对球壳做同样的事情。想法 for(double x=-earthRadius;x

我试图在C#中安排一个球壳中的点。我有代码将一堆点(我正在做有限元分析)排列成一个球形,半径为
双地球半径
。我不知道如何对球壳做同样的事情。想法

for(double x=-earthRadius;x如果((x*x)+(y*y)+(z*z),我只使用笛卡尔坐标。我选择不使用球坐标,因为这是一个次优的解决方案:它使代码不那么优雅,使用
Math.Sin()
Math.Cos()
会使它变慢。下面是我得到的最终解决方案:

  for (double x = -earthRadius; x < earthRadius; x += pointIncrement) //taken from http://stackoverflow.com/questions/8671385/sphere-drawing-in-java 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++;
                        }

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

我建议您循环查找点。然后将它们转换为笛卡尔坐标。
  for (double x = -earthRadius; x < earthRadius; x += pointIncrement) //taken from http://stackoverflow.com/questions/8671385/sphere-drawing-in-java 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++;
                        }

                    }
                }
            }
        }