コード例 #1
0
        public static Vector2 Area(ref UMT.MersenneTwister _rand, MTRandom.Normalization n, float t)
        {
            float x, y;

            x = y = 0;
            switch (n)
            {
            case MTRandom.Normalization.STDNORMAL:
                x = (float)NormalDistribution.Normalize(_rand.NextSingle(true), t);
                y = (float)NormalDistribution.Normalize(_rand.NextSingle(true), t);
                break;

            case MTRandom.Normalization.POWERLAW:
                x = (float)PowerLaw.Normalize(_rand.NextSingle(true), t, 0, 1);
                y = (float)PowerLaw.Normalize(_rand.NextSingle(true), t, 0, 1);
                break;

            default:
                x = _rand.NextSingle(true);
                y = _rand.NextSingle(true);
                break;
            }

            // Move to -1, 1 space as for CIRCLE and SPHERE
            return(new Vector2((2 * x - 1), (2 * y - 1)));
        }
コード例 #2
0
ファイル: RandomCube.cs プロジェクト: Dracir/semicolon
        public static Vector3 Surface(ref UMT.MersenneTwister _rand, MTRandom.Normalization n, float t)
        {
            Vector3 pos = new Vector3();

            switch (n)
            {
            case MTRandom.Normalization.STDNORMAL:
                pos = GetPointOnCubeSurface(
                    (float)NormalDistribution.Normalize(_rand.NextSingle(true), t),
                    (float)NormalDistribution.Normalize(_rand.NextSingle(true), t),
                    _rand.Next(5));
                break;

            case MTRandom.Normalization.POWERLAW:
                pos = GetPointOnCubeSurface(
                    (float)PowerLaw.Normalize(_rand.NextSingle(true), t, 0, 1),
                    (float)PowerLaw.Normalize(_rand.NextSingle(true), t, 0, 1),
                    _rand.Next(5));
                break;

            default:
                pos = GetPointOnCubeSurface(_rand.NextSingle(true), _rand.NextSingle(true), _rand.Next(6));
                break;
            }

            // Move to -1, 1 space as for CIRCLE and SPHERE
            return(new Vector3((2 * pos.x) - 1, (2 * pos.y) - 1, (2 * pos.z) - 1));
        }
コード例 #3
0
ファイル: RandomDisk.cs プロジェクト: Dracir/semicolon
        public static Vector2 Circle(ref UMT.MersenneTwister _rand, MTRandom.Normalization n, float t)
        {
            float r;

            switch (n)
            {
            case MTRandom.Normalization.STDNORMAL:
                r = MTRandom.ScaleFloatToRange((float)NormalDistribution.Normalize(_rand.NextSingle(true), t), 0, Int32.MaxValue, 0, 1);
                break;

            case MTRandom.Normalization.POWERLAW:
                r = (float)PowerLaw.Normalize(_rand.NextSingle(true), t, 0, Int32.MaxValue);
                break;

            default:
                r = (float)_rand.Next();
                break;
            }
            float _2pi = (float)Math.PI * 2;
            float a    = MTRandom.ScaleFloatToRange(r, 0, _2pi, 0, Int32.MaxValue);

            return(new Vector2((float)Math.Cos(a), (float)Math.Sin(a)));
        }
コード例 #4
0
ファイル: RandomDisk.cs プロジェクト: Dracir/semicolon
        public static Vector2 Disk(ref UMT.MersenneTwister _rand, MTRandom.Normalization n, float temp)
        {
            double t, theta;

            switch (n)
            {
            case MTRandom.Normalization.STDNORMAL:
                t     = NormalDistribution.Normalize(_rand.NextSingle(true), temp);
                theta = NormalDistribution.Normalize(_rand.NextSingle(true), temp) * 2 * Math.PI;
                break;

            case MTRandom.Normalization.POWERLAW:
                t     = PowerLaw.Normalize(_rand.NextSingle(true), temp, 0, 1);
                theta = PowerLaw.Normalize(_rand.NextSingle(true), temp, 0, 1) * 2 * Math.PI;
                break;

            default:
                t     = (float)_rand.NextSingle(true);
                theta = _rand.NextSingle(false) * 2 * Math.PI;
                break;
            }

            return(new Vector2((float)(Math.Sqrt(t) * Math.Cos(theta)), (float)(Math.Sqrt(t) * Math.Sin(theta))));
        }