Пример #1
0
        /// <summary>
        /// Returns a position randomly distributed inside a sphere of unit radius
        /// centered at the origin.  Orientation will be random and length will range
        /// between 0 and 1
        /// </summary>
        /// <returns></returns>
        public static Vector3 RandomVectorInUnitRadiusSphere()
        {
            Vector3 v = new Vector3();

            do
            {
                v.X = (RandomHelpers.Random() * 2) - 1;
                v.Y = (RandomHelpers.Random() * 2) - 1;
                v.Z = (RandomHelpers.Random() * 2) - 1;
            }while (v.Length() >= 1);

            return(v);
        }
Пример #2
0
        /// <summary>
        /// Returns a position randomly distributed on a disk of unit radius
        /// on the XZ (Y=0) plane, centered at the origin.  Orientation will be
        /// random and length will range between 0 and 1
        /// </summary>
        /// <returns></returns>
        public static Vector3 RandomVectorOnUnitRadiusXZDisk()
        {
            Vector3 v;

            do
            {
                v.X = (RandomHelpers.Random() * 2) - 1;
                v.Y = 0;
                v.Z = (RandomHelpers.Random() * 2) - 1;
            }while (v.Length() >= 1);

            return(v);
        }
Пример #3
0
        public static float ScalarRandomWalk(float initial, float walkspeed, float min, float max)
        {
            float next = initial + (((RandomHelpers.Random() * 2) - 1) * walkspeed);

            if (next < min)
            {
                return(min);
            }
            if (next > max)
            {
                return(max);
            }
            return(next);
        }