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