【问题标题】:Creating a spiral galaxy need math guidance创建螺旋星系需要数学指导
【发布时间】:2012-10-22 20:36:15
【问题描述】:

我正在为恒星/系统创建一个由块组成的旋转星系。

我一直在摆弄这个几天,到目前为止:

public int numberArms = 6;
public int numberStars = 1000;
public float galaxyRadius = 500f;
public int spread = 100;

float fHatRandom (float fRange)
{
   float fArea = 4 * Mathf.Atan (6.0f);
   float fP = fArea * Random.value;
   return Mathf.Tan (fP / 4) * fRange / 6.0f;
}

float fLineRandom (float fRange)
{
   float fArea = fRange * fRange / 2;
   float fP = fArea * Random.value;
   return fRange - Mathf.Sqrt (fRange * fRange - 2 * fP);
}
// Use this for initialization
void Start ()
{
   Random.seed = 100;

   int starsPerArm = numberStars / numberArms;
   float fAngularSpread = spread / numberArms;
   float fArmAngle = (360 / numberArms);
   for (int arm = 0; arm < numberArms; arm++)
   {
     for (int i = 0; i < starsPerArm; i++)
     {
      float fR = fHatRandom (galaxyRadius);      
      float fQ = fLineRandom (fAngularSpread);
      float fK = 1;

      float fA = numberArms * (fArmAngle);

      float fX = fR * Mathf.Cos (Mathf.Deg2Rad * (fA + fR * fK + fQ));
      float fY = fR * Mathf.Sin (Mathf.Deg2Rad * (fA + fR * fK + fQ));

      Vector3 starPos = new Vector3 (fX, fY, arm*4);
      Collider[] colliders = Physics.OverlapSphere (starPos, 1);

      if (colliders.Length == 0)
      {
          GameObject star = GameObject.CreatePrimitive (PrimitiveType.Cube);
          star.transform.position = starPos;
          star.transform.parent = transform;
      } else
      { 
          i--;//because they overlapped, we try again.
      }
     }    
   }
}

}

就目前而言,它可以很好地创建银河系的旋臂。但正如你所看到的,我只是将手臂的位置设置为堆叠在其他手臂上,因为我一生都无法弄清楚如何让它们围绕中心旋转,因为我的中心似乎不在.

诚然,我的数学技能堪比蚊虫,并且一直在摸索,有人可以帮助纠正数学并将手臂/中心放在他们所属的位置吗?

【问题讨论】:

    标签: c# math


    【解决方案1】:

    不应该这样吗:

    float fA = numberArms * (fArmAngle);
    

    成为

    float fA = arm * (fArmAngle);
    

    只是说...

    【讨论】:

    • 天啊。就像我说的,小虫的数学能力。我正在改变所有的公式,并试图找出我的角度为什么不对...pff。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-21
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    相关资源
    最近更新 更多