예제 #1
0
 public static T Random <T>(this IList <T> list, CumulativeDistributionFunction f)
 {
     if (list.Count > 0)
     {
         double x     = random.NextDouble();
         double y     = f(x);
         int    index = (int)(y * list.Count);
         return(list[index]);
     }
     else
     {
         return(default(T));
     }
 }
예제 #2
0
 public static double NextDouble(this Random random, CumulativeDistributionFunction f)
 {
     return(f(random.NextDouble()));
 }
예제 #3
0
//    void InitStars(double sigma)
    void InitStars()
    {
        //m_pDust = new Star[m_numDust];

        //m_pStars = new Star[m_numStars];

        //m_pH2 = new Star[m_numH2 * 2];
        m_pDust.Clear();
        m_pStars.Clear();
        m_pH2.Clear();

        Star star, dust, H2;

        star = new Star();
        m_pStars.Add(star);
        // The first three stars can be used for aligning the
        // camera with the galaxy rotation.

        // First star ist the black hole at the centre
        m_pStars[0].m_a        = 0;
        m_pStars[0].m_b        = 0;
        m_pStars[0].m_angle    = 0;
        m_pStars[0].m_theta    = 0;
        m_pStars[0].m_velTheta = 0;
        m_pStars[0].m_center   = new Vector2(0, 0);
        m_pStars[0].m_velTheta = 0; //= GetOrbitalVelocity((m_pStars[0].m_a + m_pStars[0].m_b) / 2.0);
        m_pStars[0].m_temp     = 6000;

        // second star is at the edge of the core area
        star = new Star();
        m_pStars.Add(star);

        m_pStars[1].m_a        = m_radCore;
        m_pStars[1].m_b        = m_radCore * GetExcentricity(m_radCore);
        m_pStars[1].m_angle    = GetAngularOffset(m_radCore);
        m_pStars[1].m_theta    = 0;
        m_pStars[1].m_center   = new Vector2(0, 0);
        m_pStars[1].m_velTheta = GetOrbitalVelocity((m_pStars[1].m_a + m_pStars[1].m_b) / 2.0);
        m_pStars[1].m_temp     = 6000;

        star = new Star();
        m_pStars.Add(star);

        // third star is at the edge of the disk
        m_pStars[2].m_a        = m_radGalaxy;
        m_pStars[2].m_b        = m_radGalaxy * GetExcentricity(m_radGalaxy);
        m_pStars[2].m_angle    = GetAngularOffset(m_radGalaxy);
        m_pStars[2].m_theta    = 0;
        m_pStars[2].m_center   = new Vector2(0, 0);
        m_pStars[2].m_velTheta = GetOrbitalVelocity((m_pStars[2].m_a + m_pStars[2].m_b) / 2.0);
        m_pStars[2].m_temp     = 6000;

        // cell width of the histogramm
        //double dh = (double)m_radFarField / 100.0;

        // Initialize the stars
        CumulativeDistributionFunction cdf = new CumulativeDistributionFunction();

        cdf.SetupRealistic(1.0,               // Maximalintensität
                           0.02,              // k (bulge)
                           m_radGalaxy / 3.0, // disc skalenlänge
                           m_radCore,         // bulge radius
                           0,                 // start der intensitätskurve
                           m_radFarField,     // ende der intensitätskurve
                           1000);             // Anzahl der stützstellen
        for (int i = 3; i < m_numStars; ++i)
        {
            // random value between -1 and 1
            //double sum = -6;
            //for (int j = 0; j < 12; ++j)
            //{
            //    sum += UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX;
            //}
            //double rad = Math.Abs(sum) * m_radGalaxy;

            double rad = cdf.ValFromProb((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX);
            star = new Star();

            star.m_a        = rad;
            star.m_b        = rad * GetExcentricity(rad);
            star.m_angle    = GetAngularOffset(rad);
            star.m_theta    = 360.0 * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX);
            star.m_velTheta = GetOrbitalVelocity(rad);
            star.m_center   = new Vector2(0, 0);
            star.m_temp     = 6000 + (4000 * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX)) - 2000;
            star.m_mag      = 0.1 + 0.2 * (double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX;

            //int idx = (int)Math.Min(1.0 / dh * (star.m_a + star.m_b) / 2.0, 99.0);
            m_pStars.Add(star);
            //m_numberByRad[idx]++;
        }

        // Initialise Dust
        double x, y;

        for (int i = 0; i < m_numDust; ++i)
        {
            dust = new Star();
            if (i % 4 == 0)
            {
                rad = cdf.ValFromProb((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX);
            }
            else
            {
                x   = 2 * m_radGalaxy * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX) - m_radGalaxy;
                y   = 2 * m_radGalaxy * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX) - m_radGalaxy;
                rad = Math.Sqrt(x * x + y * y);
            }

            dust.m_a        = rad;
            dust.m_b        = rad * GetExcentricity(rad);
            dust.m_angle    = GetAngularOffset(rad);
            dust.m_theta    = 360.0 * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX);
            dust.m_velTheta = GetOrbitalVelocity((dust.m_a + dust.m_b) / 2.0);
            dust.m_center   = new Vector2(0, 0);

            // I want the outer parts to appear blue, the inner parts yellow. I'm imposing
            // the following temperature distribution (no science here it just looks right)
            dust.m_temp = 5000 + rad / 4.5;

            dust.m_mag = 0.015 + 0.01 * (double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX;

            m_pDust.Add(dust);
        }

        // Initialise H2

        for (int i = 0; i < m_numH2 * 2; ++i)
        {
            H2 = new Star();
            m_pH2.Add(H2);
        }
        for (int i = 0; i < m_numH2; ++i)
        {
            x   = 2 * (m_radGalaxy) * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX) - (m_radGalaxy);
            y   = 2 * (m_radGalaxy) * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX) - (m_radGalaxy);
            rad = Math.Sqrt(x * x + y * y);

            int k1 = 2 * i;
            m_pH2[k1].m_a        = rad;
            m_pH2[k1].m_b        = rad * GetExcentricity(rad);
            m_pH2[k1].m_angle    = GetAngularOffset(rad);
            m_pH2[k1].m_theta    = 360.0 * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX);
            m_pH2[k1].m_velTheta = GetOrbitalVelocity((m_pH2[k1].m_a + m_pH2[k1].m_b) / 2.0);
            m_pH2[k1].m_center   = new Vector2(0, 0);
            m_pH2[k1].m_temp     = 6000 + (6000 * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX)) - 3000;
            m_pH2[k1].m_mag      = 0.1 + 0.05 * (double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX;

            int k2 = 2 * i + 1;
            m_pH2[k2].m_a        = rad + 1000;
            m_pH2[k2].m_b        = rad * GetExcentricity(rad);
            m_pH2[k2].m_angle    = GetAngularOffset(rad);
            m_pH2[k2].m_theta    = m_pH2[k1].m_theta;
            m_pH2[k2].m_velTheta = m_pH2[k1].m_velTheta;
            m_pH2[k2].m_center   = m_pH2[k1].m_center;
            m_pH2[k2].m_temp     = m_pH2[k1].m_temp;
            m_pH2[k2].m_mag      = m_pH2[k1].m_mag;
        }
    }
예제 #4
0
        private void initStars()
        {
            QuadTree <Star> stars     = new QuadTree <Star>(8, new Rect(-320000f, -320000f, 640000f, 640000f));
            List <Star>     starsList = new List <Star>();

            CumulativeDistributionFunction cdf = new CumulativeDistributionFunction();

            cdf.SetupRealistic(1.0d, 0.02d, galaxyGenParams.GalaxyRadius / 3, galaxyGenParams.GalaxyCoreRadius, 0d, galaxyGenParams.GalaxyFarFieldRadius, 1000);

            Star   star;
            double rand;
            int    k1 = 2;
            int    k2 = 0;

            for (int i = 0; i < galaxyGenParams.StarCount; i++)
            {
                star          = new Star();
                rand          = cdf.ValFromProb(Rand.Value);
                star.A        = rand;
                star.B        = rand * getExcentricity(rand);
                star.Angle    = getAngularOffset(rand);
                star.Theta    = 360f * Rand.Value;
                star.Position = calcPos(star, galaxyGenParams.PertubationCount, galaxyGenParams.PertubationDamp);

                // Check for stars within minDistance
                bool recheckPos;

                do
                {
                    recheckPos = false;

                    Rect rect = new Rect(star.Position.x - MinStarDistance,
                                         star.Position.z - MinStarDistance,
                                         MinStarDistance * 2f,
                                         MinStarDistance * 2f);
                    List <Star> starsInRange = stars.RetrieveObjectsInArea(rect);

                    if (starsInRange.Count > 0)
                    {
                        rand          = cdf.ValFromProb(Rand.Value);
                        star.A        = rand;
                        star.B        = rand * getExcentricity(rand);
                        star.Angle    = getAngularOffset(rand);
                        star.Theta    = 360f * Rand.Value;
                        star.Position = calcPos(star, galaxyGenParams.PertubationCount, galaxyGenParams.PertubationDamp);

                        repositionCounter++;

                        recheckPos = true;
                    }
                } while (recheckPos);


                star.Temp = 2500 + (12500 * Rand.Value - 3000);
                star.Mag  = 0.5f + 0.5 * Rand.Value;


                stars.Insert(star);
                starsList.Add(star);
            }

            Current.Galaxy.Stars    = stars;
            Current.Galaxy.AllStars = starsList;
            Debug.Log("Repositionings: " + repositionCounter);
        }
예제 #5
0
//    void InitStars(double sigma)
    void InitStars()
    {
        //m_pDust = new Star[m_numDust];

        //m_pStars = new Star[m_numStars];

        //m_pH2 = new Star[m_numH2 * 2];
        m_pDust.Clear();
        m_pStars.Clear();
        m_pH2.Clear();

        Star star, dust, H2;
        
        star = new Star();
        m_pStars.Add(star);
        // The first three stars can be used for aligning the
        // camera with the galaxy rotation.

        // First star ist the black hole at the centre
        m_pStars[0].m_a = 0;
        m_pStars[0].m_b = 0;
        m_pStars[0].m_angle = 0;
        m_pStars[0].m_theta = 0;
        m_pStars[0].m_velTheta = 0;
        m_pStars[0].m_center = new Vector2(0, 0);
        m_pStars[0].m_velTheta = 0; //= GetOrbitalVelocity((m_pStars[0].m_a + m_pStars[0].m_b) / 2.0);
        m_pStars[0].m_temp = 6000;

        // second star is at the edge of the core area
        star = new Star();
        m_pStars.Add(star);

        m_pStars[1].m_a = m_radCore;
        m_pStars[1].m_b = m_radCore * GetExcentricity(m_radCore);
        m_pStars[1].m_angle = GetAngularOffset(m_radCore);
        m_pStars[1].m_theta = 0;
        m_pStars[1].m_center = new Vector2(0, 0);
        m_pStars[1].m_velTheta = GetOrbitalVelocity((m_pStars[1].m_a + m_pStars[1].m_b) / 2.0);
        m_pStars[1].m_temp = 6000;

        star = new Star();
        m_pStars.Add(star);

        // third star is at the edge of the disk
        m_pStars[2].m_a = m_radGalaxy;
        m_pStars[2].m_b = m_radGalaxy * GetExcentricity(m_radGalaxy);
        m_pStars[2].m_angle = GetAngularOffset(m_radGalaxy);
        m_pStars[2].m_theta = 0;
        m_pStars[2].m_center = new Vector2(0, 0);
        m_pStars[2].m_velTheta = GetOrbitalVelocity((m_pStars[2].m_a + m_pStars[2].m_b) / 2.0);
        m_pStars[2].m_temp = 6000;

        // cell width of the histogramm
        //double dh = (double)m_radFarField / 100.0;

        // Initialize the stars
        CumulativeDistributionFunction cdf = new CumulativeDistributionFunction();
        cdf.SetupRealistic(1.0,             // Maximalintensität
                           0.02,            // k (bulge)
                           m_radGalaxy / 3.0, // disc skalenlänge
                           m_radCore,       // bulge radius
                           0,               // start der intensitätskurve
                           m_radFarField,   // ende der intensitätskurve
                           1000);           // Anzahl der stützstellen
        for (int i = 3; i < m_numStars; ++i)
        {
            // random value between -1 and 1
            //double sum = -6;
            //for (int j = 0; j < 12; ++j)
            //{
            //    sum += UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX;
            //}
            //double rad = Math.Abs(sum) * m_radGalaxy;
            
            double rad = cdf.ValFromProb((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX);
            star = new Star();

            star.m_a = rad;
            star.m_b = rad * GetExcentricity(rad);
            star.m_angle = GetAngularOffset(rad);
            star.m_theta = 360.0 * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double) RAND_MAX);
            star.m_velTheta = GetOrbitalVelocity(rad);
            star.m_center = new Vector2(0, 0);
            star.m_temp = 6000 + (4000 * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double) RAND_MAX)) - 2000;
            star.m_mag = 0.1 + 0.2 * (double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX;

            //int idx = (int)Math.Min(1.0 / dh * (star.m_a + star.m_b) / 2.0, 99.0);
            m_pStars.Add(star);
            //m_numberByRad[idx]++;
        }

        // Initialise Dust
        double x, y;
        for (int i = 0; i < m_numDust; ++i)
        {
            dust = new Star();
            if (i % 4 == 0)
            {
                rad = cdf.ValFromProb((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX);
            }
            else
            {
                x = 2 * m_radGalaxy * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX) - m_radGalaxy;
                y = 2 * m_radGalaxy * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX) - m_radGalaxy;
                rad = Math.Sqrt(x * x + y * y);
            }

            dust.m_a = rad;
            dust.m_b = rad * GetExcentricity(rad);
            dust.m_angle = GetAngularOffset(rad);
            dust.m_theta = 360.0 * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX);
            dust.m_velTheta = GetOrbitalVelocity((dust.m_a + dust.m_b) / 2.0);
            dust.m_center = new Vector2(0, 0);

            // I want the outer parts to appear blue, the inner parts yellow. I'm imposing
            // the following temperature distribution (no science here it just looks right)
            dust.m_temp = 5000 + rad / 4.5;

            dust.m_mag = 0.015 + 0.01 * (double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX;
            
            m_pDust.Add(dust);
        }

        // Initialise H2

        for (int i = 0; i < m_numH2*2; ++i)
        {
            H2 = new Star();
            m_pH2.Add(H2);
        }
        for (int i = 0; i < m_numH2; ++i)
        {

            x = 2 * (m_radGalaxy) * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX) - (m_radGalaxy);
            y = 2 * (m_radGalaxy) * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX) - (m_radGalaxy);
            rad = Math.Sqrt(x * x + y * y);

            int k1 = 2 * i;
            m_pH2[k1].m_a = rad;
            m_pH2[k1].m_b = rad * GetExcentricity(rad);
            m_pH2[k1].m_angle = GetAngularOffset(rad);
            m_pH2[k1].m_theta = 360.0 * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX);
            m_pH2[k1].m_velTheta = GetOrbitalVelocity((m_pH2[k1].m_a + m_pH2[k1].m_b) / 2.0);
            m_pH2[k1].m_center = new Vector2(0, 0);
            m_pH2[k1].m_temp = 6000 + (6000 * ((double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX)) - 3000;
            m_pH2[k1].m_mag = 0.1 + 0.05 * (double)UnityEngine.Random.Range(0, RAND_MAX) / (double)RAND_MAX;

            int k2 = 2 * i + 1;
            m_pH2[k2].m_a = rad + 1000;
            m_pH2[k2].m_b = rad * GetExcentricity(rad);
            m_pH2[k2].m_angle = GetAngularOffset(rad);
            m_pH2[k2].m_theta = m_pH2[k1].m_theta;
            m_pH2[k2].m_velTheta = m_pH2[k1].m_velTheta;
            m_pH2[k2].m_center = m_pH2[k1].m_center;
            m_pH2[k2].m_temp = m_pH2[k1].m_temp;
            m_pH2[k2].m_mag = m_pH2[k1].m_mag;

        }
    }